Created
January 31, 2023 03:16
-
-
Save Benargee/d06910770d7941859d431d5e1aeb6fff to your computer and use it in GitHub Desktop.
Simple code to setup, increment and print Timer/Counter5 on pin47/PL2/T5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arduino Mega (2560) Platform.io | |
//Simple code to setup, increment and print Timer/Counter5 on pin47/PL2/T5 | |
#include <Arduino.h> | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
TCCR5A=0; //Timer/Counter 5 Control Register A | |
TCCR5B=0; //Timer/Counter 5 Control Register B | |
TCNT5=0; //Reset timer5 register value to 0 | |
//Bit 2:0 – CSn2:0: Clock Select. | |
//7(b111): clock on rising edge. | |
//6(b110): clock on falling edge | |
TCCR5B = TCCR5B | 7; | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
uint16_t counter5 = TCNT5; | |
Serial.print("counter5: "); | |
Serial.println(counter5); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some credit goes to this post https://forum.arduino.cc/t/connecting-encoder-channel-a-to-hardware-counter/22431/3