Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Long time delay using timer

Status
Not open for further replies.

Jack// ani

Advanced Member level 3
Joined
Dec 2, 2004
Messages
757
Helped
107
Reputation
222
Reaction score
58
Trophy points
1,308
Activity points
5,006
Hi all,

Any idea as how to create long time delay using 16f628a timer overflow interrupt, so that cpu is free to do other task? I need some function written in CCS PIC for the same?

Thanks
 

Program the timers to interrupt at its longest reload values, then at the interrupt service routine, increment a variable, if the variable matches your desired time delay, then excute your desired subroutine.
 

Boolean Timeout; // Flag. If true, do whatever you want after the timeout.
static int8 gtimer0_overflow;

#int_timer0
timer0_isr()
{
if (--gtimer0_overflow == 0)
Timeout = TRUE;
}


In your main code, you have to setup the timer0, initialise the global variable gtimer0_overflow.


For example,


setup_timer0(RTCC_INTERNAL|RTCC_DIV_256)
Timeout = FALSE;
gtimer0_overflow = 3; // Variable to control timeout length
enable_interrupts(int_timer0)
enable_interrupts(GLOBAL)

while (!Timeout); // do nothing if Timeout =FALSE


The above example setup a 10 sec delay for PIC18 MCU, 20MHz oscillator. Note that Timer0 is 16 bit for PIC18.
 

Thanks all, I want one of the output port pin to go high for 10sec and then go low 10secs and keep on repeating like this.

Any help.....
 

#int_timer0
timer0_isr()
{
if (--gtimer0_overflow == 0)
{
Timeout = TRUE;
output_toggle(PIN_D1);

}



This will turn PIN_D1 on/off for 10 sec .
 

    Jack// ani

    Points: 2
    Helpful Answer Positive Rating
Hi lguancho,

Thanks a lot for your helpful reply. Output_toggle is very useful function here, but unfortunately it is not mentioned in the CCS PIC help file! I’ve a doubt left,

Will the output be high or low for the first time, when using output_toggle( ) function and how can I change it?

How did you calculate time delay for a single timer overflow cycle?

Thanks again
 

First, you can initialise the output pin to high or low
such as

output_high(PIN_D1) , then you enable the timer1 interrupts. When timer1 overflows, PIN_D1 will be low.

Delay Calculation:

20MHz/4/256= 19531.25Hz=> Timer1 increments every 1/19531.25 sec= 51.2us

Timer1 overflow if it reachs 65536=> 65536X51.2us= 3.3sec

Set the overflow variable to 3, i.e delay= 3x3.3 ~ 10 sec.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top