cancel
Showing results for 
Search instead for 
Did you mean: 

change wave frequency with pot ..how?

sts0340
Associate II
Posted on November 22, 2012 at 20:43

Hi. I hope someone can help me here...

I have been looking at the STM32f4 dac signal generation code. I would like to know how I could change the frequency of the output waveform with a potentiometer or, using the ADC, any other simple sensor ( LDR perhaps..)

I was wondering if it is possible to change TIM.Period via the ADC...

I am a beginner but if anyone can point me in the right direction that would be nice...?..

I am using the STM32f4 discovery and the DACsignals generation code from the peripherals library.

I am on a windows machine...

Thankyou,

STeve.

4 REPLIES 4
Andrew Neil
Chief III
Posted on November 22, 2012 at 22:42

''I have been looking at the STM32f4 dac signal generation code''

First, you need to look at how it currently sets its frequency;

Then you can think about how to adjust that setting based on the current ADC reading...

Posted on November 23, 2012 at 01:33

You could use the ADC's EOC interrupt, reading the converted value, and then translate and write the new period into the TIMx->ARR register.

Clever factoring of prescale and period might permit other, and perhaps simpler, alternatives.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Nickname12657_O
Associate III
Posted on November 23, 2012 at 16:35

Hi,

This is a method to change generated waveform frequency based on potentiometer value:

The idea to generate a wave throw DAC is to use a timer to trig transfers of an input signal to DAC. So the wave frequency is the one of the used timer. Generally, we need to know the prescaler & period to configure the timer.

So here, we have to calculate the prescaler & period based on the value read from potentiometer and converted by an ADC to know the new frequency.

Each time there is a new frequency value:

 - stop DAC generation

 - configure timer with new prescaler and period values

 - re-start generation

I hope this is helpful for you.

Cheers,

STOne-32

Andrew Neil
Chief III
Posted on November 23, 2012 at 19:19

''The idea to generate a wave throogh DAC is to use a timer to trig transfers of an input signal to DAC.''

 

You mean, transfer samples of an input signal to the DAC?

 

''So the wave frequency is the one of the used timer.''

 

 

No: the timer sets the sample rate - not the wave frequency!