Using Hall Sensor(TLE-4905) with Arduino Mega

cattledog:
That code is using the ICP(input capture) pin. ICP5 is on D48.

The OP claims that he only has the external clock source pin(T5) on D47 available.

If that's the case, you can not determine the pulse characteristics, but only the count the number of pulses in a period of time.

You will be using the timer/counter as a counter. Here is some sample code written for Timer1 on a UNO.

Okay so I understand this code pretty well. I tried running it with the following changes and it prints only zeroes in the output. Where am I going wrong? (I think the pin number in pinMode is not right...)

unsigned long count_period = 2000;
unsigned int count_to_rpm = 60000UL / count_period; //convert counts to RPM
byte number_of_sensors = 1;
unsigned long final_counts;
unsigned long start_time = millis();
unsigned long measured_time;
unsigned long current_time = millis();

void setup()
{
  Serial.begin(115200);
  TCCR5A = 0; //initialize Timer5
  TCCR5B = 0;
  TCNT5 = 0;
  pinMode( 47, INPUT_PULLUP); //external source pin for timer1
  //set external clock source pin D5 rising edge
  TCCR5B =  bit (CS50) | bit (CS51) | bit (CS52);

  //Test pulses to confirm circuit 50 pps =  3000
  //pinMode(11, OUTPUT);
  //tone(11, 50);//test pulse jumper pin 11 to pin 5
}

void loop()
{
  current_time = millis();
  if (current_time - start_time >= count_period)
  {
    TCCR5B = 0; //stop counter
    final_counts = TCNT5; //frequency limited by unsigned int TCNT5 without rollover counts
    TCNT5 = 0;
    measured_time = current_time - start_time;
    start_time = current_time;;
    unsigned int rpm = (final_counts * count_to_rpm) / number_of_sensors;
    TCCR5B =  bit (CS50) | bit (CS51) | bit (CS52); //restart external clock source

    Serial.print(measured_time);
    Serial.print("\t\t");
    Serial.print(final_counts);
    Serial.print("\t\t");
    Serial.println(rpm);
  }
}

Thanks for the help. :slight_smile: