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.

Timer2 on AT89S52 and pulse count ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Guys,

Does anyone of you have experience on how to use Timer2 on AT89S52 for counting a pulse from op-amp ?
Which pin should I connect from AT89S52 to output of op-amp ?
Any examples code on how to do it ?

Any experiences or links will be very appreciated,
thanks
 

hai,


Have to use 0th pin of PORT1 for count external pulse in 8052, so output of op-amp should be connected in P1.0
for more detail about timer 2 refer the images...

2.JPG3.JPG1.JPG
 
can I use T0 or T1 as well ? any links for example code on how to use it ?
thanks
 

A complete Labsheet giving circuit, and the implementation is given in the attached file. The program is in assembly and some comments are also there. In case of questions please feel free to discus.
 

Attachments

  • Counter.doc
    34.5 KB · Views: 98

do you have one in C ?
I saw from datasheet and ATmel uC 8051 Hardware manual page 2-86 TMOD,TCON and input from T0 for timer0 as a counter, but I don't have idea for a configuration on counting for example 60 pulse per minute ?

- - - Updated - - -

is it :
TCON = 0x10 and TMOD=0x0F and how can I count 60 pulse per minute ?
thanks
 

I make :

Code:
//init timer 0 as a counter for a pulse from op amp

sbit counter_input=P3^4;	 //input pulse from op-amp

void init_timer()
{
counter_input = 1; //set it as input to read a pulse from op-amp
TCON = 0x10;
TMOD = 0x0F;
}

How can I count it ? thanks
 

hai bianchi,

After configure as an input you have to clear counter_input by giving value 0.
now u can give input, if it getting one pulse it will increment the value in timer 2 16 bit register(TH2,TL2). then you can move that values in another PORT..
 

how can I display the value on TL0 into my LCD ?
I'm currently using Timer0..

- - - Updated - - -

like this :

Code:
void init_timer()
{
counter_input = 1; //set it as input to read a pulse from op-amp
counter_input = 0x00; //clear the counter
TCON = 0x10;
TMOD = 0x0F;
}

main()
{
        counter = TL0;
	lcd_data(counter);
}

I want to count for how many pulse per minute ?
any ideas ?

thanks
 

hai,


to display the TL0 value you have to convert that as decimal then u can display...
Code:
\\ *Program for convert binary to decimal*\\
unsigned char binary,d1,d2,d3;
binary=TL0;
x=binary/0A;
d1=binary%0A;
d2=x%0A;
d3=x/0A;

send the values d1+48,d2+48,d3+48 values to the LCD port... you can get the exact value of the TL0.
i think its may be use full for u..

thanks
 

hai,


to display the TL0 value you have to convert that as decimal then u can display...
Code:
\\ *Program for convert binary to decimal*\\
unsigned char binary,d1,d2,d3;
binary=TL0;
x=binary/0A;
d1=binary%0A;
d2=x%0A;
d3=x/0A;

send the values d1+48,d2+48,d3+48 values to the LCD port... you can get the exact value of the TL0.
i think its may be use full for u..

thanks

how can I use d1+48,d2+48,d3+48, is it dy=d1+48+d2+48+d3+48
lcd_data(dy); ?

how can I count it frequency per minute ?

thanks
 

how can I use d1+48,d2+48,d3+48, is it dy=d1+48+d2+48+d3+48
lcd_data(dy); ?

how can I count it frequency per minute ?

thanks

Not like that we have to use like this..
dx=d1+48;
dy=d2+48;
dz=d3+48;
lcd_data(dx); lcd_data(dy); lcd_data(dz);

For counting per minute u can use the one minute delay with timer.. after getting overflow with timer u can capture the value from TL0.
 

ok, thanks for the suggestion, I'll try it on the weekend and keep in touch
 

For counting per minute u can use the one minute delay with timer.. after getting overflow with timer u can capture the value from TL0.
any code examples for this idea ?
thanks
 

I did :
Code:
unsigned int counter,d1,d2,d3,dx,dy,dz,x;
counter=TL0;
x=counter/0A;
d1=counter%0A;
d2=x%0A;
d3=x/0A;

dx=d1+48;
dy=d2+48;
dz=d3+48;

I got :
INIT_LCD.C(483): error C251: illegal octal digit
INIT_LCD.C(484): error C251: illegal octal digit
INIT_LCD.C(485): error C251: illegal octal digit
INIT_LCD.C(486): error C251: illegal octal digit
 

full code :
Code:
sbit counter_input=P3^4;	 //input pulse from op-amp

//init timer 0 as a counter from op amp
void init_timer()
{
counter_input = 1; //set it as input to read a pulse from op-amp
counter_input = 0x00; //clear the counter
TCON = 0x10;
TMOD = 0x07;
}


void main() //main program

{ 
unsigned char serial_char;

unsigned int counter,d1,d2,d3,dx,dy,dz,x;
counter=TL0;
x=counter/0A;
d1=counter%0A;
d2=x%0A;
d3=x/0A;

dx=d1+48;
dy=d2+48;
dz=d3+48;
  lcd_ini(); //init LCD
  init_timer();//init timer0
   while (1)
    {

	  		message3();
		lcd_data(dx); lcd_data(dy); lcd_data(dz);	
delay(100);
	    
	  }
  }
 

HTML:
x=counter/10;
d1=counter%10;
d2=x%10;
d3=x/10;

replace these lines.... use "10" because of "0A"
 

Ok, thanks, it's compiled now, but I haven't got time trying onboard...
 

I tried already, but the result on LCD is 000 and never change, do I miss something here in my code ?thanks
 

hai there,

I uploaded your code with correction with proteus design, check with that

thank you,
 

Attachments

  • Counter.rar
    33.9 KB · Views: 89

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top