Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 9 months ago.
pulse frequency modulation
I'm trying to control a DC motor using PWM. i need to vary frequency keeping the duty cycle as 75%. can someone help out? with coding as well as logic. the frequency has to be varied using potentiometer
What have you tried yourself? Since this is fairly straightforward using AnalogIn and PwmOut.
posted by Erik - 07 Mar 2013this is what i've done and working too.but i fear this is pwm rather than pfm... hence i need to confirm with someone who knows better abt this
posted by Kishhanth Renganathan 07 Mar 2013Please use code tags:
<<code>> and <</code>>
What you now do is changing the duty cycle of Poutt, but you want to change the frequency. So simply call:
Depending on ain it will change the period 1 second (1Hz) and 1ms (1kHz). Period keeps the duty cycle constant, so you only need to set it once.
posted by Erik - 07 Mar 2013I'll implement using this and get back to you. thanks for the help.
posted by Kishhanth Renganathan 07 Mar 2013hey. that worked. i have one more problem.. if i increase the input voltage from 0-3.3 to vary the frequency suddenly there shouldnt be a sudden rise in pfm.. it should rise slowly(say 5 secs). can u help out in this cide. is it using timers?of a loop will do?
posted by Kishhanth Renganathan 15 Mar 2013Both options are possible, depending on your other requirements. What you could try is defining another variable 'slowinput'. Then use something like:
Then you can either add for example a 5ms wait and call it in a loop, or use a ticker.
posted by Erik - 15 Mar 2013is the code right for pfm? its compiling bt not functioning.. sorry i m beginner to this mbed..
posted by Kishhanth Renganathan 05 Apr 2013