Smartpin PWM tutorial
ke4pjw
Posts: 1,169
in Propeller 2
Is there an application note or tutorial on using the PWM modes of the smartpins?
Comments
https://drive.google.com/file/d/1iTA4dwbntgaUVnpt0-9pDcFCVSsvCUnU/view?usp=sharing
Propeller 2 Smart Pin Supplementary Documentation by Jon Titus is a commenting-enabled Google Doc with examples and further explanation beyond the Silicon Documentation
I guess you're after the details of what's different between the three smartpin modes. And since we're looking at differences we may as well include the NCO Duty mode too.
Sawtooth mode is your regular PWM. It produces a simple duty from 0% (flat low) to 100% (flat high). Output is high on leading portion of period.
Triangle mode is a phase midpoint timed version of the sawtooth. It equally leads and lags any adjustment. Timings are doubled numerically. Compared to sawtooth, the period is doubled and output high is shifted to middle of period. Phase centring isn't usually needed in most applications.
SwitchModePowerSupply mode has a set of inputs for gating when pulses occur. It's same PWM as sawtooth otherwise. Not well documented at all. I've used it once as a gated clock gen just by setting 50% duty.
Duty mode is technically Pulse Density Modulation rather than Pulse Width Modulation. Frequency is product of duty, with 50% duty producing highest frequency. PDM has superior DAC performance compared to PWM. Useful to know for such applications. However, in power applications, PDM will destroy the power stage switching transistors. So know when to use it.
PS: Jon Titus's diagrams of the triangle and sawtooth are excellent. He's got the polarity and phase correct. Thanks for the link Rosco.
There is a section about using smart pin PWM in this article I wrote from Nuts & Volts when the P2 first came out.
-- https://www.nutsvolts.com/magazine/article/an-introduction-to-the-parallax-propeller-2
My basic PWM objects are pretty easy to follow and should help you make sense of things.
What exactly are you planning to do with the PWM? LEDs or something with higher power (motors)?
Thanks everyone for the resources! @JonnyMac even though I am not driving an LED, I used your example from the Nuts and Volts article. I just changed the frequency to match what I am driving. It worked splendidly.
Again, thanks!
--Terry
Excellent! As you can see, the PWM object is general-purpose -- I added the DMX-compatible start() method for LEDs because I do so much of that. Glad it the object worked for you!