Skip to main content
AAbed.1
Associate III
March 27, 2020
Solved

Change the frequency of the square signal

  • March 27, 2020
  • 7 replies
  • 1405 views

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.
Best answer by AAbed.1

Thanks

I solved it by using single mode ADC.

7 replies

TDK
March 27, 2020

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
March 27, 2020

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
March 27, 2020

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
April 1, 2020

I initialized ADC by using continuous mode.

Laurent Ca...
Senior III
October 15, 2020

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
October 26, 2020

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
November 2, 2020

Thanks

I solved it by using single mode ADC.