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

CCP Tacho

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



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

CCP Tacho
PostPosted: Fri Oct 12, 2007 9:20 pm     Reply with quote

i want to be able determine the speed of a motor and have been reading old tacho post.

is the CCP in capture the best/easiest way to do this?

when using the CCP in CCP_CAPTURE_RE mode, will out put the number of clock cycles between its last rising edge and the current one?

does one need to reset the timer when the code has been into the isr

is this all the code needed where rise is the number of clock cycles?

Code:
#int_ccp1
void isr()
{
   rise = CCP_1;


void main()
{
   setup_ccp1(CCP_CAPTURE_RE);    // Configure CCP1 to capture rise
   setup_timer_1(T1_INTERNAL);    // Start timer 1

   enable_interrupts(INT_CCP1);   // Setup interrupt on risingg edge
   enable_interrupts(GLOBAL);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 13, 2007 2:41 am     Reply with quote

Study this thread while looking at the PIC data sheet and see how
the code works.
http://www.ccsinfo.com/forum/viewtopic.php?t=29963
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

tacho
PostPosted: Mon Oct 29, 2007 6:52 am     Reply with quote

sorry just now, the bellow works.
setup_timer_3(T1_INTERNAL|T1_DIV_BY_8);
setup_ccp1(CCP_CAPTURE_FE);//used for RPM monitoring
can be also RE.
the controller runs at 32MHz (18F252)
//RPM.h is the rpm reading header
//to capture the rpm, timer1 with prescaller 1:8 is used, to get 1us
// resolution.
//with ccp1 capture unit
//timer1 increment is 1us
//timer1 overflow is 65.536ms
//1,000ms/65.536=15.259 RPS
//15.259*60=915.5 RPM minimum (two stroke engine will not run lower
//than 1500 RPM
//example:
//(1,000,000us/6,000)*60=10,000 RPM
//if CCP_1<6,000, rpmtime=6,000
//the rpm calculations for hold and report are made in rpm_isr under main
#int_TIMER3
void TIMER3_isr(void)
{
rpmtime=0;//RPM<915.5, no rpm/engine not running
}
#int_CCP1
void CCP1_isr(void)
{
set_timer3(0);
clear_interrupt(INT_CCP1);
rpmtime=CCP_1;
CCP_1=0;
}
under main
while(1)//warning "Condition always TRUE" /the program will
//run in "while" if no interrupt occured
{
restart_wdt();
enable_interrupts(GLOBAL);
rpm_isr();
}
if something not clear, email joseph1948@gmail.com
joseph
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