PIC18F4685 2 PWM?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

PIC18F4685 2 PWM?

Post by Speedy2k »

I, i would like to know if it is possible with flowcode to have two pwm output, the frequency can be the same for both but the duty cycle must be independant. I know there is 1 CCP1 and 1 ECCP1 port, can they be used both for pwm and if yes how? Since flowcode doesn't let me put 2 different pwm?

Thanx a lot!

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC18F4685 2 PWM?

Post by medelec35 »

I created a Flowchart to run two pwm at the same frequency for a 16F615.
It uses one CCP and the other pwm channel uses C to monitor tmr2 channnel.
See:
http://www.matrixmultimedia.com/mmforum ... 01&#p30330

Alternatively the other way is to use bit bang pwm method.
There are a few posts on this.

If you get stuck I can help you further.

Martin
Martin

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Speedy2k »

But this chip should already have 2 pwm channel no? Maybe i understand it wrong?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC18F4685 2 PWM?

Post by medelec35 »

Hi Speedy2k,
You will need to determine how many CCP channels there are and not ECCP
Easiest way is to load data sheet and search for ccp2.

If only one CCP is found then you can only have 1 pwm, since ECCP is not currently supported by Flowcode.

I just had a look at the datasheet, and it looks like only 1 PWM is available since PWM2, PWM3 and PWM4 are ECCP, so I don't believe they count.

Martin
Martin

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Speedy2k »

Oh i see!! this is really not nice that ECCP is not supported!! I really need 2 independant PWM channel with the same frequency but independant duty cycle!

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Speedy2k »

Here is my flowchart if maybe there is something to do with it! I know there is plenty of strange things in it, but i am still testing with it!! What i want to do with it, is to control with a PID 2 separate 12 volts motors by PWM, both motor must turn the same speed!
Attachments
RPM_FREQ_PWM_GLCD.fcf
(45 KiB) Downloaded 303 times

User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Re: PIC18F4685 2 PWM?

Post by ionize »

Here is a chart with 2 independent PWM channels based on brandonb's, Martin's, Enamul's and others various charts (thanks for sharing your knowledge!). It works well and does what I want but It needs a little refinement and maybe one of these Flowcode masters can help us both by doing that. For instance, I'm going to remove the fast/slow button since I don't need it. I believe the 16F690 has only one CCP. Now I'm just a newby/novice.....
Hope this helps.
Attachments
DUAL_PWM_16F690.fcf
(28.17 KiB) Downloaded 304 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Enamul »

I believe the 16F690 has only one CCP.
Yes you are right. It has only one CCP module. You can't use two hardware CCP in this chip. As Martin said PIC18f4685 has one CCP as well.
Enamul
University of Nottingham
enamul4mm@gmail.com

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Speedy2k »

And is there any way to activate and controll the ECCP PWM with C code ?

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Speedy2k »

I have tried what you hace said by enabling a second pwm based on timer2, it seems pretty good but there is some problem
Look at this video:
http://www.youtube.com/watch?v=PNxiTqCmfE0

On the scope, the purple is the ccp pwm and the green one is the software one.
You can see the hickup in the green signal from time to time, when connected to my motor with the pid, it create inconsistency. On this video, the motor is connected to the ccp pwm and it is able to keep the speed pretty well. I will upload a video with the motor connected to the software pwm later and the flowchart for your review. And on this video both pwm should be set on the same duty cycle and they are off a little bit.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Speedy2k »

Ok here is the Flowchart! I don't know if there is any faster way to do that?
Attachments
RPM_FREQ_PWM_GLCD.fcf
(49.12 KiB) Downloaded 251 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC18F4685 2 PWM?

Post by medelec35 »

If there is an issue by using PWM component + reading timer2 register, then there are two options I can think of.

1) Use a target device with 2 CCP channels or

2) Use software bit bang method for both PWM o/p’s

I believe ECCP is used for bridge type controlling?
Therefore the o/p’s will be a certain phase with respect to CCP1.
So C code using ECCP may not work as expected?
I could be wrong of course.

Martin
Martin

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Mikat »

The Eccp can be used either normal pwm, or a bridge driver...
Here is the code for eccp1 to use normal pwm via C code.

Code: Select all

//init
pr2 = 99; //period to 99
t2con = 0x05; //tmr2 on prescaler to 4
//enable pwms
ccp1con = 0x0C; // enable ccp1
 eccp1con = 0x0C; //Enable eccp1
//Set the duty cycles
ccpr1l = FCV_DUTY_1; //Set the cpp1 duty to FCV_DUTY_1
eccpr1l = FCV_DUTY_2; // set eccp1 duty cycle to FCV_DUTY_2
That should work, at least I've have used it, and it seems to work..
I am not sure is this needed, but in my code, the RC2 and RD4 pins are set to outputs before that init code (RC2 is ccp1 ans RD4 is eccp1)..

Mika
Last edited by Mikat on Mon Nov 05, 2012 4:45 pm, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC18F4685 2 PWM?

Post by medelec35 »

Mikat wrote:The Eccp can be used either normal pwm, or a bridge driver...
Here is the code for eccp1 to use normal pwm via C code.
Thanks Mika,
That is very useful information!

I was not familiar with ECCP (as you can tell) :lol:

I will also have a play so I can learn about it myself :)

Martin
Martin

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times
Contact:

Re: PIC18F4685 2 PWM?

Post by Speedy2k »

Mikat wrote:The Eccp can be used either normal pwm, or a bridge driver...
Here is the code for eccp1 to use normal pwm via C code.

Code: Select all

//init
pr2 = 99; //period to 99
t2con = 0x05; //tmr2 on prescaler to 4
//enable pwms
ccp1con = 0x0C; // enable ccp1
 eccp1con = 0x0C; //Enable eccp1
//Set the duty cycles
ccpr1l = FCV_DUTY_1; //Set the cpp1 duty to FCV_DUTY_1
eccpr1l = FCV_DUTY_2; // set eccp1 duty cycle to FCV_DUTY_2
That should work, at least I've have used it, and it seems to work..
I am not sure is this needed, but in my code, the RC2 and RD4 pins are set to outputs before that init code (RC2 is ccp1 ans RD4 is eccp1)..

Mika
Wow thanx a lot!!! IT is working perfect!!!!!

Post Reply