PIC32 PWM Component

A forums to allow resolved bugs and problems with Flowcode v7 to be stored and marked as resolved.

Moderator: Benj

Post Reply
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:

PIC32 PWM Component

Post by QMESAR »

Hi Team

It seems that I can not use the full range of the PWM on PIC32 as I can only adjust the Period and duty similar to a PIC8
I would expect to be able to adjust between 0 -65535 and not only 255
My apologies if my understanding is incorrect

Thank you for looking into this :D
Attachments
1.JPG
1.JPG (59.25 KiB) Viewed 9839 times

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: PIC32 PWM Component

Post by Benj »

Hello Peter,

Yes the PWM on the PIC32 should be 16-bit.

I believe I have found and fixed the problem now.

The Period should default to 255 but can now be edited up to 65535.

Use the SetDuty10Bit macro to assign a duty over the range 0-255.
cal_pwm.fcpx
(8.07 KiB) Downloaded 296 times
Let me know how you get on.

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: PIC32 PWM Component

Post by QMESAR »

Hello Ben

Thank you very much for the help, I will let you know how I get along :D

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: PIC32 PWM Component

Post by QMESAR »

Hi Ben,

The PWM pin now is active however we still have some issues or misunderstanding from my side ,

As you will see in the Flowchart I enable the PWM pin and I set the following in the properties
(1) the period to 20 000 which shows a time of 500 uSec as expected( I want 2Khz)
(2) set the Timer to Timer2
(3) do a 8bit avarage on a adc pin and load this 0-255 value to the DC regsiter ( I also loaded fix value of 127 and 255 )

The results as you will see in the scope prints
(1) the Frequency or period is double the expected so my 2Khz i2 4 Khz
(2) The duty cycle never goes bigger than 2.9 uSec about 2% max of the period

Note: I am sure I get the 255 in the adc8Bit value as when I display this variable in PORTD I can light up all 8 Leds and any numer down to 0

Sorry if I am doing something wrong :D
Attachments
4.JPG
4.JPG (18.71 KiB) Viewed 9790 times
3.JPG
3.JPG (36.9 KiB) Viewed 9790 times
2.JPG
2.JPG (55.13 KiB) Viewed 9790 times
1.JPG
1.JPG (65.02 KiB) Viewed 9790 times

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: PIC32 PWM Component

Post by Benj »

Thanks Peter,

Sounds like another bug to me, should be easy to solve so I'll get on it.

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: PIC32 PWM Component

Post by QMESAR »

Thanks Ben ;
have good one :D

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: PIC32 PWM Component

Post by Benj »

Hi Peter,

Right here is another component fix which hopefully better reflects what the PIC32 PWM hardware is doing.
cal_pwm.fcpx
(8.09 KiB) Downloaded 279 times
Let me know how you get on.

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: PIC32 PWM Component

Post by QMESAR »

Hi Ben;

Thank you very much this file is working fine the following observations

(1) The perioad fit exactly to the setting in PWM properties
(2) The Duty cycle does not work with values between 0 -and 255 as you mentioned in a previous post

In my understanding from the PIC32 the Duty cycle value must match the Period value to achieve 100% Duty cycle
there for when I apply a value between 0 and the 40000 which is the period cycle or value I can scale the Duty cycle exactly between 0 and 100%

I achievde this by doing a 10 bit ADC read(0 -1023) and mulitiply by 40 which is for a fast test 0 -40000 :D (also load 40000 directly to the setDutycycle Function )
Benj wrote: Use the SetDuty10Bit macro to assign a duty over the range 0-255.
I am only concerned if the setDutycycle() function expects 0-255 then something is still wrong however my asuption above is based on my experience using the PWM
in C code and there it works as I mentioned above and now in FC also like it is now with the last file you posted

Many Thanks once again.

Have good one
Attachments
1.JPG
1.JPG (49.31 KiB) Viewed 9722 times

Post Reply