• AVR Freaks

Hot!dsPIC33CK256MP508 PWM synchronization

Author
Elfina
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2021/01/19 05:29:40
  • Location: 0
  • Status: offline
2021/01/19 23:14:19 (permalink)
0

dsPIC33CK256MP508 PWM synchronization

Hello,
 
What is the correct way to synchronize between 2 PWM signals?
I have 2 PWM generators:
  1. First generator with freq 45kHz with different DC each period (should be sine wave)
  2. Second generator with 110 Hz freq 50% DC.
The sine wave of first PWM generator should be synchronized with start of second generator.
I have one interrupt for first generator which calculate and set  correct value of DC and second generator interrupt which should restart the sine wave.
I have tried in several ways, but I didn't succeed to synchronize between them. 
I added also third PWM generator, just for test, with 220 Hz frequency to see if it will be synchronized with the 110 Hz PWM signal. But I see, that after power up they are start together and seems to be synchronized, but with a time the gap between 2 signals is growing. Both generators are with the same clock divided frequency.
 
Attached is pwm.c generated by MCC.
 
Will appreciate any help 
#1

1 Reply Related Threads

    du00000001
    Just Some Member
    • Total Posts : 4114
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33CK256MP508 PWM synchronization 2021/01/20 16:00:29 (permalink)
    2 (1)
    Your profile indicates "Professional 1+ years with MCHP products" - - - I consider this a blunt lie  Smile: Smile
    EE Student ?
     
    I'm not sure whether you posted all relevant code (e.g. I do not see ISR code other than just clearing the IFs), but if PG1 corresponds to the 110 Hz PWM and PG2 corresponds to the 220 Hz PWM, I can tell you why these drift out-of-phase over time:
         because 2*28409 != 56816
    [ OK - if PGxPER is the real period in clock cycles - 1 (I didn't check this into the last detail), the reaon would be
         because 2*28410 - 1 != 56817  ]
    So sit down and redo your math.
     
    The synchronization with your high frequency (45 kHz) is a bit trickier: provided you apply the same kind of PWM period scheme, you should increase this frequency to 45.100 kHz. If htis is not possible . . . well, there are other ways to force synchronization by skipping DC values in the HF PWM. It's just that 45000 is no integer multipple of 110, so no "natural" syncronicity can be achieved.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    Jump to:
    © 2021 APG vNext Commercial Version 4.5