Page 1 of 1

pwm 2+2

Posted: Mon Dec 28, 2009 10:36 pm
by Bobes
Hello,
this is more of a PIC specialist question:
I am using dsPIC33fj128mc802, and I need to generate 4 PWM signals:
to drive 2 DC brushed motors (same frequency around 10 kHz but independent duty cycle)
and 2 "modeller" servos (same frequency 50Hz but independent duty cycle)

my question is: is it possible to generate 2 PWM on one PWM module each with different frequency?
I have tried it out, but I have got error from the compiler (I do not have my DevKit with me right now, so HW testing is not possible at the moment).

Please excuse me, I am quite a beginner...
I will appreciate any help and/or advices
Thanks
Kind regards
Josef

UPDATE: I have tried removing second servo PWM (removed PWM2_motor block) and it was compiled without an error (having on PWM1_motor block 3 channels with 2 different frequencies) On one hand this may mean that it can be done, but on the other: I am more confused: why it does not work?

Re: pwm 2+2

Posted: Tue Jan 19, 2010 12:37 pm
by Bobes
update: it is not possible to run one PWM module with two different frequencies. :(

Re: pwm 2+2

Posted: Tue Jan 19, 2010 1:12 pm
by LubinKerhuel
Hi Josef,

It may not be possible to get two different PWM period from one "PWM motor" peripheral. However, you may use an Output Compare block that is capable to generate PWM signals with different periods.

I just updated the PWM help page http://www.kerhuel.eu/wiki/Block/PWM_Mo ... ut#Periode
Please feel free to complete wiki help page for others usefull informations.

Lubin

Re: pwm 2+2

Posted: Tue Jan 19, 2010 1:31 pm
by Bobes
Hello Lubin,
yes... I have reached this conclusion as well.

However I have now something else: I was trying to set the period externally, but I was asked for uint16. Is this correct?
Thanks

Re: pwm 2+2

Posted: Tue Jan 19, 2010 1:59 pm
by LubinKerhuel
Bobes wrote: However I have now something else: I was trying to set the period externally, but I was asked for uint16. Is this correct?
Yes, That is correct.
Input value must be :

requestedTime (in s) * { PWMmax (variable defined in the workspace) / Periode set in the block (in s) }

You'll get a large value that you may round off. See the many example for more details.

Lubin