1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: AVR fast PWM

  1. Mar 18, 2013 #1
    1. The problem statement, all variables and given/known data

    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?

    3. The attempt at a solution

    Code (Text):
    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.
    //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.
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted