1

I want to read the value of the register (8-bit). In particular I want to read the values of:

  1. The Timer/Counter - TCNT0 ( Adress 0x26 (0x46) )
  2. The output compare registers - OCR0A and OCR0B.

Is there a way to read them with the Arduino program?

asked May 1, 2019 at 19:10
3
  • How about just using them in your program? You can use the register names directly Commented May 1, 2019 at 19:11
  • @chrisl So is the output of Serial.print(TCNT0, BIN) the current value (in binary) of the register? Commented May 1, 2019 at 19:14
  • Yes, that should work. You see much code on the web, where timers are configured by directly writing to the registers. You can try it. Write a value to a register and read it back. Though, if you are using the Arduino core, the timer0 counter will change, because it is used for millis() and siblings. You can try it with a currently disabled timer. Commented May 1, 2019 at 19:18

1 Answer 1

3

To convert my comments to an answer:

You can use the register names directly. They are defined in the boards/chips core. To read them, simply use the names in your calculations. Write to the registers by setting the value of the registers name (like a variable: TCNT0 = 0;). Be sure to look into the datasheet, to check the behavior of that register.

answered May 1, 2019 at 19:25
1
  • As noted, do check the datasheet -- some register flags are cleared (zeroed) by writing a 1 to them. Commented May 1, 2019 at 19:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.