MIAC dsPIC - PWM on Motor Outputs

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Post Reply
User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

MIAC dsPIC - PWM on Motor Outputs

Post by Jay Dee »

Hi Guys,
Another feature I'm struggling with on the dsPIC MIAC.
I've been playing with settings for an hour or so and I just cant get a PWM signal out of the Motor Pins.
MIAC_dsPIC_Manual_Pulse.fcfx
(17.52 KiB) Downloaded 332 times
I have Enabled the motor outputs by setting F0 and F1 to a logic 1.
I have set the PWM components setting to re-map the pin to F0
Enabled the PWM
Set a duty cycle. (Set duty of 32, with a prescaler of 64 = 50% PWM)

Just toggled the 'Alternative pin' option... still no PWM out.

Any ideas where I'm going wrong? Thanks J.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: MIAC dsPIC - PWM on Motor Outputs

Post by LeighM »

Hi J,
You are right, this is very odd, looks like PWM is broken, it did work, but I'm not getting much sense out of it myself at the moment.
Investigations continue ...
Thanks!
Leigh
ps. the duty cycle is a fraction of the period, not the prescale

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: MIAC dsPIC - PWM on Motor Outputs

Post by LeighM »

Hi J,
Like you, I think I fell into a few traps. But I now find it all works OK.
So here are a few examples:

First a simple PWM control of a single output...
MIAC PWM OUTPUT C.fcfx
(9.68 KiB) Downloaded 322 times
Second example is using the PWM on the F1 enable of C/D, such that they are used in full bridge mode...
MIAC PWM OUTPUT C+D.fcfx
(10.55 KiB) Downloaded 309 times
The above example works but needs the trick of re-enabling the PWM after using OutputON (as that disables the PWM)

So this third example uses direct port control instead...
MIAC PWM OUTPUT C+D with port control.fcfx
(10.18 KiB) Downloaded 323 times
Hope that helps,
Leigh

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: MIAC dsPIC - PWM on Motor Outputs

Post by Jay Dee »

Hi,
A bit more information after some bench testing this end.

When assigning a PWM direct to a motor output pin D4, D5, D6,D7.
To have to enable the output by setting the relevant OutputON using you MIAC output macros.
If you change either the Duty, Period Overflow or Pre-Scaler using the MIAC macros, you must re-set the OutputOn.
NOTE! When making changes to your Period OverFlow and PreScaler values in the PWM properties box, the Frequency shown is double the actual output PWM frequency you'll measure on Hardware with a scope.
MIAC PWM OUTPUT_Changing Duty and PreScaler.fcfx
PreScaler Duty Period Overflow
(10.41 KiB) Downloaded 340 times
When assigning a PWM to the MOTOR ENABLE pins F0 (Enable Outputs A & B) or F0 (Enable Outputs B & C)
The rough maximum frequency that this pin will respond to is ~6kHz. (Note above applies, this is 6kHz calculated in FC or roughly 3 kHz measured on hardware.)
So just adjust your prescaler and period overflow to keep below this limit and it works fine.

To stay below this limit, you'll often have to put in large values for your Period RollOver.
For example, With a PreScaler of 1, the Period rollover has to be over roughly 11000. As such, when setting the duty you have to use the SetDutyCycle10Bit macro.
J.

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: MIAC dsPIC - PWM on Motor Outputs

Post by Jay Dee »

Question :)
In the PWM properties you can select the PWM Timer and you adjust the Period Overflow and Prescasler of that timer.
Is it correct to assume that if you have an Interupt based on the same time is will also be effected?
Seems obvious I guess, but you just need to share your Timers out so that they dont interfere. You can pick timer 1-5 for PWM and 1-9 for Interrupts.
Given that other behind the scenes (non user defined) macros may also be using timers and interupts, do you guys at Matrix preference any timers for your use and which are best avoided by us end users?
J.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: MIAC dsPIC - PWM on Motor Outputs

Post by LeighM »

Hi J
Thanks for your investigations.
We don't use any timers internally, so you are free to use all in your application.
The PWM frequency calculations look OK to me, here is my test program that sets output C PWM at 5KHz and modulates the Duty cycle...
MIAC_PWM_C_DUTY.fcfx
(11.25 KiB) Downloaded 355 times
Cheers,
Leigh

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: MIAC dsPIC - PWM on Motor Outputs

Post by Jay Dee »

Hmm Indeed odd.. your SetDutyCycle10Bit seems to work just fine in your example, I struggled on my basic function tests. I'll have another look if I get time today.
But I'm learning more about the PWM control everyday!! haha
Thanks Leigh.

Post Reply