[CART360] Arduino Hardware timer + Multichannel synthesis code

Vincent Leclerc vincentlecler at gmail.com
Sun Nov 29 07:54:14 EST 2009


>
> Also, I am researching implementing a version that uses the low level
> hardware timers on the Arduino. I'm told it would improve the accuracy of
> the output (though I don't understand why). I'm having trouble and seeking
> help.


This is not simple, but once you understand it, it's very easy. You need to
understand the timer chapter of your AVR datasheet:
http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf (p. 88....)

And use the <avr/interrupt.h> library (no need to install it):
http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html


In the end, you should have at the top of your sketch:
#include <avr/interrupt.h>

Then 4-5 lines of code in your void setup() looking like:
TCCR0A = ......
TCCR0B = ......
TCNT0 = .....
.
.
.
(see pages 100-105)

AND a seperate function that deals with the interrupt. Something like:
ISR (TIMER0_COMPA_vect ){
   // your code here
}

This will change depending on the behavior you want from the registers in
void setup(). Look at the vector table in the interrupt doc:
http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html

Vincent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://uttermatter.com/pipermail/cart360_uttermatter.com/attachments/20091129/e5add0a6/attachment.html>


More information about the CART360 mailing list