Generateing 16Khz signal with PWMPAL?
datac99
Posts: 15
So I've got a PWM pal that I wanted to use to drive an OSMC (High powered H-Bridge). The documentation for the OSMC recommends a 16Khz PWM frequency... Since I found out the PWMPAL glitches when you change duty cycle I've given up on haveing rampable speed control, and just want to do a few steps... Say 25%, 50%, etc...
So I do the math and I get the following:
PWM For Freq of 16Khz
Frequency(Hz)=1/Period
1/X=16000
X=0.0000625
Period = 0.0000625
For 50% duty cycle On time = 0.0000125
PWM PAL Period = 2.5
ON TIMES
2.5 x .25 = 0.625 On Time (25% Duty Cycle)
2.5 x .5 = 1.25 On Time (50% Duty Cycle)
2.5 x .75 = 1.875 On Time (75% Duty Cycle)
2.5 x 1 = 2.5 On Time (100% Duty Cycle)
OFF TIMES
2.5 - 0.625 = 1.875 Off Time (25% Duty Cycle)
2.5 - 1.25 = 1.25 Off Time (50% Duty Cycle)
2.5 - 0.625 = 0.625 Off Time (75% Duty Cycle)
2.5 - 2.5 = 0 Off Time (100% Duty Cycle)
And that's about as far as I get... if I try to set any of these numbers in a word var to be passed to the PWMPAL like in the app notes I get an error... Does not like the "."... So I don't really know where to go with this... I know I'm just missing some basic knowledge about how to convert these numbers to binary, but when I try the stuff I look up it still does not seem to work.... Can I only feed this thing whole numbers? How do I go about figuring out the max frequency that's equal or less then 16Khz that I can work with...
Please help a poor noob.
So I do the math and I get the following:
PWM For Freq of 16Khz
Frequency(Hz)=1/Period
1/X=16000
X=0.0000625
Period = 0.0000625
For 50% duty cycle On time = 0.0000125
PWM PAL Period = 2.5
ON TIMES
2.5 x .25 = 0.625 On Time (25% Duty Cycle)
2.5 x .5 = 1.25 On Time (50% Duty Cycle)
2.5 x .75 = 1.875 On Time (75% Duty Cycle)
2.5 x 1 = 2.5 On Time (100% Duty Cycle)
OFF TIMES
2.5 - 0.625 = 1.875 Off Time (25% Duty Cycle)
2.5 - 1.25 = 1.25 Off Time (50% Duty Cycle)
2.5 - 0.625 = 0.625 Off Time (75% Duty Cycle)
2.5 - 2.5 = 0 Off Time (100% Duty Cycle)
And that's about as far as I get... if I try to set any of these numbers in a word var to be passed to the PWMPAL like in the app notes I get an error... Does not like the "."... So I don't really know where to go with this... I know I'm just missing some basic knowledge about how to convert these numbers to binary, but when I try the stuff I look up it still does not seem to work.... Can I only feed this thing whole numbers? How do I go about figuring out the max frequency that's equal or less then 16Khz that I can work with...
Please help a poor noob.
Comments
So okay... Someone will surely argue that this is Darwinism at it's finest but I really need help figuring this out, the end product of all this is an electric skateboard with a 4HP electric motor... So I really, really, need some speed control... Right now I've just got it running at half power with an on/off switch.... So I guess you could say that PWM frequency right now is about .1 Hz... I keep it on from about 10 sec and then kill it when it gets going to fast... It kind of sucks but after spending a month on the mechanicals I've just gotta' ride it...
Thanks again,
PM
It appears what you're trying to do cannot be done with the PWMPAL. Please note the following from the documentation.
Generate frequencies from 0.3 Hz to 20 kHz; duty cycle independent *
* Duty cycle independence is not available for the entire range of output frequencies
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
EDIT: I started typing this before I saw Chris's answer.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (D Faust) : 8/20/2007 3:09:48 PM GMT
Thanks both for answering my plee...
Chris,
So what I get from that is that it works over the specified range of frequency's just not at all of them... So somewhere around the 16 Khz range I should be able to find a frequency that is devisable in such a way that I get the whole numbers that I have to feed the PWMPAL right? I'm not stuck on 16 Khz, that's just the max I can feed my H-Bridge... Like Faust said, I just need something that's up there so I get smooth operation. I tried running the demo code that does a 100Hz 25-100% ramp and it works okay, it's just rough and noisy...
I guess my question is probably more appropriate for a high school math teacher rather then this forum (dammit I wish I had paid more attention in school... why didn't they tell me you needed math for cool stuff, not just figuring out which train would get to Boston first???)
But I just don't know how to work backwards to find a frequency that's greater then say 10K and less then 16K and produces integer pwmpal units when I run it though the timing formulas. I know, I'm thick-as-a-brick, but I'm trying...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support