![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
codewrecker2
Joined: 23 Dec 2005 Posts: 23
|
delay issue |
Posted: Sun Jan 01, 2006 12:28 pm |
|
|
i have this application ,wher i have to turn on the motor ,every time the pressure sensor reading drops below a set limit.The duration of the motor turn on is 12 secs.the code works perfectly using delay_ms .the problem is that the pic has to communicate with the pc via rs 232 and every time there is a request from the pc side,the pic has to respond immediately.if the serial interrupt occurs just after the motor is turned on,the worst case delay would be around 12secs ,for the pic to respond. guess i hafta use a timer/counter/rtcc.
the pic is 16f689 and has 3 8bit timers.am using 8mhz internal oscilltor.am kinda new to using timers,so may know ,which timer to select and how to go about implementing the delay?
would be really helpful,if u guys pitch in.
--------------------------------------------------------------------------------------
HAPPY NEW YEAR,EACH ONE OF YA |
|
![](templates/subSilver/images/spacer.gif) |
codewrecker2
Joined: 23 Dec 2005 Posts: 23
|
|
Posted: Sun Jan 01, 2006 12:42 pm |
|
|
also,can i do away with a timer interrupt ,so it doesnt collide with serial comm. interrupt |
|
![](templates/subSilver/images/spacer.gif) |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sun Jan 01, 2006 1:18 pm |
|
|
Start here:
http://www.ccsinfo.com/forum/viewtopic.php?t=22467
codewrecker2 wrote: | also,can i do away with a timer interrupt ,so it doesnt collide with serial comm. interrupt |
If your ISRs are short, as they should be, that won't be a problem. Also read about the #priority option. Your RDA interrupt will come first and timer second. I assume 12 seconds +/- a few milliseconds is accurate enough?
Good luck,
John |
|
![](templates/subSilver/images/spacer.gif) |
codewrecker2
Joined: 23 Dec 2005 Posts: 23
|
|
Posted: Mon Jan 02, 2006 11:41 am |
|
|
jecottrell, dead on dude,thanx a lot.saved a lot of my time.the thread did the trick for me.
best wishes |
|
![](templates/subSilver/images/spacer.gif) |
codewrecker2
Joined: 23 Dec 2005 Posts: 23
|
|
Posted: Mon Jan 02, 2006 1:09 pm |
|
|
also,i would like to know that ,while i m in the timer1isr, if a serial interrupt occurs,how to give it a high priority and goto a point in the main function to process the serial data and send an ack. i m using #priority rda,timer1 before defining these service routines.will this be enough to override the timer1 overflow,because this is what i tried.
Code: |
int count; //global variable
int32 location; // "
void motor_startup (void)
{
output_high(pin_RA5); //start the motor
enable_interrupt(timer1) as well as global;
setup(T1_internal | T1_DIV_8);
while(count<53)
{
if (RCIF==1)
{delay_ms(50); //allow data to be buffered
goto_address(location); // location of the label in main ,from
} //wher processing would begin
}
output_low(pin_RA5); //turn off the motor
}
#int_timer1
void delay_isr(void)
{
count++; //timer overflow,every 0.26144sec
//53 counts give me around 14secs
// which is good enuff
}
|
i have written the above code ,thru woteva i recollect from the code at the work place.so spare me for any wrong directives.
so,about the isr, as i am polling for the serial interrupt in the motor startup routine,if i give some stimulus,the serial isr is not served somehow,and its continuously polled till count>=53.is ther ne workaround for this.
i also tried polling the BKBHIT macro (buffer[next_in]!=buffer[next_out])for any incoming data.this way i am able to receive dat ,but end up losing a few characters,sometimes.
the isr routine is similar to that in EX_SISR.C
Thanx an aweful lot for pitching in. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|