Shop OBEX P1 Docs P2 Docs Learn Events
New 32 Channel PWM Object for Propeller — Parallax Forums

New 32 Channel PWM Object for Propeller

Daniel HarrisDaniel Harris Posts: 207
edited 2013-04-03 01:13 in Propeller 1
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

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-04-01 18:25
    It looks like a typo but right now it only serves 31 channels.
  • SRLMSRLM Posts: 5,045
    edited 2013-04-02 00:35
    I had a bit of trouble with the Parallax font. It turned all the characters in the last bit of the file to Chinese (or another Asian language? I can't tell). I don't remember if Parallax was planning on moving away from the proprietary Propeller font or not? Maybe you guys could get it into the major Linux font repo's.
    1024 x 618 - 47K
  • Heater.Heater. Posts: 21,230
    edited 2013-04-02 00:48
    Yep, the Parallax font is a pain.

    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.
  • dgatelydgately Posts: 1,630
    edited 2013-04-02 10:03
    Thanks Daniel,

    Nicely commented! Even I can figure out how it works... :-)

    dgately
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2013-04-02 11:06
    Good catch, Kuroneko! I've fixed and updated the download.

    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!
  • pedwardpedward Posts: 1,642
    edited 2013-04-02 23:56
    The font isn't the problem, it's a bog standard Unicode character space font. The problem is the stupid wide character encoding.

    When you convert SPIN files from UTF-16 into UTF-8, everything seems to magically become right with the world.
  • Heater.Heater. Posts: 21,230
    edited 2013-04-03 00:54
    Not in this part of the world it does not:
    $ iconv --verbose -f UTF-16 -t UTF-8 PWM32.spin > temp
    $ file temp
    temp: ASCII text, with CRLF line terminators
    

    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.
  • Heater.Heater. Posts: 21,230
    edited 2013-04-03 01:13
    In case anyone is wondering about the above post. From dictionary.com I get:

    [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?
Sign In or Register to comment.