Shop OBEX P1 Docs P2 Docs Learn Events
120deg phase offset pwm in one cog — Parallax Forums

120deg phase offset pwm in one cog

bmentinkbmentink Posts: 107
edited 2015-03-09 11:17 in Propeller 1
Hi There,

I am trying to generate two 50% duty square waves with 120deg phase shift in one cog using the counters, at the highest freq I can, but still having some resolution to be able to change the phase.
The closest I can see as an example is the counterpwm.spin file posted elsewhere on the forum, but I don't see anywhere in the code how to adjust phase.
Can anyone give me a clue how to do this ..

Cheers,
bernie

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2015-03-09 04:54
    Simple (untested) example. This assumes that no parameter needs adjusting. Counter B setup is delayed for d120 cycles (equivalent to 120 degree).
    '  d120: clock ticks covering 1/3 of the total cycle
    '  d240: clock ticks covering 2/3 of the total cycle
    ' value: clock ticks covering 1/2 of the total cycle
    '
    ' f = clkfreq/(d120+d240)
    '
    CON
      cycle = 30
    
    DAT             org     0
    
    '               counter/parameter setup omitted
    
    loop            waitcnt target, d120
                    neg     phsa, value
                    waitcnt target, d240
                    neg     phsb, value
                    jmp     #loop
    
    d120            long    cycle/3
    d240            long    cycle/3*2
    value           long    cycle/2
    
                    fit
    
  • bmentinkbmentink Posts: 107
    edited 2015-03-09 10:35
    Many thanks, will give it a go. I will modify the file above.
    The above .spin file requires passing start(pin,Freq,PwmAddr), can anyone remind me how to pass the PwmAddr pointer?

    Cheers,
    B
  • kwinnkwinn Posts: 8,697
    edited 2015-03-09 11:17
    (pin,Freq,@PwmAddr)
Sign In or Register to comment.