View previous topic :: View next topic |
Author |
Message |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
#INT_TIMER1 |
Posted: Mon Oct 31, 2011 12:49 pm |
|
|
I'm doing right ?
Code: |
/*****************************************************************************
Timer1 Interrupt, executed every 10 ms
****************************************************************************/
#INT_TIMER1
void TIMER1_isr(void)
{
// Increment time_elasped to keep track of ms
time_elasped++;
// Increment seconds variable if 1000 ms have passed
if (time_elasped == 100) // led blink frequency @ 1000 ms
{
seconds++;
BlinkLED_flag=~BlinkLED_flag;
time_elasped = 0;
}
// On start up, blink LED for 3 mins
//led1 blink mains normal, led1 blink & Reads ADC
// both are work in same time. not one by one.
//if led blink duration complete then it no blink agen.
//Has three mins passed?
if (seconds > STARTUP_SEC)
{
BlinkMains_flag=1;
//output_high(RL5);
}
//Reset Timer 1
set_timer1(60545);
clear_interrupt(INT_TIMER1);
} |
Quote: | set_timer1(60545); | is right ? _________________ sahu |
|
|
mtsoule
Joined: 19 Oct 2011 Posts: 31
|
|
Posted: Mon Oct 31, 2011 2:22 pm |
|
|
Looks right to me, just make sure you enable your interrupts.
Code: |
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
|
|
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Tue Dec 13, 2011 1:12 pm |
|
|
what is this 60545? _________________ sahu |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Dec 13, 2011 7:08 pm |
|
|
!6 bit timers count up. Now if the timer is set to a value EX 60545 then it counts up from that value. This allows for fine tuning in addition to scalers that are limited to a few powers of two. |
|
|
starter
Joined: 14 Dec 2011 Posts: 3
|
|
Posted: Wed Dec 14, 2011 2:14 pm |
|
|
Timer1 is 16bit and it overflow is 65535 if you set_timer1(0) and if you use set_timer1(60545) ticks made to reach 65535 is given by 65535- 60545=4990, now to check what is the clock defined. If clock defined is 48MHz (usually for USB) then it is previously divided by 4 giving 12MHz if no prescaler value defined. Now take 4990/12MHz and this is the time timer1 takes to overflow for this case it is 415.83us so, everytime timer interrupt occurs at this time. Also, check the link below:
http://www.ccsinfo.com/forum/viewtopic.php?t=22467 |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Thu Dec 15, 2011 4:38 am |
|
|
I am using 4 MHZ internal osc. PIC 16F676 _________________ sahu |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Dec 15, 2011 8:49 am |
|
|
Be aware that internal oscillators are NOT great 'time keepers'... |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
Re: #INT_TIMER1 |
Posted: Sun Jan 08, 2012 10:17 am |
|
|
Code: |
/*****************************************************************************
Timer1 Interrupt, executed every 10 ms
****************************************************************************/
#INT_TIMER1
void TIMER1_isr(void)
{
// Increment time_elasped to keep track of ms
time_elasped++;
// Increment seconds variable if 1000 ms have passed
if (time_elasped == 100) // led blink frequency @ 1000 ms
{
seconds++;
BlinkLED_flag=~BlinkLED_flag;
time_elasped = 0;
}
// On start up, blink LED for 3 mins
//led1 blink mains normal, led1 blink & Reads ADC
// both are work in same time. not one by one.
//if led blink duration complete then it no blink agen.
//Has three mins passed?
if (seconds > STARTUP_SEC)
{
BlinkMains_flag=1;
//output_high(RL5);
}
//Reset Timer 1
set_timer1(60545);
clear_interrupt(INT_TIMER1);
} |
how can use it as countdown timer display on 16*2 lcd .
xtal 4 MHz @16f72 _________________ sahu |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Jan 08, 2012 6:17 pm |
|
|
I suggest you look at the software RTC that's in the code library.
it works, easy to understand, and is easy to modify for your use... |
|
|
|