- #1
peterpiper
- 14
- 0
Homework Statement
I'm needing to use an ATMega324P with fastPWM to generate an audio tone which gets sent to a piezo speaker. I'm generating a signal with a set of predetermined tones with an attached value for the various registers involved in fastPWM. tone is the variable associated with the actual note (A#6, Bb5, etc) while freq_count is the actual number being used to create the appropriate duty cycle. I have a 1/64 prescaler on.
OCR1A = freq_count[tone] / 2;
ICR1H = freq_count[tone]>>8;
ICR1L = freq_count[tone] & 0x00FF;
My issue so far is that after a certain amount of time, the signal randomly stops and then restarts again after a few seconds.
Now I have an array of values that play a song that get fed to the above registers. When I say my signal stops and restarts I mean that the traversal through the array and the appropriate delay that the sound would have been played passes, but there just isn't any sound until it randomly comes back at a later tone. Any ideas why this might be?
The Attempt at a Solution
Code:
DDRD |= 0x20;
//Set up for pwm.
OCR1A = freq_count[tone] / 2;
ICR1H = freq_count[tone]>>8;
ICR1L = freq_count[tone] & 0x00FF;
//Because of processor speed, delaying milliseconds gives the appropriate time.
//The set up for play_tone takes only 80 ns so the delay is adequate.
delay_milliseconds(note_time);
//Disable Speaker when tone is done playing.
DDRD &= 0xDF;
tone and note_time are given as parameters to the function which is supposed to play each note. If more code needs to be seen, just say so.