2022-03-05 03:47 PM
I'm using an STM32F407, I want to use the falling edge of a PWM to trigger the ADC and then with the DMA move the data into a variable. The problem I have is that I am trying to check if the ADC is actually taking samples at the PWM frequency. I am trying with a low frequency (100 Hz) but I have a problem. To check if the ADC actually samples at 100 Hz, inside the HAL_ADC_ConvCpltCallback() function I change the state of a pin and measure it with the oscilloscope. If the frequency is 100Hz, the oscilloscope should measure 50Hz (1 trigger for each falling edge). But on the oscilloscope I see that the signal is not what I expected and when debugging the code I noticed that the HAL_ADC_ConvCpltCallback() function is called 2 times for each trigger signal. That's why the state of the pin changes 2 times (very fast) for each trigger.
This only happens when I use DMA! Anyone know what might be happening?
I attach the code in C, if you need the rest of the files, please tell me! Thanks a lot
2022-03-06 01:33 AM
I dont check all , but primary adc buff is normaly uin16 , dma half word and init for rank 3 cant be
HAL_ADC_Start_DMA(&hadc1, adc1_array, 2)
2022-03-06 01:54 PM
Change the adc1_array array to uint16 and the DMA data width to half word. I modified the function like this HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&adc1_array, 2) but there was no change. But I noticed that changing the size of the amount of data that the dma should fill, ie the 3rd parameter of the HAL_ADC_Start_DMA function changes the number of times it enters the HAL_ADC_ConvCpltCallback() function. If I configure the DMA to store a single value (eg HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&adc1_array, 1) I see what I'm looking for. I don't understand the relationship between the amount of data the DMA must store with the call to the HAL_ADC_ConvCpltCallback() function.