tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.45k stars 911 forks source link

Setting a timer interrupt on an Arduino Uno R3 #2489

Open scottlu opened 2 years ago

scottlu commented 2 years ago

I'm looking for sample code for setting a timer interrupt on an Arduino Uno R3.

mccolljr commented 2 years ago

@scottlu did you ever figure this out?

mccolljr commented 2 years ago

@scottlu I got this working.

To do it, you have to import the device/avr package and set the values of several registers on your own. I followed this:

https://www.google.com/url?q=https://exploreembedded.com/wiki/AVR_Timer_Interrupts&sa=U&ved=2ahUKEwiopeHmrs74AhV8K0QIHTjUB-8QFnoECAQQAg&usg=AOvVaw2BA6J8R8KUk47fLeIMbvMS

The registers are pretty much named 1-1 with the registers mentioned in the tutorial.

The main difference from the example code is that setting the count to a 16 bit value requires setting the hi and lo (H and L) 8-bit registers, rather than one 16-bit value

scottlu commented 2 years ago

Thanks.... looks good.