Seeeduino mega Counters

Hello there i have a seeeduino mega and i want to use the external counters on the device to count some rotary encoders. I have been messing about with code for a few days and no matter what i do it just seems that they just count up all by them selves and seem to count up in a odd way. if someone could help me with some working code that would be great. Here’s what i have at the moment.

void CountersStart() 
{ 
  TCCR5A=0;		       // reset timer/countern control register A
  TCCR5B=0;		       // reset timer/countern control register B
  TCNT5=0;	     		       // counter value = 0

  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCR5B ,CS10);	 // External clock source on Tn pin. Clock on rising edge.
  sbi (TCCR5B ,CS11);
  sbi (TCCR5B ,CS12);
  
  TCCR5B = TCCR5B | 7;
}


// call this to get the current count for left motor encoder
unsigned int GetEncoderCounterLeft()
{
unsigned int nReturn;

  nReturn = TCNT5H << 8 ;
  nReturn |= TCNT5L;
   return nReturn;
}

I have so far been using the pin marked 47 on the seeeduino board as i think this is the correct input pin and i have put this down to ground which should mean the counter does nothing but this has the same effect.

Thank you in Advance! :slight_smile: