2017-03-03 11:18 AM
I use STM32L151 for digitizing 3 values: Vrefint, Temp.sensor and 1 external source. Program uses sleep mode.
I get garbage after switching CPU freq from 250 kHz to 4 mHz and correct values when switching from 500 kHz to 4 mHz. Both freq's based on HSI source. ADC RESOLUTION - 12 bit
(DMA init omitted)
ADC init code...
ADC->CCR = ADC_CCR_TSVREFE;
ADC1->CR1 = ADC_CR1_PDI | ADC_CR1_SCAN;
ADC1->CR2 = ADC_CR2_DDS;
// Enable DMA mode
ADC1->CR2 |= ADC_CR2_DMA;ADC1->SQR1 = ((3 - 1) << 20);
ADC1->SQR5 = (6 << 0) | (17 << 5) | (16 << 10);
// vtest 192 cycles
ADC1->SMPR3 = (6 << 0);// Vrefint 192 cycles Temp sensor 384 cycles
// chan 17 chan 16ADC1->SMPR2 = (6 << ((17 - 10) * 3)) | (7 << ((16 - 10) * 3));// DMA1_Channel1_IRQn interrupt configuration
DMA1_Channel1->CCR |= DMA_CCR_EN;ADC1->CR2 |= ADC_CR2_ADON;
// Enable DMA transfer complete
DMA1_Channel1->CCR |= DMA_CCR_TCIE;NVIC_EnableIRQ(DMA1_Channel1_IRQn);Every 250 ms I read previous ADC values from dedicated memory and then ADC starts with:
ADC1->SR &= ~(ADC_SR_EOC | ADC_SR_OVR);
// ADC1 regular conversion start
ADC1->CR2 |= ADC_CR2_SWSTART;#adc #sleep #dmaSolved! Go to Solution.
2017-03-04 01:36 AM
So, one of the coversion data in your buffer is corrupted, and you know for sure that the frequency switch happened *during* that conversion?
JW
2017-03-04 01:36 AM
So, one of the coversion data in your buffer is corrupted, and you know for sure that the frequency switch happened *during* that conversion?
JW
2017-03-04 04:56 AM
Thank you, Jan. That's right. While low freq DMA does not have time to transfer the data from ADC, so I add ADC auto delay to ADC1->CR2 and trouble gone.