Go Down

Topic: Need help in Timers (Read 302 times) previous topic - next topic

ambuj

Hello Guys,
                     Right now i am using arduino mega adk, i am using it's timer5 as a external pulse counter. but when i connect with pulse sensor it's gives me random values i dont know why, any idea why it's not working for me

Code
Quote

  TIMSK5 = 0x10;
  TCCR5A = 0x00;
  TCCR5B = 0x46;
  TCNT5  = 0x00;

Nick Gammon

http://www.gammon.com.au/electronics

ambuj

My Bed....... for this

Code: [Select]
void setup()
{
  Serial.begin(115200);
  TIMSK5 = 0x10;
  TCCR5A = 0x00;
  TCCR5B = 0x46;
  TCNT5  = 0x00;
}

void loop()
{
  Serial.println(TCNT5);
}

Nick Gammon

Could you describe the wiring of this external pulse counter?
http://www.gammon.com.au/electronics

MarkT

Code: [Select]
TIMSK3 = 0x10 ;
is clearly wrong as that bit is read-only.

What mode do you think you are programming?  Normal mode 0b0000 is what you
have programmed, and you are setting the clock input to be T5 (pin 47) falling edge,
so you should be seeing the counter incrementing once per falling edge on that
pin.

If your pulse source isn't debounced that could explain why you see "random"
counts, but that could also be because you are connected to the wrong pin.  T5 is
hard wired as pin 47 (from my notes, haven't actually tested this, can someone
else check?)

If you are changing the timer mode it is a good idea to change all three
control registers, TCCR5A/B/C, so that you don't inherit state from what it
happened to be before (although you should know what that is as you have
the Arduino sources).

TCNT5 is a 16 bit register, I would use 0x0000 rather than 0x00
to make that obvious in the source code.

You are also setting the input capture edge bit (0x40 in TCCR5B) despite the
fact you are apparently not using input capture.
[ I won't respond to messages, use the forum please ]

Nick Gammon


T5 is hard wired as pin 47 (from my notes, haven't actually tested this, can someone else check?)


Pin 37 on the chip, D47 on the board.
http://www.gammon.com.au/electronics

ambuj

Thanks for your suggestions....  :)

I tried new config bits but still i did not find any result.....
Code: [Select]
void setup()
{
  Serial.begin(9600);
TIFR5 = 0x00;
TIMSK5 = 0x00;
TCCR5A = 0x00;
TCCR5B = 0x06;
TCNT5 = 0x0000;
}

void loop()
{
  Serial.println(TCNT5);
  delay(40);
  TCNT5 = 0;
  delay(40);
}


Any thing you want to add so please tell me

ambuj

Quote
Could you describe the wiring of this external pulse counter?


5V
GND
Output :- 47 pin of ADK board


Nick Gammon

Why are you clearing the counter each time through loop()? The serial printing is buffered and won't complete before the counter is reset.

http://www.gammon.com.au/forum/?id=11504
http://www.gammon.com.au/electronics

Go Up