Shop OBEX P1 Docs P2 Docs Learn Events
PWM phase sync — Parallax Forums

PWM phase sync

bennettdanbennettdan Posts: 614
edited 2011-03-29 02:48 in Propeller 1
Hello,
I have been looking through Beau Schwabe's PWM_32 code and its has the ability to sync three PWM signals 120 degrees apart it works fine but it has about a 15khz limit and I dont need the other functions of the code just the three phase sync PWM.
I know I can get a much faster PWM switching speed with PASM and I looking for advice on how to use mutiple pins from one counter?
Also is it possiable to launch mulitple counters without using a cog?
Thanks Dan

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-03-25 18:54
    bennettdan wrote: »
    I know I can get a much faster PWM switching speed with PASM and I looking for advice on how to use mutiple pins from one counter?
    A counter - if it's driving pins - can manage up to 2 pins (differential mode). As this is basically the same signal (inverted) it's probably not what you want. Which basically means each output requires its own counter. Can you elaborate on your exact requirements?
    bennettdan wrote: »
    Also is it possiable to launch mulitple counters without using a cog?
    Counters can only be used when the cog containing them is active. If it's fire-and-forget (counter) usage then the cog itself can run unrelated code.
  • bennettdanbennettdan Posts: 614
    edited 2011-03-25 19:12
    Beau's object has a phase sync ability which allows 3 pins to be 120 degrees apart but have the same pusle width. I want to be able to do the same thing but his object is limited to around 15khz and I want to be able to the same thing just at a faster switching rate.
    I have been working with the counter app note and will see what I can come up with but just wanted a point into the right direction as to be able to sync the three pins.
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-25 19:15
    What it boils down to is an offset which is applied to the 3 used phsx registers (with minor adjustments as setting the register will take time, unless you run 3 cogs in perfect sync). This shouldn't be too difficult. Just get the PASM part working (assumption on my part) and then we can figure out the rest.
  • bennettdanbennettdan Posts: 614
    edited 2011-03-25 19:58
    This attachment might be able to sync 3 cogs but the waitcnt would have to be adjusted I am sure.
    I have not tested this yet though.
    I dont really want to use three cogs if their is a way to do sync it in one cog, I will study on this some more thanks for the help.
    pwmasm_3Phase.spin
    pwmAsm - Archive [Date 2011.03.25 Time 21.49].zip
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-25 20:04
    You'll need at least 2 cogs (1.5 in fact in terms of counters). OTOH, if you dedicate a single cog to the task you probably could do the signal output manually (no counters). It puts some restrictions to minimum timing as you need to communicate with the hub at some point (for updates). Just thinking aloud here ...
  • pjvpjv Posts: 1,903
    edited 2011-03-25 23:10
    Hello Bennettdan;

    What is the maximum speed you are looking for?

    If it is below, say 50 or possibly 100KHz, then there is a very simple one cog solution if you employ my multi threading scheduler,

    If that is of interest to you then let me know and I will send you the scheduler kernel, but only if your application is not of a significant commercial nature. If it is, then a very small per-unit license fee would apply.

    Cheers,

    Peter (pjv)
  • bennettdanbennettdan Posts: 614
    edited 2011-03-25 23:53
    Peter,
    Thanks for the help this might turn into a comercial product so right now I plan to work out the details with testing. I am working on a brushless 3 phase AC servo Amp for use on CNC equipment I have here in the shop but if it works out I plan to sell it at a hobbist cost.
    I plan to switch my power stage around 15k to 20khz.
    I have been looking into some other PWM examples that dont use counters they just sync off the system counter.
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-26 01:25
    Out of curiosity, when the duty cycle changes how does this affect the outputs? Let's say output 0 starts a cycle with the new duty value, do outputs 1 and 2 finish their current cycle with the old value before they pick up the new one? My assumption is they do, just want to get a second opinion.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2011-03-26 03:04
    If you use the counters you will get excellent resolution and frequency but it will need two cogs. I've been doing some assembly PWM using the counters and attached is some example code. There is a point in the main loop where you can add other code (I implemented PID in that space) so it can be quite efficient, the table at the top indicates how much space for instructions there is in theory for different frequencies and resolution.

    Phil (PhiPi) has also made an excellent PWM object that uses the video hardware and up to 8 channels, it operates at high frequency though is a little slow to change the duty.

    This issue of the phase shift between the three channels, will this actually need to be done at the level of the PWM generation or will the phase shift be introduced in the modulation of the duty of the channels? i.e. if you wanted to produce a sinusoidal field variation you could modulate the duty in a sinusoidal manner and you would introduce a phase shift between the modulation of each channel while the PWM which could be at a much higher frequency could be synced perfectly. That is certainly the case for brushless DC motors used in model aircraft except they don't even bother with the sinusoid.

    Graham
  • pjvpjv Posts: 1,903
    edited 2011-03-26 08:25
    Graham;

    The duty concept directly from the counters works very well for many things that can tolerate fast and frequent switching transitions. Not so with power stages for motor drivers. They don't like the many short durations the counters produce, and causes significant unnecessary heating. A slower speed such as the 20 or so KHz Bennettdan suggests is much better, and that can't be done with the simple use of a counter in "duty" mode..... cog intervention is required.

    Cheers,

    Peter (pjv)
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2011-03-26 12:51
    Peter,

    I am not using the counters in duty mode, this is true PWM (can vary duty 0-100% at a fixed f) and 20khz is no problem. It does use cog intervention but still leaves a lot of time for other code to run. Check my code out.

    Graham
  • bennettdanbennettdan Posts: 614
    edited 2011-03-26 13:40
    @Graham I will look at the code sample I am also interested in PID control of the motors I am using also. Thanks

    @pjv Peter I Don't mind using a one or even two cogs but if their is a way to do it in as little as one cog then that would be ok.

    @ kuroneko I dont plan to change the duty cycle very much just set it to around 50% but I will ahve to reverse the Phase Sync to allow the motor to trun backwards.

    This will be a true sine wave style 3 phase inverter I have it worked out as fars as how I plan to control the sine wave frequency its just the phase sync is the next step.
    Thanks again for the help.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2011-03-28 04:51
    bennettdan wrote: »
    This will be a true sine wave style 3 phase inverter I have it worked out as fars as how I plan to control the sine wave frequency its just the phase sync is the next step.
    Thanks again for the help.

    As I mention above I think the phase shifting is at the level of the sin modulation not at the PWM level. Like this:

    fig4.gif

    The duty is varied to create the sine wave. The sine waves need to be out out phase but not the PWM (although the duties given to the PWM routines will be out of phase).

    Unless I've missed something

    Graham
  • bennettdanbennettdan Posts: 614
    edited 2011-03-28 17:36
    @Graham yes you are correct with the varied duty cycle to create the sine waves I plan to do basically the same thing but I also want to be able to change the base voltage of the sine wave not just the frequency of it so I will tell you what I have in mind.

    I plan to output three 120 degree in sync PWM pulses at 10khz to 20khz on three prop pins then also a fourth pin I plan to output a Sine wave of the base 20hz to 200hz then using three Comparators I plan to feed one side the PWM and the other the Sine and when you look at the output of the Comparator it will look like the Picture of the varied duty cycle PWM sine wave.
    I believe this will allow me to vary the voltage of the DC buss with PWM and also the speed of the motor with the varied sine wave.
    Most AC drives dont filter out the high frequency pulses but I plan to use a Three phase filter which is basically a low pass filter with a cutoff of around 200hz.
    I am not home right now so I cant test this code but if you or anyone wants to test this PASM program I wrote to output 3 120 degree in sync pulses of 50% duty cycle at 10Khz I would not mind at all this code is not finished I plan to add the math to allow this to be ran at other frequencys.

    3Phase PWM.spin
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2011-03-29 02:48
    What you suggest will not work, comparing a PWM signal with a sinewave does not give you the waveform above. You can compare a triangle wave with a sine wave as per this diagram.

    image096.gif

    BUT these are the tricks used before microcontrollers! As the first diagram shows PWM can create any voltage between +/- the bus voltage so you can easily create sine waves of varying amplitude and frequency directly from the propeller. You just need a sine look up table, the faster you move through the table the higher the frequency and the greater the multiplier between the table and the PWM duty the greater the amplitude.

    In either case there is no need for the PWM itself to be phase shifted.

    Graham
Sign In or Register to comment.