Shop OBEX P1 Docs P2 Docs Learn Events
PWM with CTRA, variable on time, off time? — Parallax Forums

PWM with CTRA, variable on time, off time?

T ChapT Chap Posts: 4,223
edited 2008-09-26 00:40 in Propeller 1
I need to control something with PWM, and will need to experiment with the on time and off time.

I have been testing the CTRA but can only find methods to adjust the duty using 001100, making variable on and off times not possible. Maybe I have missed something.

The PWM.spin object does the job, but requires a cog.

Is there any solution for making a counter accomplish this goal without the assembly object and additional cog?

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-25 16:54
    You can't do variable on/off times with just a counter. You need to have a cog involved.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-25 16:55
    Originator,

    No, not really. For a counter to generate true PWM on its own, it needs either to reload PHSx from two different sources or reload from one source and trigger a second counter for the alternate phase. The Propeller counters don't have either capability. Consequently, unless DUTY mode is adequate, PWM needs to be mediated in software. For even moderate PWM rates, this entails assembly code.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • T ChapT Chap Posts: 4,223
    edited 2008-09-25 17:07
    Thanks guys.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-09-25 17:25
    I think yo can enlist both CTRA and CTRB together to the task, both addressing the same pin. Both run at the same frequency but with offset phases. The counter outputs are OR'd, so the pin is high when either is high and low when both are low. The range without further tricks is either 50% to 100%, or 0% to 50%, depending on how you look at it. A choice of either with differential output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • T ChapT Chap Posts: 4,223
    edited 2008-09-25 17:38
    That is a good idea. I will need smooth ramping from 0% duty to 100%, 100% - 0%, adjustable Freq, which seems to mean either use the PWM obj or build a custom loop that just controls the pins.

    Post Edited (Originator) : 9/25/2008 5:43:44 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-25 17:56
    Tracy, that's brilliant!

    -Phil

    Addendum: The tricky part will be setting the relative phases in Spin. It can probably be done by doing a WAITCNT, clearing PHSA, then doing another WAITCNT before clearing PHSB. The latencies between the WAITCNTs and the clearing of PHSx should be equal. The relative phases will depend on the programmed delay of the second WAITCNT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 9/25/2008 6:05:40 PM GMT
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-09-25 18:15
    Thanks Phil, but I must add that that PWM solution has come up here before. To return the complement, it is nothing compared to the six counters you enlisted for in the homodyne radio receiver!

    Originator, with an external XOR gate and two propeller pins, it could do the whole 0-100% range.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • TJHJTJHJ Posts: 243
    edited 2008-09-26 00:40
    On this note, Does anyone know what the maxium frequency the PWM object is capable of?

    Thanks TJ
Sign In or Register to comment.