ADC: adapt to new libopencm3 + added calibration
This commit is contained in:
parent
63fdc2797b
commit
f698413f8d
16
src/main.c
16
src/main.c
|
@ -194,9 +194,9 @@ static void init_timer(void)
|
|||
static void init_adc(void)
|
||||
{
|
||||
uint8_t channels[ADC_NUM_CHANNELS] = {
|
||||
ADC_CHANNEL0, // VInSense
|
||||
ADC_CHANNEL1, // VOutSense
|
||||
ADC_CHANNEL2 // CurrentSense
|
||||
0, // VInSense
|
||||
1, // VOutSense
|
||||
2 // CurrentSense
|
||||
};
|
||||
|
||||
adc_power_off(ADC1);
|
||||
|
@ -205,7 +205,7 @@ static void init_adc(void)
|
|||
//adc_enable_scan_mode(ADC1);
|
||||
adc_set_single_conversion_mode(ADC1);
|
||||
adc_set_resolution(ADC1, ADC_RESOLUTION_12BIT);
|
||||
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_071DOT5);
|
||||
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_239DOT5);
|
||||
adc_disable_external_trigger_regular(ADC1);
|
||||
adc_set_right_aligned(ADC1);
|
||||
adc_set_regular_sequence(ADC1, ADC_NUM_CHANNELS, channels);
|
||||
|
@ -229,9 +229,7 @@ static void init_adc(void)
|
|||
|
||||
adc_enable_dma(ADC1);
|
||||
|
||||
// GO!
|
||||
adc_power_on(ADC1);
|
||||
|
||||
}
|
||||
|
||||
static void deepsleep(uint32_t duration_secs)
|
||||
|
@ -595,6 +593,12 @@ int main(void)
|
|||
|
||||
// triggered every 1 ms
|
||||
while (1) {
|
||||
if(timebase_ms == 900) {
|
||||
adc_power_off(ADC1);
|
||||
adc_calibrate(ADC1);
|
||||
adc_power_on(ADC1);
|
||||
}
|
||||
|
||||
// let the ADC+DMA do its work
|
||||
adc_start_conversion_regular(ADC1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue