//******************************************************************************\r
// ADC status struct.\r
//! \brief Holds sampled data and ADC-status\r
-ADC_Status_t ADCS;\r
+volatile ADC_Status_t ADCS;\r
\r
\r
/*! \brief Indicates maximum battery voltage.\r
\r
// Scale sample according to jumper setting, handle negative numbers.\r
if (ADC > 511) {\r
- ADCS.IBAT = -(signed int)ScaleI(eeprom_read_byte(&VBAT_RANGE),\r
- (1024 - (ADC-ADCS.ADC5_G20_OS)));\r
+ ADCS.IBAT = -(signed int)ScaleI(eeprom_read_byte(&VBAT_RANGE),\r
+ (1024 - (ADC-ADCS.ADC5_G20_OS)));\r
} else if (ADC > 0) {\r
- ADCS.IBAT = ScaleI(eeprom_read_byte(&VBAT_RANGE), (ADC-ADCS.ADC5_G20_OS));\r
+ ADCS.IBAT = ScaleI(eeprom_read_byte(&VBAT_RANGE), (ADC-ADCS.ADC5_G20_OS));\r
} else {\r
ADCS.IBAT = 0;\r
}\r
ADMUX = (1<<REFS0) + ADCS.MUX;\r
\r
if (Signed) {\r
- ADCSRB |= (1<<BIN);\r
+ ADCSRB |= (1<<BIN);\r
} else {\r
- ADCSRB &= ~(1<<BIN);\r
+ ADCSRB &= ~(1<<BIN);\r
}\r
\r
// Re-enable the ADC unless a halt has been flagged and a conversion\r
// cycle has completed.\r
if (!((ADCS.Halt) && (ADCS.Flag))) {\r
- ADCSRA |= (1<<ADEN)|(1<<ADSC);\r
+ ADCSRA |= (1<<ADEN)|(1<<ADSC);\r
}\r
}\r
\r
do {\r
} while (ADCS.Flag == FALSE);\r
\r
- // Repeat, so we are sure the data beong to the same cycle.\r
+ // Repeat, so we are sure the data belongs to the same cycle.\r
ADCS.Flag = FALSE;\r
do {\r
} while (ADCS.Flag == FALSE);\r
void ADC_Init(void)\r
{\r
unsigned char i;\r
+ unsigned char sreg_saved;\r
\r
+ sreg_saved = SREG;\r
cli();\r
\r
ADCS.Halt = FALSE; // Enable consecutive runs of ADC.\r
\r
// Get a complete cycle of data before returning.\r
ADC_Wait();\r
+\r
+ SREG = sreg_saved;\r
}\r