3
\$\begingroup\$

I'm trying to create a simple audio circuit that is able to output a sine wave at an audible frequency. I'm using an atmega328p for this because I'd like the frequency pattern to be programmable in software. It is working mostly correctly except for a mysterious ~1Hz oscillation on top of whatever frequency is being played, and I'd like to get rid of the ~1Hz noise. The code is pretty simple, just containing one interrupt to set the PWM value that is called about 30,000/s and there are no other interrupts or loop events. The circuit is simple as well containing the MCU, icsp header, reset pushbutton, audio jack and a low pass filter to get rid of high frequency noise. Here is a picture:

enter image description here

Originally I was using a breadboard but I found some suggestions that capacitative coupling in the breadboard could be causing this, so I moved it to the soldered protoboard above without success. Also, I've tried battery, wall and USB power with no success.

Any suggestions on things to try? Could it be related to ground loops?

thanks.

\$\endgroup\$
  • 1
    \$\begingroup\$ @Fake Name: it is indeed noticable; a once per second 'warbling' \$\endgroup\$ – Greg Jun 26 '11 at 4:13
  • 1
    \$\begingroup\$ That's not a 1Hz oscillation, it's a high-frequency oscillation gated at 1 Hz. \$\endgroup\$ – Connor Wolf Jun 26 '11 at 4:37
  • 2
    \$\begingroup\$ Oh you just did. Are you sure there's an oscillation in the output, or are you just seeing an artifact of the way the wave is displayed in Audacity? Can you zoom in on it and post that? \$\endgroup\$ – endolith Jun 26 '11 at 4:46
  • 2
    \$\begingroup\$ Do you happen to have a schematic of what that board is doing? It is hard for me to tell by just looking at it. \$\endgroup\$ – Kellenjb Jun 26 '11 at 5:04
  • 2
    \$\begingroup\$ @Greg, there doesn't look to be anything wrong with the waveform you posted, other than it's displayed at too low a resolution so that you see aliasing against the display. Keep expanding the time axis until you can see complete individual cycles, and then see if there is anything weird going on every second. It seems you are just seeing artifacts in how you're displaying the waveform. Try listening to it and see if there is anything going on once per second. \$\endgroup\$ – Olin Lathrop Jun 26 '11 at 16:37
2
\$\begingroup\$

This is a long shot as I'm a PIC guy and don't have experience with Atmega. However, what about the watchdog timer? Could it be accidentally on and resetting the processor every second or so?

Show a capture of the waveform showing what happens around this one second anomaly. That might give a hint to the cause.

\$\endgroup\$
1
\$\begingroup\$

You should be very careful WHEN you change your PWM value, doing so in the middle of the PWM cycle would lead to all sorts of crazy things.

So, try to set new value in PWM counter overflow interrupt, and set new value let's say on each 100 interrupts.

\$\endgroup\$
  • \$\begingroup\$ I'm new at this so I followed this example: adrianfreed.com/content/…, which uses the overflow interrupt. Is this what you meant? \$\endgroup\$ – Greg Jun 27 '11 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.