timerbased low freq pwm

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

timerbased low freq pwm

Post by brandonb »

this is to get some really low pwm frequencies, from seconds up to about 350hz, (high frequencies dont leave enough time for main) ...it works with tmr2 interrupt only so frequency is stable, pot connected to A2 ... output is on A5...... will have to play with tmr2 settings to see what frequencies you can hit as there are many, to get 1:64 prescaler enable for the 1900 and 1800 chips use code in fcf t2con=t2con|0b1111<<3;.... can change the count #'s in the tmr macro for faster but lower resolution, thought maybe it could be useful to someone someday?
Attachments
updowncntpwm.fcf
(12.3 KiB) Downloaded 268 times

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: timerbased low freq pwm

Post by brandonb »

i got the idea from this video starting at 17:00 http://www.youtube.com/watch?v=mVx02s1fHIY he gives an overveiw of how a avr tmr works, then i did it the only way i could figure out..... the overveiw is below, basicly what the fcf does is every time the tmr macro is accessed it either increases a tick or decreases, the ticks count from 0 to 100 then from 100 to zero, the pwm variable gets a returned number from the adc, when the tick is counting up it will turn the output on when the tick is greater than the pwm variable, then when the count reaches 100 it reverses count direction and on the falling count it will keep the output on until the tick count drops below the pwm variable, then repeat,
Attachments
pwm.jpg
pwm.jpg (20.1 KiB) Viewed 3735 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: timerbased low freq pwm

Post by Enamul »

Hi,
Thanks for the nice video link. It's very good for even those who knew what is PWM.
Enamul
University of Nottingham
enamul4mm@gmail.com

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: timerbased low freq pwm

Post by brandonb »

heres a pwm that i was working on today, this one has fully adjustable tmr2 oscillator on the fly, can set the prescaler 1:1 -1:64 postscaler 1:1-1:16 and rollover 1-256 (pwm =tmr2/200).. it shows the output pwm frequency derived from timer math, the useable output range is 3 seconds to 660hz, like we would really use a second pwm...anything above 660hz slows program down to much, up to 600hz works great, at anytime you can reset the frequency, program operation below

set freq (default is loaded)
press switch 3 to increment through the pre,post,roll over
press switch 1 or 2 to increament values,
rollover mode has 10x value is hold switch 4 when scrolling
press switch 5 when desired freq is chosen, this takes you to pwm menu
switch1 increases duty
switch 2 decreases duty
switch3 if press simultaniously with switch1 or switch2 puts into fast scrolling mode
switch 4 enables output
switch 5 disables output
--> quick access
switch1+switch 4 or 5 = 25% duty
switch2+switch 4 or 5 = 50% duty
switch3+switch 4 or 5 = 75% duty

to change freq, hold switches 1,2,3 then hit switch 5
after chosen new freq hit switch5 to go to pwm menu
Attachments
TMR2_PWM_FREQ_ADJ.fcf
(71.63 KiB) Downloaded 302 times

Post Reply