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
USING 8 PWM outputs on PIC18F4431 in FC8
Moderator: Benj
-
- Posts: 10
- Joined: Thu Jan 29, 2015 11:45 am
- Been thanked: 3 times
- Contact:
- 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
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.
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.
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
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;
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;
https://www.matrixtsl.com/wiki/index.ph ... ftware_PWM
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 10
- Joined: Thu Jan 29, 2015 11:45 am
- Been thanked: 3 times
- Contact:
Re: USING 8 PWM outputs on PIC18F4431 in FC8
Hi Benj,
Thx for the quick answer.
I will try it out.
Also the software solution looks ok to me.
Theo
Thx for the quick answer.
I will try it out.
Also the software solution looks ok to me.
Theo
-
- Posts: 10
- Joined: Thu Jan 29, 2015 11:45 am
- Been thanked: 3 times
- Contact:
Re: USING 8 PWM outputs on PIC18F4431 in FC8
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel