PWM issues

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

PWM issues

Post by Lord Grezington »

Hello All

I am trying to use the PWM outputs form the dsPIC33EP32MC504 to gernerate various waves from data stored in a LUT. In general it works very well, however I seem to be getting glitches on the falling edges (aways seems to be on falling, and never rising).

As you can see in the triangle wave example, as the PWM duty is reducing, for some reason the duty glitches in the high state so stays on longer than it should (never in the low). The glitch also seems to move accross the peroid of the waves on a sort of pattern that repeats every few periods.

Things I have tried:
I have tried chaning the clock sourse from the PWM component
I have tried changing the PWM frequencies.
I have tried changing the number of values within the LUT per period of the sine wave
I have tied using both pull and and pull down reistors.
I have tried changing all the values between bytes and ints (for some reason when the addresses are ints, this resets the whole program every few seconds).

I have added two examples. One where you can see both the PWM generated and the trianlge wave (the same signal but run via a filter). The other one is a sample of two different PWM modules filtered running together and showing a similar patten.

Any ideas will be useful, I have attached my test program.

Thanks
glitch Same signal.jpg
glitch Same signal.jpg (122.73 KiB) Viewed 2275 times
Two diffenet PWM's with pattern.jpg
Two diffenet PWM's with pattern.jpg (150.68 KiB) Viewed 2275 times
Attachments
Test.fcfx
(24.65 KiB) Downloaded 161 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PWM issues

Post by QMESAR »

Hi.
In my humble opinion the problem is a PWM Resolution problem
In basics the PWM has a specific resolution for a given frequency and if there is a small mismatch between the set period and set DC you will see this in any signal generation probably not when driving for example a DC bridge for a DC motor but if you generate a signal (which has level and phase )
you will see this clearly .
If I would do this I will use a C Icon and use the correct vales for Period and duty cycle which correspondence to the PWM Resolution for that frequency.
I know this sounds weird but the PWM is a tricky module on the dsPIC or any higher level micro

my 2 cents on this without investigating the issue deeper.

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: PWM issues

Post by Lord Grezington »

Thank you QMesar

I have done what I can with attempting to vary the perieods and frequencies with no luck. I think what I will try next is use the high speed PWM peripherals on the dsPIC33EP32MC504 with C (rather than the PWM component) to see if the issue persists.

Thanks

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PWM issues

Post by QMESAR »

That would be a good thing and make sure that you have the correct values for Period and DC as calculated by the Resolution ,check the PWM section in the datasheet very carefully

example (just numbers for explanation)
100KHz Period 4099 and then 50% Dc will be 2049 and so on obviously 100% Dc will be 4099 value written to the DC registers
20KHZ Period 3500 then 50% Dc will be 1750 and 100% will be 1750

Goodluck

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 issues

Post by Benj »

Hello,

I've seen these glitches before. It basically happens when you write a lower duty but the timer has already couted past the value you set. And so instead of immediatley outputting low the output remains high for the rest of the period.

When writing to the PWM duty try resetting the timer count register to 0 using a c icon and see if that makes any difference. I might make this part of the component CAL code if that is what's happening to save this problem appearing again.

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 issues

Post by Benj »

I've pushed a change to the update system that should solve the problem automatically for you.

This is the fix I have implemented when changing the duty.

Code: Select all

	#if (MX_PWM_TMR_X == 1)
	  if (duty <= TMR1)
	    TMR1 = 0;
	#endif
	#if (MX_PWM_TMR_X == 2)
	  if (duty <= TMR2)
	    TMR2 = 0;
	#endif
	#if (MX_PWM_TMR_X == 3)
	  if (duty <= TMR3)
	    TMR3 = 0;
	#endif
	#if (MX_PWM_TMR_X == 4)
	  if (duty <= TMR4)
	    TMR4 = 0;
	#endif
	#if (MX_PWM_TMR_X == 5)
	  if (duty <= TMR5)
	    TMR5 = 0;
	#endif
Let us know how you get on.

Post Reply