Skip to main content
sts0340
Associate II
November 22, 2012
Question

change wave frequency with pot ..how?

  • November 22, 2012
  • 4 replies
  • 1150 views
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.

    This topic has been closed for replies.

    4 replies

    Andrew Neil
    Super User
    November 22, 2012
    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...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Tesla DeLorean
    Guru
    November 23, 2012
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Nickname12657_O
    Associate III
    November 23, 2012
    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
    Super User
    November 23, 2012
    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!

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.