cancel
Showing results for 
Search instead for 
Did you mean: 

What is the minimum clock speed if I use ADC with DMA?

Nazim Nuriev
Associate II
Posted on March 03, 2017 at 20:18

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 16

ADC1->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 #dma
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 04, 2017 at 10:36

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

View solution in original post

2 REPLIES 2
Posted on March 04, 2017 at 10:36

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

Posted on March 04, 2017 at 12:56

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.