View previous topic :: View next topic |
Author |
Message |
Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
Question on CCP1 & CCP2 usage... |
Posted: Mon Feb 02, 2015 9:28 pm |
|
|
Hello All,
First, let me say that setting up and using the PWM modules using CCS C is simply a dream. Its so easy and straight forward, compared to the old way I have been using with other compilers for over a decade where you have to set up all the special function registers, one at a time and cross your fingers it would do anything at all!
My question for you is this. In the 40pin PIC I'm using, the (outdated) 16F877a, there are two CCP modules, 1 & 2. But they both share the timer 2 for their operation, and can't be set up and used at the same time at different frequencies and duty cycles. I was hoping to be able to use one for the right wheel and one for the left wheel of a robot for speed adjustments. Is there a way around this? Or do I have to get a different chip which uses TWO different timers, one for each CCP?
Thanks guys. Hope you have an answer for me. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 03, 2015 1:02 am |
|
|
Post the manufacturer and p/n of the wheel motors. Do they really
require adjustable PWM frequency ? |
|
|
Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
CCP... |
Posted: Tue Feb 03, 2015 6:15 am |
|
|
Im designing the product from scratch, so Ill be using H bridges for the motors, and thus the need for PWM for each wheel.
Chris |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Tue Feb 03, 2015 8:33 am |
|
|
Have a look at the 18F46K22. _________________ David |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Feb 03, 2015 8:48 am |
|
|
I 'second' David's choice of the 18F46K22. Tons of memory, peripherals, etc. A very good PIC for the money.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
Re: CCP... |
Posted: Tue Feb 03, 2015 9:30 am |
|
|
Arizona Chris wrote: | Im designing the product from scratch, so Ill be using H bridges for the motors, and thus the need for PWM for each wheel.
Chris |
However this misses the point that PCM_programmer was making. You change the speed of a motor using PWM, by changing the pulse _width_, not the frequency. You keep the PWM frequency constant whatever speed the motor is doing.
You have two different approaches you can consider beyond this. To control two motors with H-bridge drives, there are three different 'types of drive' you could use:
1) H bridge directly from the PIC. With this you use four outputs on the PIC (and need one with the ECCP module for each motor), and the PIC generates the patterns to give forward/reverse, and the 'dead-time' as you switch one FET off and the other on. Four PIC pins for each motor.
2) Half bridge directly from the PIC. Here you use two PIC outputs, and again have it generate the dead-time, but now handle the direction control externally. One extra direction control line. Three PIC pins for each motor.
3) Straight PWM. You use FET drivers that warrant the dead-time (always guarantee that the off switching is faster than the on switching), and just feed a simple PWM waveform, with separate direction control signals. Just one PWM output for each motor from the PIC (and a separate direction line). Two PIC pins for each motor.
Both 1, and 2, require that you choose a PIC that has the ECCP or motor control module (2 channels required for two motors).
The 46K22 suggestion is 'great'. It allows two ECCP's both supporting full bridge operation, or three ECCP's with one running full bridge and two running half bridge, and two more conventional PWM's as well!...
Last edited by Ttelmah on Tue Feb 03, 2015 12:49 pm; edited 1 time in total |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Tue Feb 03, 2015 10:05 am |
|
|
I can only add that on the PIC16F877A the two CCP modules operate on the same timebase/period but can in fact output two different duty cycles which is probably what you need (different speed for each wheel). |
|
|
Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
CCps |
Posted: Wed Feb 04, 2015 6:20 am |
|
|
Thanks for the suggestions - I have the least expensive version of CCS C, and cant do any 18F devices, but I did look at the data sheet for that part and for the money it is an awesome part!
Guy - If what you are saying is true, that I can use the same frequency but change the pulse widths independently on two CCP channels with my '877a part, then that would do the trick. UNfortunately - when I set up both CCP modules, set the timer, and PWM to the same say 50%, it doesn't work. You get a garbled waveform out of CCP1 and CCP2 just goes high. OH well, you have to try these things, thats what makes it fun!
Time for a new processor... ;)
in Sunny warm Arizona
Chris |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Feb 04, 2015 9:35 am |
|
|
You should be able to set the two PWM's fine.
You only need:
Code: |
//Header here for your processor, fuses, clock rates etc.
void main(void)
{
setup_timer_2(T2_DIV_BY_1,255,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty((int16)511);
set_pwm2_duty((int16)511);
while(TRUE)
;
}
|
This sets both CCP's to give 50%(ish) duty, at FOSC/(4*256) Hz. So from 4MHz, 3906.25Hz.
If you are getting distortion then look carefully at your hardware (grounds etc...). This _works_. |
|
|
Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
CCP |
Posted: Wed Feb 04, 2015 12:18 pm |
|
|
When I get home from work tonight Ill compare what I have with yours. Looks identical to mine first glance, but I could be missing something small.
Chris |
|
|
|