2019-01-24 08:49 AM
I'm using STM32f401re nucleo board and Truestudio IDE. I am only concentrating on ADC peripheral. I want to measure the number of clock cycles consumed for single ADC conversion. I am willing to measure conversion time for 6, 8, 10, 12 bit resolution ADC. Can somebody suggest how can do this? I tried to use ADC in interrupt mode and timer. Then I used HAL_ADC_ConvCpltCallback function to store the counter value but this did not work for me.
2019-01-24 09:16 AM
You specify the sample time in ADC clocks, and the manual defines the clocks for the actual conversion, I think 12 ADCCLK for 12-bit, but I'm sure the Reference Manual states this explicitly.
The ADC clock comes from the APB the ADC is on, and the ADC Prescaler DIVIDES that down.
Normally when I want specific periodicity, I program a TIM with the "sample frequency" have it to trigger the ADC, have the DMA fetch the data, and use the DMA HT and TC interrupts to call be when each half of the "ping-pong" buffer is ready and not changing under foot.
2019-01-24 09:32 AM
to measure something you need something to measure like osciloscope and measure frequency for example at PIN 5, from perion lenght you can calculate how long it takes for 1000000 or more conversions.
while(); {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
for (int i= 0; i<1000000; i++){
value1= HAL_ADC_GetValue(&hadc1);
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
}
2019-01-24 10:09 AM
I forgot you need to wait until you obtain value, you need in the function the 1 ms delay but in fact it takes like microseconds to get the value.
while(); {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
for (int i= 0; i<1000000; i++){
if (HAL_ADC_PollForConversion(&hadc1,1) == HAL_OK)
{ value1= HAL_ADC_GetValue(&hadc1);}
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
}