Skip to main content
AAbed.1
Associate III
Mar 27, 2020 5:02 PM UTC
Solved

Change the frequency of the square signal

Hi

I am working on changing the frequency of the square signal which comes from STM32F4. I used Timer and ADC simultaneously where I change ARR and CCR1 accordingly to change the frequency. When I use an incremental loop for these values I can get different frequency but When I add ADC (continuous mode) in the fly of the program, the output gives me just one frequency and when I press the reset button with changing variable resistor I get updated value. How can I solve this issue? Is there another method to do that?

this is my code:

-----------------------------------------------------------------------

while (1)

{

AA=HAL_ADC_GetValue(&hadc1);

DT=0.5*AA;

htim3.Instance->ARR=AA;

htim3.Instance->CCR1=DT;

}

-------------------------------------------------------------------------

I will hear from you.

Thanks

This topic has been closed for replies.
AAbed.1
AAbed.1Best answer
Associate III
Nov 2, 2020 2:24 AM UTC

Thanks

I solved it by using single mode ADC.

7 replies

TDK
Mar 27, 2020 5:31 PM UTC

HAL_ADC_GetValue only reads the last converted channel, it doesn't start a new conversion. Assuming you've set the ADC to convert continuously, your method should work.

From the reference manual:

> It may be useful to let the ADC convert one or more channels without reading the data each

time (if there is an analog watchdog for instance). For that, the DMA must be disabled

(DMA = 0) and the EOC bit must be set at the end of a sequence only (EOCS = 0). In this

configuration, overrun detection is disabled.

"If you feel a post has answered your question, please click ""Accept as Solution""."
AAbed.1
AAbed.1Author
Associate III
Mar 27, 2020 7:53 PM UTC

I did ADC convert Continuously mode. But I could not get any change until I press reset button to change frequency so the code can not follow the change of variable resistor's voltage

TDK
Mar 27, 2020 10:56 PM UTC

How are you initializing and starting ADC conversions?

"If you feel a post has answered your question, please click ""Accept as Solution""."
AAbed.1
AAbed.1Author
Associate III
Apr 1, 2020 1:31 PM UTC

I initialized ADC by using continuous mode.

Laurent Ca...
Senior III
Oct 15, 2020 9:51 AM UTC

Dear @AAbed.1​ 

Do you have still this problem to solve?

And just in case, if not, do not hesitate to share the final solution you found.

Best regards

Laurent Ca...

==

Dear 

Laurent Ca...
Senior III
Oct 26, 2020 8:52 AM UTC

Dear @AAbed.1​ 

I guess you don't have to solve this problem anymore, therefore I consider this thread closed.

If not, feel free to reopen it by posting an answer.

Best regards

Laurent Ca...

AAbed.1
AAbed.1AuthorBest answer
Associate III
Nov 2, 2020 2:24 AM UTC

Thanks

I solved it by using single mode ADC.