Main Site Documentation

Multiple PWMS


#1

Are all of the PWM outputs synchronized? Say, I set 4 differnt PWMs duty cycles, do all 4 pulses begin at the same time? Can this relation be adjusted?
Can some of the PWM’s be at a different freq?

i see many examples with just 1 PWM signal, but not more than one

This is a cobra board


#2

PWMs run off the same clock/timer (however it’s done internally on the chip). You can only set one frequency, and the frequency dictates the rising edges which will always be in alignment.


#3

[quote]You can only set one frequency, and the frequency dictates the rising edges which will always be in alignment.
[/quote]
I hate to say it but I have two freqs going at once & they are not locked together (PWM0 & PWM1).

            PWM pwm0 = new PWM(GHIElectronics.NETMF.Hardware.PWM.Pin.PWM0);
            pwm0.SetPulse(71420, 35714);

            PWM pwm1 = new PWM(GHIElectronics.NETMF.Hardware.PWM.Pin.PWM1);
            pwm1.SetPulse(7142, 2000);

I’d expect these to be locked, since one is 10x of the other freq

If I make both periods 71420, then they are locked, but the narrow pulse begins about 3/4 of the way into the wider pwm. If it make the two periods 71420 & 71430 they stay locked, which is impossible! These pulse are still out of alignment. They may have the same freq due to some truncation of 714xx.

If I do:

            PWM pwm0 = new PWM(GHIElectronics.NETMF.Hardware.PWM.Pin.PWM0);
            pwm0.SetPulse(1000000, 500000);

            PWM pwm1 = new PWM(GHIElectronics.NETMF.Hardware.PWM.Pin.PWM1);
            pwm1.SetPulse(500000, 250000);

I get two freqs, but the two pwms creep slowly against each other,as though the freq are not exact multiples…maybe each has +/-1 errors ,so then they are not exact multiples (ex: 20/40 vs 21/41)

Is there any reliable detailed timing description of using these PWM signals?


#4

ah-ha
if I subtract 1 from both, I get 2 locked waveforms of the two freqs , but the pulses are way out of alignment…still strange

            PWM pwm0 = new PWM(GHIElectronics.NETMF.Hardware.PWM.Pin.PWM0);
            pwm0.SetPulse(1000000-1, 500000);

            PWM pwm1 = new PWM(GHIElectronics.NETMF.Hardware.PWM.Pin.PWM1);
            pwm1.SetPulse(500000-1, 150000);

#5

I’ll stand corrected, if that’s what you’re seeing.

[quote]Yes, to configure PWM (internally) we give it the period and then the high pulse length.

The fastest you can do is
2xclock period
1xclock high pulse
…that is 50% duty

In order for you to get 25% duty you need a clock of 4x minimum
4xclock period
1xclock high pulse

This is better explained in user manual http://www.keil.com/dd/docs/datashts/philips/lpc23xx_um.pdf

Note that GHI also provides “Register” class and through it, you can write your own PWM to fit any specific needs.
[/quote] (from http://www.tinyclr.com/forum/2/2415/) so you can always refer back to the datasheet and get more info.

out of interest, how are you measuring this?


#6

Here’s the other relevant thread I used as my reference,
http://www.tinyclr.com/forum/2/4867/
where Gus said

[quote]All PWM signals share the same clock frequency. You can have different duty cycle though.
[/quote]
which i now assume means that is explicitly on USBizi and doesn’t apply to EMX


#7

PWM signals are not guaranteed to be in sync. Some chips have one timers, others have more. You can test this by changing the frequency on one and seeing if it effects the other.

You may want to use register access to make your own PWM drivers to fit your needs.


#8

fyi, from GHI

[quote]USBizi
All PWM pins share the same timer. Changing one PWM frequency will affect the others.

EMX
Some PWM pins share the same timer. Changing one PWM frequency will affect the others.
PWM0 and PWM 2 share the same timer.
PWM1, PWM3, PWM4 and PWM5 share the same timer.

ChipworkX
Only one channel is available (0) with four frequencies: 391 KHz, 195 KHz, 98 KHz and 49 KHz.
[/quote]

If there are pwms on 3,4,5 they should all be in sync, coming from the same timer, but what is the timing between them? how is it set, or is the timing between them just luck of the draw?


#9

This is done in hardware. There is no timing difference in between PWM from the same timer.

The LPC24xx user manual will give you full details on the internals.


#10

I looked at the datasheet & think I can do som ethings I need just by manually setting some values in the timer & pwm registers, without any custom asm code needed. Then the chip will d o as I commnd :wink: :)I believe I can just send these register values from normal managed code, without needing RLP, correct?

Are there any gotchas to be worried about or on the lookout for?


#11

Yes you can write a complete custom PWM driver using register class.