cancel
Showing results for 
Search instead for 
Did you mean: 

Change the frequency of the square signal

AAbed.1
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
AAbed.1
Associate III

Thanks

I solved it by using single mode ADC.

View solution in original post

7 REPLIES 7
TDK
Guru

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
Associate III

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
Guru

How are you initializing and starting ADC conversions?

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

I initialized ADC by using continuous mode.

Laurent Ca...
Lead II

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...
Lead II

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
Associate III

Thanks

I solved it by using single mode ADC.