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
Visit site
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
 

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: 136

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
 


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.
 

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);
	    
	  }
  }
 

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: 127

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…