cancel
Showing results for 
Search instead for 
Did you mean: 

ADC fluctuations problem

Maciej Skrzypczak
Associate II
Posted on February 26, 2018 at 14:50

Hi,

I am having a problem with ADC read. The values I get from conversion are 100% random. They get from 0 to max range without any pattern. Example codes from MXCube work fine and the value is stable. My own code generated in cube is not fixing the issue. I tried to compare the example and my own code, but didnt find any difference besides CPUcache beeing enabled in example (that I ignored). Every other function in ADC works for me. Can anyone please tell me what am I doing wrong? Thanks in advance!

I am using KeiluVision 5.0 with STM32F767ZI on nucleo board. Here is my code 

.

int main()

{

   ADC_init();

   ADC_port_init();

}

.

void ADC_port_init(void)

{

   /////////// AHB for GPIOA

   RCC -> AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

.

   /////////// Pin A1 analog

   GPIOA -> MODER |= GPIO_MODER_MODER1_0 | GPIO_MODER_MODER1_1;

.

   /////////// Pin A1 very high speed

   GPIOA -> OSPEEDR |= GPIO_OSPEEDER_OSPEEDR1_0 | GPIO_OSPEEDER_OSPEEDR1_1;

}

.

void ADC_init (void)

{

   /////////// Conwerter ON

   ADC1 -> CR2 |= ADC_CR2_ADON;

.

   /////////// APB for ADC init

   RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;

.

   /////////// Interrupt when EOC

   ADC1 -> CR1 |= ADC_CR1_EOCIE;

.

   /////////// 12 bit resolution (11)

   ADC1 -> CR1 &= ~ADC_CR1_RES_0 & ~ADC_CR1_RES_0;

.

   /////////// Single conversion

   ADC1 -> CR2 &= ~ADC_CR2_CONT;

.

   /////////// EOC after regular group

   ADC1 ->CR2 &= ~ADC_CR2_EOCS;

.

   /////////// Sample time 480 cycles (010)

   ADC1 ->SMPR2 |= ADC_SMPR2_SMP1_0 | ADC_SMPR2_SMP1_1 | ADC_SMPR2_SMP1_2;

.

   /////////// 1 measurement in regular group (0000)

   ADC1 -> SQR1 &= ~ADC_SQR1_L_0 & ~ADC_SQR1_L_1 & ~ADC_SQR1_L_2 & ~ADC_SQR1_L_3;

.

   /////////// First measurement on PA1 (0001)

   ADC1 -> SQR3 &= ~ADC_SQR3_SQ1_0 | ADC_SQR3_SQ1_1 & ~ADC_SQR3_SQ1_2 & ~ADC_SQR3_SQ1_3;

.

   /////////// Start regular conversion

   ADC1 -> CR2 |= ADC_CR2_SWSTART;

}

#problem #adc #fluctuations #stm32f767zi
10 REPLIES 10
Posted on February 27, 2018 at 11:23

Maciej Skrzypczak wrote:

Can You please tell me what LL is?

Take a look at this: 

http://empa.com/dokumanlar/st2016/12_Low-Layer-Library-theory.pdf