PIC18F4685 2 PWM?
Moderator: Benj
PIC18F4685 2 PWM?
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!
Thanx a lot!
-
- 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?
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
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
Re: PIC18F4685 2 PWM?
But this chip should already have 2 pwm channel no? Maybe i understand it wrong?
-
- 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?
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
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
Re: PIC18F4685 2 PWM?
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!
Re: PIC18F4685 2 PWM?
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
- ionize
- Posts: 25
- Joined: Fri Aug 05, 2011 8:01 pm
- Has thanked: 29 times
- Been thanked: 11 times
- Contact:
Re: PIC18F4685 2 PWM?
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.
Hope this helps.
- Attachments
-
- DUAL_PWM_16F690.fcf
- (28.17 KiB) Downloaded 304 times
- 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?
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.I believe the 16F690 has only one CCP.
Re: PIC18F4685 2 PWM?
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.
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.
Re: PIC18F4685 2 PWM?
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
-
- 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?
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
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
-
- 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?
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.
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
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
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.
-
- 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?
Thanks Mika,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.
That is very useful information!
I was not familiar with ECCP (as you can tell)
I will also have a play so I can learn about it myself
Martin
Martin
Re: PIC18F4685 2 PWM?
Wow thanx a lot!!! IT is working perfect!!!!!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.That should work, at least I've have used it, and it seems to work..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
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