Counting a pulse question ?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

I'm trying to count a pulse from T0 input on P3.4,

Here's the code :
sbit counter_input=P3^4; //input pulse from op-amp

void init_timer()
{
	TL0=0x00;
	//TH0=0x00;

	counter_input = 1; //set it as input to read a pulse from op-amp
	counter_input = 0x00; //clear the counter
	
	TMOD=0x05;
	P0=0x00;
}
main :
.
.
.
unsigned int counter=0,d1,d2,d3,dx,dy,dz,x;
  lcd_ini(); //init LCD
  init_timer();//init timer0
  TR0=1;
  
   while (1)
    {
		counter=TL0;
		P0=TL0;
		x=counter/10;
		d1=counter%10;
		d2=x%10;
		d3=x/10;
		
		dx=d1+48;
		dy=d2+48;
		dz=d3+48;
	lcd_data(dx); lcd_data(dy);     lcd_data(dz);	

}

I got the output already, but it's not consistent yet,
781, 881,321, 050...etc,
I tested with putting input to the sensor it's responding on the display according to the input, but...it's not yet displaying for example 000, 030, 050,090, etc...

Any ideas on this case ?
I'm abit confuse on using timer and counter ....

Thanks for the ideas

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like 8051 to me. You've come to the wrong place.

Something must be wrong in your code - how do you get values greater than 255 from a 8 bit counter?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

who knows someone has a knowledge on MCS51, yes, I don't understand why it's more than 255...

Do you know any MCS51 forum ?
thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Do you know any MCS51 forum ?
http://www.keil.com/forum/thread...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's always www.8052.com

Your problem isn't with the counter. Put a bit more effort into locating the problem. Besides, I've already hinted at your problem.