PWMOUT Calculator

Fowkc

Senior Member
If anyone's interested, I've written a Javascript calculator to work out values for the PWMOUT command:

<A href='http://www.fowkc.com/elec/pwmout.shtml' Target=_Blank>External Web Link</a>

I've also tried to explain the maths behind it.

And as much as it might appear to be, it's not entirely a shameless attempt at getting people to look at my website. Really.
 
Excellent work! It works very well. I was able to control a motor at 20kHZ. Maybe something like this calculator should be included within the actual PICAXE Editor software. It saves a lot of time.
 

Michael 2727

Senior Member
Very good Fowkc,
I just got some U-Sonic transducers and was
wondering how I was going to work out the PWM.
And good point about including it in the SIM,
would be very handy, maybe they are watching ~ ;o)

And don't tell them about the last part, Shhhhh !
 

cpedw

Senior Member
Very useful. One small point, shouldn't the numerator in equation 4 read &quot;0.3*1/6000&quot; ?
The answer seems correct for 30% duty cycle but the numbers you supplied suggest 45%.
Derek
 

thelabwiz

Senior Member
Thanks for the contribution!
Just one problem - the calculator &quot;form&quot; section does not display correctly in IE6 (XP Pro, SP2, latest fixes, window size a little less than 1024x768). The calculator section is partially hidden by the equation 6 graphic. Adding &lt;div&gt;&lt;/div&gt; around the form section makes it display properly.
This may be OK in other browsers (only have IE6 on this PC).

John
 

georgec

New Member
Good site and interesting UV camera project.
How about making the links on the left hand side of the page someother colour than blue as it's a bit difficult to read?
 

Technical

Technical Support
Staff member
This is an excellent idea and we will look at adding a similar wizard to the Prog Edit software in the future.
 

Fowkc

Senior Member
The calculator displays fine in IE7 and Firefox, but the &lt;DIV&gt; tags don't make any difference to those browsers, so in they go. Thanks, it's good to have feedback.

I've added another warning if the period is 0 or -1 as well. This happens if the frequency is too high.
 

Fowkc

Senior Member
It's in the middle of a &quot;minor&quot; change in the Javascript, which is turning into a major one, and I have to go out... should be fixing later tonight.

EDIT: Fixed. Now gives an error if frequency is too high, which leads to a period value of 0 or -1 because of rounding errors.

Edited by - Fowkc on 17/10/2006 21:25:34
 
I just wanted to thank you for putting this together. Just the formulas and the explaination was good enough, but the calculator is awesome. My only question is what determines frequency? Frequency and duty cycle determine the PWMOUT command but how does frequency change the result? I would assume a frequency of 50 would make it noticable that the motor is turning on an off, where 6000 makes the motor run smoothly. Is there a reccomended frequency or just keep pluging away until I get the results I want?
 

Fowkc

Senior Member
I'm not sure about choosing a frequency. I've never actually used PWMOUT for motor control, just LED brightness and poor mans digital-to-analog conversion. I'm sure someone can give sensible advice.
 

xstamp

Senior Member
Many thanks for sharing your PWM simulator with us. Do you know of any PICAXE programmes to produce &#8216;a poor mans function generator&#8217;? Even a relatively slow (adc input controlled) triangular output could provide a useful test instrument.

 

premelec

Senior Member
I have used a PICAXE to drive a Digital to Analog IC - you can easily get slow triangle, or sawtooth this way - or approximate other waveforms with a lookup table. My application used a 8 channel D/A converter but any D/A with serial input can be used. If you have a lot of outputs available you can drive resistor networks to approximate various waveforms.
 

RickAlty

Senior Member
Great site and a usefull wizard, fowkc.

One question... what's the clear plastic thingy over your head in the glider pics? :)

Real gliders have open cockpits!

http://www.lasham.org.uk/news/articles/T21/t21.asp

The T-21 I learned in many, many moons past has through many owners made it's way to here in California, and is being rebuilt down in the high desert. Hopefully get a chance in it when it's done :)

[/offtopic]

Richard
 

Dippy

Moderator
Good stuff.

On my screen, though, the input boxes sit on top of the information text, so I can't see where I'm meant to enter parameters.
 

Dippy

Moderator
Thanks.
Aha!
Well done, very smart.
Yeah, bung that in the programme editor, it'll prevent a lot of bald patches.
 

Fowkc

Senior Member
Yay, addition to the Programming Editor. Thus making my webpage obsolete in the space of a week and a half. Heh.
 

Michael 2727

Senior Member
Using Fowkc's nifty calculator I made the lazy persons Wall Chart.
Why, because I'm lazy. It's only for 50/50 duty cycles, in case you need a quick ref.
<code><pre><font size=2 face='Courier'>PWMOUT codes for picaxe outputs at 50% duty. 18,500 Hz @ 50% Duty = PWMOUT ?, 53, 108
4MHz Clock speed. ON PIN = ? ( select ) 19,000 Hz @ 50% Duty = PWMOUT ?, 52, 105
4,000 Hz @ 50% Duty = PWMOUT ?, 249, 500 19,200 Hz @ 50% Duty = PWMOUT ?, 51, 104
4,500 Hz @ 50% Duty = PWMOUT ?, 221, 444 19,500 Hz @ 50% Duty = PWMOUT ?, 50, 103
4,800 Hz @ 50% Duty = PWMOUT ?, 207, 417 20,000 Hz @ 50% Duty = PWMOUT ?, 49, 100
5,000 Hz @ 50% Duty = PWMOUT ?, 199, 400 20,500 Hz @ 50% Duty = PWMOUT ?, 48, 98
5,500 Hz @ 50% Duty = PWMOUT ?, 181, 364 21,000 Hz @ 50% Duty = PWMOUT ?, 47, 95
6,000 Hz @ 50% Duty = PWMOUT ?, 166, 333 21,500 Hz @ 50% Duty = PWMOUT ?, 46, 93
6,500 Hz @ 50% Duty = PWMOUT ?, 153, 308 22,000 Hz @ 50% Duty = PWMOUT ?, 44, 91
7,000 Hz @ 50% Duty = PWMOUT ?, 142, 286 22,500 Hz @ 50% Duty = PWMOUT ?, 43, 89
7,500 Hz @ 50% Duty = PWMOUT ?, 132, 267 23,000 Hz @ 50% Duty = PWMOUT ?, 42, 87
8,000 Hz @ 50% Duty = PWMOUT ?, 124, 250 23,500 Hz @ 50% Duty = PWMOUT ?, 42, 85
8,500 Hz @ 50% Duty = PWMOUT ?, 117, 235 24,000 Hz @ 50% Duty = PWMOUT ?, 41, 83
9,000 Hz @ 50% Duty = PWMOUT ?, 110, 222 24,500 Hz @ 50% Duty = PWMOUT ?, 40, 82
9,500 Hz @ 50% Duty = PWMOUT ?, 104, 211 25,000 Hz @ 50% Duty = PWMOUT ?, 39, 80
9,600 Hz @ 50% Duty = PWMOUT ?, 103, 208 30,000 Hz @ 50% Duty = PWMOUT ?, 32, 67
10,000 Hz @ 50% Duty = PWMOUT ?, 99, 200 35,000 Hz @ 50% Duty = PWMOUT ?, 28, 57
10,500 Hz @ 50% Duty = PWMOUT ?, 94, 190 38,000 Hz @ 50% Duty = PWMOUT ?, 25, 53
11,000 Hz @ 50% Duty = PWMOUT ?, 90, 182 40,000 Hz @ 50% Duty = PWMOUT ?, 24, 50
11,500 Hz @ 50% Duty = PWMOUT ?, 86, 174 45,000 Hz @ 50% Duty = PWMOUT ?, 21, 44
12,000 Hz @ 50% Duty = PWMOUT ?, 82, 167 50,000 Hz @ 50% Duty = PWMOUT ?, 19, 40
12,500 Hz @ 50% Duty = PWMOUT ?, 79, 160 55,000 Hz @ 50% Duty = PWMOUT ?, 17, 36
13,000 Hz @ 50% Duty = PWMOUT ?, 76, 154 60,000 Hz @ 50% Duty = PWMOUT ?, 16, 33
13,500 Hz @ 50% Duty = PWMOUT ?, 73, 148 65,000 Hz @ 50% Duty = PWMOUT ?, 14, 31
14,000 Hz @ 50% Duty = PWMOUT ?, 70, 143 70,000 Hz @ 50% Duty = PWMOUT ?, 13, 29
14,500 Hz @ 50% Duty = PWMOUT ?, 68, 138 75,000 Hz @ 50% Duty = PWMOUT ?, 12, 27
15,000 Hz @ 50% Duty = PWMOUT ?, 66, 133 80,000 Hz @ 50% Duty = PWMOUT ?, 12, 25
15,500 Hz @ 50% Duty = PWMOUT ?, 64, 129 85,000 Hz @ 50% Duty = PWMOUT ?, 11, 24
16,000 Hz @ 50% Duty = PWMOUT ?, 62, 125 90,000 Hz @ 50% Duty = PWMOUT ?, 10, 22
16,500 Hz @ 50% Duty = PWMOUT ?, 60, 121 95,000 Hz @ 50% Duty = PWMOUT ?, 10, 21
17,000 Hz @ 50% Duty = PWMOUT ?, 58, 118 100,000 Hz @ 50% Duty = PWMOUT ?, 9, 20
17,500 Hz @ 50% Duty = PWMOUT ?, 56, 114 105,000 Hz @ 50% Duty = PWMOUT ?, 9, 19
18,000 Hz @ 50% Duty = PWMOUT ?, 55, 111 110,000 Hz @ 50% Duty = PWMOUT ?, 8, 18 </font></pre></code>
 
Top