cancel
Showing results for 
Search instead for 
Did you mean: 

rms value measurement in stm32f030c6t6

Sbomm.1
Associate

dear experts i am working on stm32f030c6t6 MCU 

i want to calculate the adc measurement of sine wave form at Gpio pin and that gpio pin has a adc channel also i am using the DMA 

here i am using another Adc channel for other purpose please check my code 

here i am using another adc channels for other purpose please check my code is there any adc values are mixing with another gpio pin adc values i am using DMA

i am collecting the adc samples of sine wave at gpio pin and i have done my calculation they are good enough but problem is taking the data from ADC DR register there are different channels which i am using in my MCU there is no rank option to select the adc channel priority

Dear experts please help me

void ADC_Calculation(void)

{

res1=0;

HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_14);

/*****************ADC_DR collection************/

for(int i=0;i<100;i++)

{

  HAL_ADC_Start_DMA(&hadc,adc,5);

if(adc[1]>res1)    

res1=adc[1];

temp2[i]=adc[2];

temp3[i]=adc[3];

temp4[i]=adc[4];

HAL_Delay(1);

}

/*****************ADC_DR collection************/

/*************** Calculations ****************/

sum_b = 0;

 for(int i=0;i<100;i++)

    sum_b += temp2[i];

  sum_b = sum_b/100;

V_Bat = (sum_b*3.3)/4095;

sum_v = 0;

 for(int i=0;i<100;i++)

   sum_v += temp3[i];

  sum_v = sum_v/100;

voltage = (sum_v*3.3)/4095;

sum_i = 0;

 for(int i=0;i<100;i++)

    sum_i += temp4[i];

  sum_i = sum_i/100;

current = (sum_i*3.3)/4095;

max =(res1*3.3)/4095; //12bit resolution

max=max-1.65;    //shifting value

max=max/0.00197;   //gain

vrms=max*.707106781;

Temperature = adc[0];

2 REPLIES 2
TDK
Guru

> HAL_ADC_Start_DMA(&hadc,adc,5);

> if(adc[1]>res1)  

DMA works in the background. You need to wait until the values are populated before you use them in your code.

Channels are converted in order (or in reverse order) on the STM32F0. You can't select an arbitrary order like you can on other chips.

If you feel a post has answered your question, please click "Accept as Solution".
Sbomm.1
Associate

thank you for your response