3

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.

Connor Wolf
  • 32,168
  • 6
  • 79
  • 138
Greg
  • 31
  • 1
  • 1Hz? Why do you care - It's not audio. – Connor Wolf Jun 26 '11 at 03:24
  • Also, where are your bypass caps on that breadboard? I don't think that layout is much of an improvement over a solderless protoboard. – Connor Wolf Jun 26 '11 at 03:26
  • maybe it's not coming from your power. maybe you're generating it. how stable is the timebase for this project? – JustJeff Jun 26 '11 at 03:55
  • 1
    @Fake Name: it is indeed noticable; a once per second 'warbling' – Greg Jun 26 '11 at 04:13
  • 1
    That's not a 1Hz oscillation, it's a high-frequency oscillation gated at 1 Hz. – Connor Wolf Jun 26 '11 at 04:37
  • You're right I don't have any bypass caps on there. I have one off the board for the voltage regulator output. I tried adding a .1uF cap across the VCC and GND of the 328p but I still get the same result... – Greg Jun 26 '11 at 04:39
  • Perhaps I'm not using the right term (and I'm not sure what you mean by 'gated'). In any case, this is what it looks like when recorded: http://i.imgur.com/knwO8.png – Greg Jun 26 '11 at 04:42
  • can you post a waveform? – endolith Jun 26 '11 at 04:43
  • 2
    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? – endolith Jun 26 '11 at 04:46
  • 2
    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. – Kellenjb Jun 26 '11 at 05:04
  • The waveform looks a lot like a Moiré pattern to me... http://en.wikipedia.org/wiki/Moir%C3%A9_pattern – Majenko Jun 26 '11 at 09:04
  • 2
    @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. – Olin Lathrop Jun 26 '11 at 16:37
  • I was wondering if the waveform was playing tricks on me. I do hear low frequency noise, however. It's not that an event occurs every second in the waveform, something more subtle is happening. This is the code I adapted mine from: http://www.adrianfreed.com/content/arduino-sketch-high-frequency-precision-sine-wave-tone-sound-synthesis. I will try to record a usable audio clip to illustrate. – Greg Jun 27 '11 at 04:42

2 Answers2

2

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.

Olin Lathrop
  • 313,258
  • 36
  • 434
  • 925
1

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.

BarsMonster
  • 3,327
  • 5
  • 46
  • 80
  • I'm new at this so I followed this example: http://www.adrianfreed.com/content/arduino-sketch-high-frequency-precision-sine-wave-tone-sound-synthesis, which uses the overflow interrupt. Is this what you meant? – Greg Jun 27 '11 at 04:35