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.

how to design TIMEOUT algorithm with AT89C51?

Status
Not open for further replies.

semiconductor

Full Member level 4
Joined
Apr 4, 2003
Messages
236
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Activity points
2,735
timeout in 89C51/89C52

I'm assigned an exercise to program an AT89C51 for automatic door project.

I'm facing a problem: TIMEOUT

if the outer sensor detects people available, it will open the door and waiting the inner sensor detects people available. After 20s, if no signal is detected, it automatically close the door and return to the beginning of the program (waiting for signal from outer door.

with AT89C51, I'm programming in C but I don't know how to design TIMEOUT algorithm with AT89C51 (20 seconds).

Can someone recommend me solutions?
 

Re: timeout in 89C51/89C52

Use TIMER1 in MODE1 (16-bit counter) to count (Fclock/12) : FFFFh.
If crystal is 11.0952MHz the interrupt will occur every (11095200/12)/65536 = 14.108.. times per second.
Create variable TimeH and TimeL.
Increase TimeHTimeL every interrupt. To reach 20 seconds you will need ≈282 interrupts and that will leave the TimeHTimeL = 01 1A (h) = 0282 (d).
Now you can reset 20s counter (TimeHTimeL) and execute whatever should be done after 20s..

Good luck ..
 

Re: timeout in 89C51/89C52

IanP is completly right,

but, I suggest to use 12MHz crystal, so one cycle is 1us.

Then, you use timer 1 as 16-bit timer and made 50ms timer (T1H=0x3C T1L=0xAF), so you have 20 counts in one second => to rich 20sec you need exactly 400 counts.


Best regards,


Mr.Cube
 

Re: timeout in 89C51/89C52

Hi,

For long time period you need sotware counter.

Use 16-bit hardware counter for periodic intterupt generation.

In the interrupt service routine set CNT_FLAG variable.

unsigned char CNT_FLAG;
unsigned long cnt;
unsigned char TIMEOUT;
unsigned char TIMEOUT_ENABLED;

#define TIMEOUT_THRESHOLD 1024

void interrupt_routine ()
{
CNT_FLAG=1;
}

void main()
{
init();

while(1) {
...
cnt_process();
sleep(); // go to sleep mode
}
}

void cnt_process()
{
if (CNT_FLAG) {
CNT_FLAG=0;
if (TIMEOUT_ENABLED) {
if (cnt < TIMEOUT_THRESHOLD)
cnt++;
TIMEOUT=(cnt==TIMEOUT_THRESHOLD);
}
}
}

When cnt reach TIMEOUT_THRESHOLD TIMEOUT will be set.

Another solution is to increment cnt in the interrupt routine

void interrupt_routine()
{
if (TIMEOUT_ENABLED) {
if (cnt < TIMEOUT_THRESHOLD)
cnt++;
TIMEOUT=(cnt==TIMEOUT_THRESHOLD);
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top