gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
tacho |
Posted: Mon Oct 29, 2007 6:52 am |
|
|
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 [email protected]
joseph |
|