Tag Archives: sound

Audio synthesis and sharing the timers

We’re using the Mozzi sound synthesis library for Arduino to allow the robots to produce sound.  Our synthesis is implemented on the auxiliary circuit (environmental), which is also responsible for interfacing with all environmental sensors.  The main challenge with using Mozzi is that the library disables Arduino time functions millis(), micros(), delay(), and delayMicroseconds(), which we use often with various sensors.  Once Mozzi has been started, the library does not provide a method of stopping and regaining use of the timers.  Our solution is outlined below.

Mozzi modifies the following registers when starting up: TCCR0A, TCCR0B, OCR0A, TIMSK0, TCCR1A, TCCR1B, OCR1A, TIMSK1. Therefore, before starting Mozzi we backup the values of these registers:

byte _TCCR0A = TCCR0A;
byte _TCCR0B = TCCR0B;

etc… for the other registers.

When we want to stop Mozzi, we simply restore the backed up values:

TCCR0A = _TCCR0A;
TCCR0B = _TCCR0B;

etc… for the other registers.

These routines are wrapped in a custom audio library used for managing sound.