So I've got an SNES controller (basically a bunch of buttons and a pair of 4021 shit registers) hooked up to the Arduino, going out into a pair of 74HC595 shift registers, which output to both an 8ohm speaker via a 1kohm resistor and a standard 2x16 backlit LCD.
Everything works as it should, but the tone coming out of the speaker is very buzzy unless I comment out the code that writes to the LCD. I've tried putting a cap in after the resistor, but that didn't help. I thought it was a power issue, but I've got the Arduino going on a 12v/1A power supply. There's about a 0.25V across the speaker when the lcd.print code is active and 0.33 when it's commented out.
Any ideas? The main loop code and an photo of the wiring are below.
Each button sends a different tone to the speaker, so it's sort of like a keyboard. The LCD displays the tone/button being pressed. The speaker has 1 pin of output, and the LCD has 3. They don't share any wiring.
Well a buzz is alternating current so, as the data is constantly being shifted all the binary data(or rapidly alternating current) gets passed the speaker on its way out, when its a pure tone the speaker gets an exact frequency, the lcd data isn't so exact and causes the sounds you hear, your actually hearing the arduino "talk" to the lcd
id suggest dedicate the pin to the speaker or find another way to drive it, perhaps a 555 timer circuit using a transistor as a variable resistor, base being fed thru an rc filter with pwm
or just toggle a pin on the arduino solely for the speaker(difference being 555 can provide 200ma instead of 30)
You are using five different libraries, probably written by five different people, each one relatively unconcerned about what anyone else might be doing with the processor resources. It's amazing that it works as well as it does.
griphus:
Everything works as it should, but the tone coming out of the speaker is very buzzy unless I comment out the code that writes to the LCD.
That library does this to write to the LCD:
void LiquidCrystal_SR3W::loadSR(uint8_t value)
{
// Load the shift register with information
fio_shiftOut(_data_reg, _data, _clk_reg, _clk, value, MSBFIRST);
// Strobe the data into the latch
ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
fio_digitalWrite_HIGH(_strobe_reg, _strobe);
fio_digitalWrite_SWITCHTO(_strobe_reg, _strobe, LOW);
}
}
ATOMIC_BLOCK disables interrupts. The tone library uses interrupts. Hence tones stop when you are writing to the LCD.
Would you know if there is either a tone-generating library that doesn't use interrupts or an shift register-based LCD library that doesn't disable them? I'm afraid I don't actually know enough about how either library works to tell if either of those qualities are inherent to the output. Or if there's a way to correct for the interrupts in hardware?