New 32 Channel PWM Object for Propeller
Daniel Harris
Posts: 207
Hi all,
Recently, I wrote a new PWM driver for the Propeller to be used as an LED controller. I know I know, who needs more objects to blink an LED? I just couldn't find a PWM object that gave me the number of channels, ease of use, and resolution I was looking for - so I wrote my own. This subject is a little near and dear to my heart because this was the very first thing I ever did on a microcontroller (it was a PIC16F628, actually). Years later, I have Propeller-ized my original PIC ASM, which now does 32 times more channels in 25% of the number of instructions, and probably runs 20x faster than the original (which only did one PWM at a time).
This object will PWM up to 32 channels (every Propeller IO) with 32-bit resolution. I realize 32-bits of resolution is overkill for most, so I added a "SetDutyScaled" method that accepts an 8-bit duty cycle value and scales it to fit the 32-bit requirement. The object simply runs as fast as it can without any delay. I haven't calculated or measure the period, so I cannot actually tell you what frequency it runs at. For now, you also cannot set a frequency. This will probably be updated in the next release. Suffice it to say that it runs plenty fast - you won't notice any glitches!
Any questions or comments, post 'em here!
Thank you guys!
Daniel
Recently, I wrote a new PWM driver for the Propeller to be used as an LED controller. I know I know, who needs more objects to blink an LED? I just couldn't find a PWM object that gave me the number of channels, ease of use, and resolution I was looking for - so I wrote my own. This subject is a little near and dear to my heart because this was the very first thing I ever did on a microcontroller (it was a PIC16F628, actually). Years later, I have Propeller-ized my original PIC ASM, which now does 32 times more channels in 25% of the number of instructions, and probably runs 20x faster than the original (which only did one PWM at a time).
This object will PWM up to 32 channels (every Propeller IO) with 32-bit resolution. I realize 32-bits of resolution is overkill for most, so I added a "SetDutyScaled" method that accepts an 8-bit duty cycle value and scales it to fit the 32-bit requirement. The object simply runs as fast as it can without any delay. I haven't calculated or measure the period, so I cannot actually tell you what frequency it runs at. For now, you also cannot set a frequency. This will probably be updated in the next release. Suffice it to say that it runs plenty fast - you won't notice any glitches!
Any questions or comments, post 'em here!
Thank you guys!
Daniel
spin
22K
Comments
My editors, vim, kate, Sublime Text 2, can at least handle the box drawing characters , as used around the license conditions. But they throw up on the schematic symbols and such.
Having schematics drawn like that is frustrating and not useful.
Especially since those thoughtful people bringing us unicode include symbols for smilies, snow men, playing cards and the like but not resistors and capacitors etc.
Nicely commented! Even I can figure out how it works... :-)
dgately
I've also removed those proprietary Parallax font characters. I haven't heard any serious grumblings about moving away from the font, but it does come up from time to time.
Thank you guys for taking the time to check it out. I really appreciate your feedback! After thinking about it a little more, it is particularly good for PWMing LEDs, but not so much for motors. Perhaps I'll rename it for future releases.
Cheers!
When you convert SPIN files from UTF-16 into UTF-8, everything seems to magically become right with the world.
Still those timing diagrams come out as square boxes in: vim, kate, Sublime Text, LibreOffice.
Yes, I don't have a Parallax font installed. That's my point, needing a custom font is flawed. You can't expect it to be everywhere.
Edit: Oops. How to make oneself look an ***. I did that again and now the timing diagrams look ok in vim, kate and sublime.
All screwed up in LibreOffice though. Unless we change to a mono-space font but then we don't have compilable file anymore.
[h=2]***[/h]1. a long-eared, slow, patient, sure-footed domesticated mammal, Equus asinus, related to the horse, used chiefly as a beast of burden.
2. any wild species of the genus Equus, as the onager.
3. a stupid, foolish, or stubborn person.
Why is regular English language being censored?