CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Question on CCP1 & CCP2 usage...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

Question on CCP1 & CCP2 usage...
PostPosted: Mon Feb 02, 2015 9:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 1:02 am     Reply with quote

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

View user's profile Send private message Visit poster's website

CCP...
PostPosted: Tue Feb 03, 2015 6:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 8:33 am     Reply with quote

Have a look at the 18F46K22.
_________________
David
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 8:48 am     Reply with quote

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: 19451

View user's profile Send private message

Re: CCP...
PostPosted: Tue Feb 03, 2015 9:30 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 03, 2015 10:05 am     Reply with quote

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

View user's profile Send private message Visit poster's website

CCps
PostPosted: Wed Feb 04, 2015 6:20 am     Reply with quote

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: 19451

View user's profile Send private message

PostPosted: Wed Feb 04, 2015 9:35 am     Reply with quote

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

View user's profile Send private message Visit poster's website

CCP
PostPosted: Wed Feb 04, 2015 12:18 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group