52 #include "em_device.h" 63 #define DBPRINT_TIMEOUT 0 66 #define TIMEOUT_CONVERSION 50 71 ADC_Init_TypeDef
init = ADC_INIT_DEFAULT;
72 ADC_InitSingle_TypeDef
initSingle = ADC_INITSINGLE_DEFAULT;
89 CMU_ClockEnable(cmuClock_HFPER,
true);
90 CMU_ClockEnable(cmuClock_ADC0,
true);
94 init.timebase = ADC_TimebaseCalc(0);
98 init.prescale = ADC_PrescaleCalc(400000, 0);
101 ADC_Init(ADC0, &
init);
114 #if DEBUG_DBPRINT == 1 115 dbcrit(
"Unknown ADC peripheral selected!");
119 CMU_ClockEnable(cmuClock_ADC0,
false);
135 ADC_IntEnable(ADC0, ADC_IEN_SINGLE);
136 NVIC_ClearPendingIRQ(ADC0_IRQn);
137 NVIC_EnableIRQ(ADC0_IRQn);
140 CMU_ClockEnable(cmuClock_ADC0,
false);
142 #if DEBUG_DBPRINT == 1 166 uint16_t counter = 0;
170 CMU_ClockEnable(cmuClock_ADC0,
true);
192 #if DEBUG_DBPRINT == 1 193 dbcrit(
"Unknown ADC peripheral selected!");
197 CMU_ClockEnable(cmuClock_ADC0,
false);
209 ADC_Start(ADC0, adcStartSingle);
218 #if DEBUG_DBPRINT == 1 219 dbcrit(
"Waiting time for ADC conversion reached!");
223 CMU_ClockEnable(cmuClock_ADC0,
false);
230 #if DBPRINT_TIMEOUT == 1 234 #if DEBUG_DBPRINT == 1 235 dbwarnInt(
"ADC conversion (", counter,
")");
242 value = ADC_DataSingleGet(ADC0);
245 CMU_ClockEnable(cmuClock_ADC0,
false);
251 value = (int32_t) ft;
255 float32_t fv = value * 3.75 / 4.096;
256 value = (int32_t) fv;
282 int32_t cal_temp_0 = ((DEVINFO->CAL & _DEVINFO_CAL_TEMP_MASK)
283 >> _DEVINFO_CAL_TEMP_SHIFT);
286 int32_t cal_value_0 = ((DEVINFO->ADC0CAL2 & _DEVINFO_ADC0CAL2_TEMP1V25_MASK)
287 >> _DEVINFO_ADC0CAL2_TEMP1V25_SHIFT);
290 float32_t t_grad = -6.27;
292 temp = (cal_temp_0 - ((cal_value_0 - adcSample) / t_grad));
305 uint32_t flags = ADC_IntGet(ADC0);
308 ADC_IntClear(ADC0, flags);
ADC_InitSingle_TypeDef initSingle
void ADC0_IRQHandler(void)
Interrupt Service Routine for ADC0.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
ADC functionality for reading the (battery) voltage and internal temperature.
#define TIMEOUT_CONVERSION
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
int32_t readADC(ADC_Measurement_t peripheral)
Method to read the battery voltage or internal temperature.
static float32_t convertToCelsius(int32_t adcSample)
Method to convert an ADC value to a temperature value.
void error(uint8_t number)
Error method.
volatile bool adcConversionComplete
Enable or disable printing to UART with dbprint.
void initADC(ADC_Measurement_t peripheral)
Method to initialize the ADC to later check the battery voltage or internal temperature.
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
enum adc_measurements ADC_Measurement_t