Rev 1979 | Rev 1987 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1979 | Rev 1986 | ||
---|---|---|---|
Line 151... | Line 151... | ||
151 | * Experiment: Measuring vibration-induced sensor noise. |
151 | * Experiment: Measuring vibration-induced sensor noise. |
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 -... | Line 155... | ||
- | 155 | ||
- | 156 | volatile uint8_t adState; |
|
155 | 157 | ||
156 | // ADC channels |
158 | // ADC channels |
157 | #define AD_GYRO_YAW 0 |
159 | #define AD_GYRO_YAW 0 |
158 | #define AD_GYRO_ROLL 1 |
160 | #define AD_GYRO_ROLL 1 |
159 | #define AD_GYRO_PITCH 2 |
161 | #define AD_GYRO_PITCH 2 |
Line 206... | Line 208... | ||
206 | // Disable digital input buffer for analog adc_channel pins |
208 | // Disable digital input buffer for analog adc_channel pins |
207 | DIDR0 = 0xFF; |
209 | DIDR0 = 0xFF; |
208 | // external reference, adjust data to the right |
210 | // external reference, adjust data to the right |
209 | ADMUX &= ~((1<<REFS1)|(1<<REFS0)|(1<<ADLAR)); |
211 | ADMUX &= ~((1<<REFS1)|(1<<REFS0)|(1<<ADLAR)); |
210 | // set muxer to ADC adc_channel 0 (0 to 7 is a valid choice) |
212 | // set muxer to ADC adc_channel 0 (0 to 7 is a valid choice) |
211 | ADMUX = (ADMUX & 0xE0) | channelsForStates[0]; |
213 | ADMUX = (ADMUX & 0xE0) | AD_GYRO_PITCH; |
212 | //Set ADC Control and Status Register A |
214 | //Set ADC Control and Status Register A |
213 | //Auto Trigger Enable, Prescaler Select Bits to Division Factor 128, i.e. ADC clock = SYSCKL/128 = 156.25 kHz |
215 | //Auto Trigger Enable, Prescaler Select Bits to Division Factor 128, i.e. ADC clock = SYSCKL/128 = 156.25 kHz |
214 | ADCSRA = (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); |
216 | ADCSRA = (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); |
215 | //Set ADC Control and Status Register B |
217 | //Set ADC Control and Status Register B |
216 | //Trigger Source to Free Running Mode |
218 | //Trigger Source to Free Running Mode |
Line 247... | Line 249... | ||
247 | analogDataReady = 0; |
249 | analogDataReady = 0; |
248 | // Stop the sampling. Cycle is over. |
250 | // Stop the sampling. Cycle is over. |
249 | for (uint8_t i = 0; i < 8; i++) { |
251 | for (uint8_t i = 0; i < 8; i++) { |
250 | sensorInputs[i] = 0; |
252 | sensorInputs[i] = 0; |
251 | } |
253 | } |
- | 254 | adState = 0; |
|
252 | ADMUX = (ADMUX & 0xE0) | channelsForStates[0]; |
255 | ADMUX = (ADMUX & 0xE0) | AD_GYRO_PITCH; |
253 | startADC(); |
256 | startADC(); |
254 | } |
257 | } |
Line 255... | Line 258... | ||
255 | 258 | ||
256 | /***************************************************** |
259 | /***************************************************** |
257 | * Interrupt Service Routine for ADC |
260 | * Interrupt Service Routine for ADC |
258 | * Runs at 312.5 kHz or 3.2 �s. When all states are |
261 | * Runs at 312.5 kHz or 3.2 �s. When all states are |
259 | * processed further conversions are stopped. |
262 | * processed further conversions are stopped. |
260 | *****************************************************/ |
263 | *****************************************************/ |
261 | ISR(ADC_vect) { |
264 | ISR(ADC_vect) { |
262 | static uint8_t ad_channel = AD_GYRO_PITCH, state = 0; |
265 | static uint8_t adChannel = AD_GYRO_PITCH; |
263 | sensorInputs[ad_channel] += ADC; |
266 | sensorInputs[adChannel] += ADC; |
264 | // set up for next state. |
267 | // set up for next state. |
265 | state++; |
268 | adState++; |
266 | if (state < 18) { |
269 | if (adState < sizeof(channelsForStates)) { |
267 | ad_channel = pgm_read_byte(&channelsForStates[state]); |
270 | adChannel = pgm_read_byte(&channelsForStates[adState]); |
268 | // set adc muxer to next ad_channel |
271 | // set adc muxer to next adChannel |
269 | ADMUX = (ADMUX & 0xE0) | ad_channel; |
272 | ADMUX = (ADMUX & 0xE0) | adChannel; |
270 | // after full cycle stop further interrupts |
273 | // after full cycle stop further interrupts |
271 | startADC(); |
274 | startADC(); |
272 | } else { |
- | |
273 | state = 0; |
275 | } else { |
274 | ADCycleCount++; |
276 | ADCycleCount++; |
275 | analogDataReady = 1; |
277 | analogDataReady = 1; |
276 | // do not restart ADC converter. |
278 | // do not restart ADC converter. |
277 | } |
279 | } |
Line 449... | Line 451... | ||
449 | void analog_updateBatteryVoltage(void) { |
451 | void analog_updateBatteryVoltage(void) { |
450 | // Battery. The measured value is: (V * 1k/11k)/3v * 1024 = 31.03 counts per volt (max. measurable is 33v). |
452 | // Battery. The measured value is: (V * 1k/11k)/3v * 1024 = 31.03 counts per volt (max. measurable is 33v). |
451 | // This is divided by 3 --> 10.34 counts per volt. |
453 | // This is divided by 3 --> 10.34 counts per volt. |
452 | UBat = (3 * UBat + sensorInputs[AD_UBAT] / 3) / 4; |
454 | UBat = (3 * UBat + sensorInputs[AD_UBAT] / 3) / 4; |
453 | debugOut.analog[11] = UBat; |
455 | debugOut.analog[11] = UBat; |
- | 456 | debugOut.analog[21] = sensorInputs[AD_UBAT]; |
|
454 | } |
457 | } |
Line 455... | Line 458... | ||
455 | 458 | ||
456 | void analog_update(void) { |
459 | void analog_update(void) { |
457 | analog_updateGyros(); |
460 | analog_updateGyros(); |