PIC32 PWM Component

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

Moderator: Benj

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 957
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

PIC32 PWM Component

Postby QMESAR » Sun Aug 14, 2016 5:34 pm

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 3435 times

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

Re: PIC32 PWM Component

Postby Benj » Mon Aug 15, 2016 5:04 pm

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 86 times


Let me know how you get on.
These users thanked the author Benj for the post:
QMESAR (Mon Aug 15, 2016 5:15 pm)
Rating: 5.88%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 957
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: PIC32 PWM Component

Postby QMESAR » Mon Aug 15, 2016 5:18 pm

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: 957
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: PIC32 PWM Component

Postby QMESAR » Mon Aug 15, 2016 7:36 pm

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 3386 times
3.JPG
3.JPG (36.9 KiB) Viewed 3386 times
2.JPG
2.JPG (55.13 KiB) Viewed 3386 times
1.JPG
1.JPG (65.03 KiB) Viewed 3386 times
These users thanked the author QMESAR for the post:
Benj (Mon Aug 15, 2016 9:08 pm)
Rating: 5.88%
 

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

Re: PIC32 PWM Component

Postby Benj » Mon Aug 15, 2016 9:09 pm

Thanks Peter,

Sounds like another bug to me, should be easy to solve so I'll get on it.
These users thanked the author Benj for the post:
QMESAR (Mon Aug 15, 2016 9:17 pm)
Rating: 5.88%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 957
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: PIC32 PWM Component

Postby QMESAR » Mon Aug 15, 2016 9:17 pm

Thanks Ben ;
have good one :D

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

Re: PIC32 PWM Component

Postby Benj » Tue Aug 16, 2016 10:35 am

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 81 times


Let me know how you get on.
These users thanked the author Benj for the post:
QMESAR (Tue Aug 16, 2016 12:13 pm)
Rating: 5.88%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 957
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: PIC32 PWM Component

Postby QMESAR » Tue Aug 16, 2016 6:08 pm

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.32 KiB) Viewed 3318 times
These users thanked the author QMESAR for the post:
Benj (Tue Aug 23, 2016 10:00 am)
Rating: 5.88%