PWM duty cycle not adjusting

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

Moderators: Benj, Mods

Post Reply
singerinst_ben
Posts: 22
Joined: Fri Jun 20, 2014 4:41 pm
Location: England, UK
Has thanked: 10 times
Been thanked: 7 times
Contact:

PWM duty cycle not adjusting

Post by singerinst_ben »

Hi,

I think I've found a problem with the PWM component. On our project I have the period set to 255, the prescale 16 and the duty cycle 128. This gives me a frequency of 2.92Hz, a period of 3.41us and an on and off of around 171us, so a 50/50 duty cycle.

When we scope the output on the MIAC that the PWM is running through (A) we have found the duty is vastly different - actual amount 90/10 (30us off, 300us on). Adjusting the duty to 64, you would expect the on duty to be around 25%, and again setting it to 32 you would expect 12.5% but when scoped it doesn't change noticeably. It updates correctly on the simulation though.

Any help is much appreciated!

Regards,

Ben

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: PWM duty cycle not adjusting

Post by LeighM »

Hi Ben,
I cannot see any fault. I’ve attached a test program.
Regards,
Leigh
Attachments
MIAC PWM TEST.fcfx
(5.37 KiB) Downloaded 364 times

singerinst_ben
Posts: 22
Joined: Fri Jun 20, 2014 4:41 pm
Location: England, UK
Has thanked: 10 times
Been thanked: 7 times
Contact:

Re: PWM duty cycle not adjusting

Post by singerinst_ben »

Apologies - I wasn't setting the duty and period after enabling the PWM, it appears you have to set these each time you enable. Is there any way of reducing the frequency further, we are using a prescale of 16 to reduce the frequency, but could do with dividing this by 2 again to further reduce the frequency. Is this possible? The maximum prescale appears to be 16.

Regards,

Ben

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM duty cycle not adjusting

Post by Benj »

Hello,

It looks like the device only has a max prescaler of 16 for the PWM so the hardware PWM cannot be run any slower.

You could use a timer based software PWM and this should give you much more scope for setting the frequency.

An example of software based PWM using a timer interrupt can be found here.
http://www.matrixtsl.com/article.php?a=52

The count variable sets the period in multiples of the timer interrupt timeout and the PWMx variables set the various channel dutys.

Let me know how you get on.

singerinst_ben
Posts: 22
Joined: Fri Jun 20, 2014 4:41 pm
Location: England, UK
Has thanked: 10 times
Been thanked: 7 times
Contact:

Re: PWM duty cycle not adjusting

Post by singerinst_ben »

Thanks, great idea, I hadn't thought of that. Our stepper river board should arrive later so once we have given it a go I'll let you know if we need to go the software route! Thanks again for your help.

Ben

Post Reply