Subversion Repositories FlightCtrl

Rev

Rev 1986 | Rev 1991 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1986 Rev 1987
Line 152... Line 152...
152
 */
152
 */
153
volatile uint16_t gyroNoisePeak[3];
153
volatile uint16_t gyroNoisePeak[3];
154
volatile uint16_t accNoisePeak[3];
154
volatile uint16_t accNoisePeak[3];
Line 155... Line 155...
155
 
155
 
-
 
156
volatile uint8_t adState;
Line 156... Line 157...
156
volatile uint8_t adState;
157
volatile uint8_t adChannel;
157
 
158
 
158
// ADC channels
159
// ADC channels
159
#define AD_GYRO_YAW       0
160
#define AD_GYRO_YAW       0
Line 208... Line 209...
208
        // Disable digital input buffer for analog adc_channel pins
209
        // Disable digital input buffer for analog adc_channel pins
209
        DIDR0 = 0xFF;
210
        DIDR0 = 0xFF;
210
        // external reference, adjust data to the right
211
        // external reference, adjust data to the right
211
        ADMUX &= ~((1<<REFS1)|(1<<REFS0)|(1<<ADLAR));
212
        ADMUX &= ~((1<<REFS1)|(1<<REFS0)|(1<<ADLAR));
212
        // set muxer to ADC adc_channel 0 (0 to 7 is a valid choice)
213
        // set muxer to ADC adc_channel 0 (0 to 7 is a valid choice)
213
        ADMUX = (ADMUX & 0xE0) | AD_GYRO_PITCH;
214
        ADMUX = (ADMUX & 0xE0);
214
        //Set ADC Control and Status Register A
215
        //Set ADC Control and Status Register A
215
        //Auto Trigger Enable, Prescaler Select Bits to Division Factor 128, i.e. ADC clock = SYSCKL/128 = 156.25 kHz
216
        //Auto Trigger Enable, Prescaler Select Bits to Division Factor 128, i.e. ADC clock = SYSCKL/128 = 156.25 kHz
216
        ADCSRA = (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
217
        ADCSRA = (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
217
        //Set ADC Control and Status Register B
218
        //Set ADC Control and Status Register B
218
        //Trigger Source to Free Running Mode
219
        //Trigger Source to Free Running Mode
Line 250... Line 251...
250
  // Stop the sampling. Cycle is over.
251
  // Stop the sampling. Cycle is over.
251
  for (uint8_t i = 0; i < 8; i++) {
252
  for (uint8_t i = 0; i < 8; i++) {
252
    sensorInputs[i] = 0;
253
    sensorInputs[i] = 0;
253
  }
254
  }
254
  adState = 0;
255
  adState = 0;
-
 
256
  adChannel = AD_GYRO_PITCH;
255
  ADMUX = (ADMUX & 0xE0) | AD_GYRO_PITCH;
257
  ADMUX = (ADMUX & 0xE0) | adChannel;
256
  startADC();
258
  startADC();
257
}
259
}
Line 258... Line 260...
258
 
260
 
259
/*****************************************************
261
/*****************************************************
260
 * Interrupt Service Routine for ADC
262
 * Interrupt Service Routine for ADC
261
 * Runs at 312.5 kHz or 3.2 �s. When all states are
263
 * Runs at 312.5 kHz or 3.2 �s. When all states are
262
 * processed further conversions are stopped.
264
 * processed further conversions are stopped.
263
 *****************************************************/
265
 *****************************************************/
264
ISR(ADC_vect) {
-
 
265
  static uint8_t adChannel = AD_GYRO_PITCH;
266
ISR(ADC_vect) {
266
  sensorInputs[adChannel] += ADC;
267
  sensorInputs[adChannel] += ADC;
267
  // set up for next state.
268
  // set up for next state.
268
  adState++;
269
  adState++;
269
  if (adState < sizeof(channelsForStates)) {
270
  if (adState < sizeof(channelsForStates)) {