Shop OBEX P1 Docs P2 Docs Learn Events
Generateing 16Khz signal with PWMPAL? — Parallax Forums

Generateing 16Khz signal with PWMPAL?

datac99datac99 Posts: 15
edited 2007-08-20 17:49 in BASIC Stamp
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. wink.gif

Comments

  • datac99datac99 Posts: 15
    edited 2007-08-20 14:37
    Alright... So if this is really basic or something, could someone at least point me in the right direction? All the examples I see for the pwmpal somehow the math just always works out to be integers... Course whenever I do it I get fractions at the end of my calcs... And every time I do a search it's ether someone generating much lower frequency's so I can't learn anything from their code... Or it's one of 5000 posts saying how much someone loves the pwmpal, how great it works, how easy it is to use and asking what the best H-Bridge to use with it.

    So okay... Someone will surely argue that this is Darwinism at it's finest wink.gif 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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-08-20 14:52
    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
  • D FaustD Faust Posts: 608
    edited 2007-08-20 15:02
    For one of your first questions, you can only use whole numbers. You said the recommendation is to use 16kHz.(My guess this is for a very smooth flow to the motor) I didn't notice any glitches in your math, so I think you will have to use a lower frequency.(I might be slightly more jerky, but probably still unnoticable). After all it works with frequencies from 16kHz to .1Hz. [noparse];)[/noparse] If you have SX experience, you might want to program an SX for this purpose. (PWMPal uses an SX). I don't have experience with SX, but I have a PWMPal, so you would have to ask in the SX forum for the frequencies it could generate/the program you would use.

    EDIT: I started typing this before I saw Chris's answer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    

    Post Edited (D Faust) : 8/20/2007 3:09:48 PM GMT
  • datac99datac99 Posts: 15
    edited 2007-08-20 15:30
    Hey Chris and D Faust,

    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... wink.gif
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-08-20 15:45
    I would try my calculations for ranges of 9 or 10 kHz…That is where many motor controllers run their H-Bridges at. Without actually doing the math, it would appear that at 10 kHz you should be fine…I think you’ll have a resultant value of 1 for 25% and 2 for 50%, and so on. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • datac99datac99 Posts: 15
    edited 2007-08-20 17:49
    Ah... I guess that makes perfect sense... Chris, thanks very much.
Sign In or Register to comment.