Goliath Fall 2016

Playing Tank Noises

By: Sou Thao (Electronics and Control Engineer)

Approved by Kristen Oduca (Project Manager)

Table of Contents

Introuction

Requirement: Goliath should make motor noises during the game that fall between 20 to 65dB.

We used a 8 ohm 0.5W speaker connected to our PCB.  The 8 ohm speaker was chosen instead of the piezo speaker because it has better sound contrast and better sound quality.  Playing sound continuously requires the use of timer interrupts.  Timer interrupts work by interrupting the program running at certain time intervals to call a function.  After the function is called and the code executed, it will return back to the program where it was interrupted to run the next code.  By doing this, we are able to continuously interrupt the program to play our tank noise.

Obtaining the Notes to Play a Tank Noise

In order to get the tank noise, we went on youtube to decipher the notes for playing a tank noise [1]Because the tone function uses notes based on frequency similar to keys on the piano, we used a tuner life app to help us decipher the notes of the tank noise.  After deciphering the tank noise, the notes were:

NOTE_E3, NOTE_A2, NOTE_B2, NOTE_F1, NOTE_CS1, NOTE_E1, NOTE_D1, NOTE_AS3, NOTE_E3, NOTE_E2, NOTE_B2, NOTE_E3, NOTE_F2, NOTE_AS1, NOTE_D3, NOTE_B3,

NOTE_CS2, and NOTE_E3.

Now that we were able to obtain the notes for the tank noise, we had to find a way to use interrupts in play the tank noise.  When searching online, we found a library to use Timer 1 Interrupts [2]. To use the Timer 1 Interrupt, we first initialized the time the timer should interrupt the program in microseconds using Timer1.initialize(microseconds).  After that, we need to attach a function to the timer interrupt in order to play our tank noise using Timer1.attachInterrupt(function).  Thus, we will be able to play the tank noise continuously throughout the game.

For the sensors, our goal was to find the ideal placement without compromising the size of the Goliath. In the images, we considered enclosing the sensors in the front top as shown in Figure 1.

Writing the Tank Noise Algorithm

//pitches.h file converts notes to PWM frequency values

#include “pitches.h”

//We have to include the Timer 1 Library to use interrupts

#include

//thisNote is used as a counter to play each note

int thisNote;

//the notes for the tank noise

int melody[] = {

 NOTE_E3, NOTE_A2, NOTE_B2, NOTE_F1,

 NOTE_CS1, NOTE_E1, NOTE_D1, NOTE_AS3,

 NOTE_E3, NOTE_E2, NOTE_B2, NOTE_E3,

 NOTE_F2, NOTE_AS1, NOTE_D3, NOTE_B3,

 NOTE_CS2, NOTE_E3

};

void setup() {

Serial.begin(9600);

Timer3.initialize(8000);

}

void loop() {

Timer3.attachInterrupt(play);

}

void play(){

//play the sound from the first note to the last

 int size = sizeof(melody) / sizeof(int);

thisNote++;

if (thisNote == size){

 thisNote = 0;}

tone(13, melody[thisNote],8);

}

Problems Faced Using Timer 1 and Timer 3 Interrupts

We were not able to use the timer1 on the 3Dot Board because it will interfere with the analogWrite PWM for the motors if we used the 3DoT Library [2].  Timer1 affects the analog pins 9, 10, and 11.  On the 3DoT Library, we controlled motor A by calling motorA.begin(5,10,9).  As a result, pin 9 was affected when we used timer1 interrupt in our code to run the tank noise while running our motors in the program.

Next, we tried using timer3 interrupts.  According to this website, the timer2 uses the tone function needed to play the tank noise [3].  However, since the atmega32u4 processor does not have a timer2, the tone function uses timer3 to control the pwm for the frequencies.  Therefore, when we tested the timer3 interrupt to run our tank noise, there were no interrupts because the tone function would not run.

Conclusion

By using timer interrupts, we were able to get the tank noise to work continuously throughout the code.  However, when we ran our motors, the timer 1 interrupt affected the PWM speed of motor A.  Timer 3 interrupt did not run because the tone function could not be used to play the notes from the tank noise.  As a result, we chose to play the tank noise in the setup of our code to show that we were able to obtain a noise similar to a tank.  However, because we ran into issues with the timer interrupts, we were not able to play the tank noise continuously throughout the code.  Due to the time limits, future students should try using timer 4 interrupts to see if they can get the tank noise to play continuously throughout the code.