USING 8 PWM outputs on PIC18F4431 in FC8

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

Moderator: Benj

Post Reply
theopieleke
Posts: 10
Joined: Thu Jan 29, 2015 11:45 am
Been thanked: 3 times
Contact:

USING 8 PWM outputs on PIC18F4431 in FC8

Post by theopieleke »

Hello,
can anyone tell me if it is possible to use the 8 PWM outputs provided on the PIC18F4431 microcontroller using Flowcode 8?
And so, how to do it? I am not a good C--programmer and I can only see that there are just two channels provided in de component-macro of PWM for this microcontroller, using channel1 en channel2. There should be a possibility to use the 8 PWM outputs.
I am using the educational version of Flowcode 8 (as I am an electronics teacher).

Can anyone give me some advice.
Thx,
Theo

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: USING 8 PWM outputs on PIC18F4431 in FC8

Post by Benj »

Hello,

Flowcode can drive the CCP based PWM but only some devices with special function PWM. On the 4431 device it looks like it would be fairly complex to crowbar the special function PWM in so it is supported by the component but C code should be an option for you.

First to enable the PWM outputs.

Code: Select all

PTCON0 = 0x00;  //PWM Time Base, Clock Prescaler and Freerunning Mode
PTCON1 = 0x80;  //PWM Time Base is Enabled and counting up
PWMCON0 = 0x4F;  //PWM Channels 0-5 Enabled and in Independent mode
PWMCON1 = 0x00;  //Special Event triggers
OVDCOND = 0x3F;  //Enable PWM Peripherals to drive IO Pins

//Set 12-bit PWM Period 
PTPERL = 0xFF;
PTPERH = 0x0F;
Then this would set the various duties on the PWM outputs. Note channels are in pairs and tied to the same duty either outputting the same or complementary states.

Code: Select all

//Set Channels 0-1 12-bit Duty - 50%
PDC0L = 0xFF;
PDC0H = 0x07;

Code: Select all

//Set Channels 2-3 12-bit Duty - 50%
PDC1L = 0xFF;
PDC1H = 0x07;

Code: Select all

//Set Channels 4-5 12-bit Duty - 50%
PDC2L = 0xFF;
PDC2H = 0x07;
Hope this helps. If you need 8 or more independent channels then software PWM using a timer interrupt may be a better option for you.
https://www.matrixtsl.com/wiki/index.ph ... ftware_PWM

theopieleke
Posts: 10
Joined: Thu Jan 29, 2015 11:45 am
Been thanked: 3 times
Contact:

Re: USING 8 PWM outputs on PIC18F4431 in FC8

Post by theopieleke »

Hi Benj,

Thx for the quick answer.
I will try it out.
Also the software solution looks ok to me.

Theo

theopieleke
Posts: 10
Joined: Thu Jan 29, 2015 11:45 am
Been thanked: 3 times
Contact:

Re: USING 8 PWM outputs on PIC18F4431 in FC8

Post by theopieleke »

Hello Benj,

not sure what you mean by this: "Flowcode can drive the CCP based PWM but only some devices with special function PWM", but are there devices (PIC) in Flowcode that could make it possible to use 8 PWM outputs?

I'm a bit confused right now.
Theo

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: USING 8 PWM outputs on PIC18F4431 in FC8

Post by Benj »

Hi Theo,

The J13, J53, K22 devices all look to have 10 channels but might be worth a quick compile test to ensure all channels are supported.

Post Reply