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.

Timer and counter in 89s52

Status
Not open for further replies.

Sharath411

Member level 1
Joined
Mar 27, 2010
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Bangalore
Activity points
1,529
Hi friends...

Is it possible to use timer and counter in the same program in 89s52. that is both timer 0 and counter 0 at a time or parallel. or is there any options.. please help me


thank you.........
 

The C/T bit in the TMOD register clearly defines whether Timer0 is configured as Timer or as Counter ..
It's value can be only 1 or 0 ..

IanP
:wink:
 

The C/T bit in the TMOD register clearly defines whether Timer0 is configured as Timer or as Counter ..
It's value can be only 1 or 0 ..

IanP
:wink:
Hello IanP

actually i am doing a project on frequency counting, i need to check for one second how much pulses are counted so at first i activating the timer then starting the counter in that loop. but its not working i am not able to control the loop
Pl. help me. or any options to do in without using timer pl. help me
here is my code

TMOD=0x01;
TL0=0xFE;
TH0=0xA5;
TR0=1;
count1=COUNTER();
TR0=0;
TF0=0;
;
;
;
;
while(1)
{
DISPLAY(count1);
}
}

//Counter routine
long int COUNTER()
{
unsigned long int count;
unsigned int lbyte,hbyte;
T=1;
TMOD=0x50;
TH1=0;
TL1=0;
while(TF0==1)
{
TR1=1;
lbyte=TL1;
hbyte=TH1;
hbyte=hbyte<<8;
count= hbyte | lbyte;
//Dispaly call
DISPLAY(count);
}
TR1=0;
return(count);

}

thanks in advance
 

Hi friend,

for Frequency count, You must use two timer
One(Timer0) for Time counting(for ex. 1 Second),
and other(Timer1) for pulse counting.

and then

Frequncy = Timer1 / Timer0.

Hope this is help you,
Shyam
INDIA
 

you can use 1 timer for delay and other timer for counter. or even u can use manual 1 second delay program
 

Hi friends..

thanks for reply..
but am asking is it possible to access both the timers at a time that is one for counter and one for timer, just check the code wt i given and tell me is any thing wrong there....
pl.. help


thank you ...........
 

define TMOD only once

void init()
{
tmod=0x51;

TL0=0xFE;
TH0=0xA5;
TH1=0;
TL1=0;
}

void main()
{
init(); //timer1 as counter timer0 for delay
tr1=1;
delay(); // 1s delay using timer0
tr1=0
...
.
.
use TL1 and TH1 to get counted data

}
 
hi friend....
Hi friends..

am asking is it possible to access both the timers at a time that is one for counter and one for timer

Yes, You can use both timer at a time.
even if you are using AT89S52, there are also timer2, means there are total three timer.
and you can also use all three timer at a time.

Hope this is help you.

Shyam.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Hello IanP

actually i am doing a project on frequency counting, i need to check for one second how much pulses are counted so at first i activating the timer then starting the counter in that loop. but its not working i am not able to control the loop
Pl. help me. or any options to do in without using timer pl. help me

There is another way that you can find frequency. It uses an interrupt and a timer. Switch on the timer on first interrupt and off the timer at second interrupt. Now you can calculate the frequency by Frequency = 1/time.

Anyway you have to use atleast one timer
 

    V

    Points: 2
    Helpful Answer Positive Rating
Hi friend.......
thanks for help... am getting the count. but the thing is the count am getting is not correct. actually am generating 1kHz by using 555 timer and giving it to T1, and am counting it but for 1s MC giving just 20 count here is the delay routine pl.. tell me is it right....
void delay()
{
TR0=1;
while (TF0==0);
TR0=0;
TF0=0;
}

the values in the TH and TL is A5 FE.

PL... tell is the routine is right or i need to modification.........

thank you...........
 

//1sec delay using timer iterrupt
#include <REGX51.H>
unsigned int i;
void main()
{
P2=0x00;
TMOD=0X10;
TH1=0x4B; //50 ms
TL1=0xFD; //delay
TR1=1;

while(1)
{

IE=0x88; //enable timer1 interrupt
if(i==20)
{
P2=~P2;
i=0;
}

}
}

void timer1(void) interrupt 3
{
i++;
//automatically clear tf1 in interrupt ,hence load th1 tl1 value to again run timer.
TH1=0x4B;
TL1=0xFD;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top