Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp Speaker Circuit — Parallax Forums

Basic Stamp Speaker Circuit

eiplannereiplanner Posts: 112
edited 2009-12-29 15:08 in BASIC Stamp
Hey All,
I am a newbie to electronics in general. I have just completed the "What is a Microcontroller" text and all exercises therein.

I am looking to program my basic stamp to read sheet music note by note and play the chords on an 8 ohm .5 watt speaker.
I have spent more than 10 hours online for 2 days trying to find the circuit diagrams to accomplish this. I found the sheet music conversion program that Parallax recently wrote, but this is output to a piezo speaker. I want to do it on my normal speaker. I am pretty sure it is not the same circuit as the one for the piezo and I do not want to damage my stamp by just connecting it and giving it a try.

Can someone point me to an exact schematic that shows all the connections, devices and their values, from my BS2 Homework Board to my 8 ohm speaker.

Thank you for tolerating me and my novice/newbie status. I really am enjoying my new toys and the world of possibilities.

P.S. I forgot to state that I want to build the entire circuit from scratch myself on my homework board and am not looking for any other controllers that accomplish this for me........Thank You

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-13 22:54
    Page 446 of the BASIC Stamp Syntax and Reference Manual shows what you need to drive a speaker from a Stamp I/O pin. This won't provide anything like 0.5W since an I/O pin at best might provide 50mW to 100mW. The 33 Ohm resistor mentioned in series with the speaker would absorb most of that power leaving you with 10mW to 20mW for the speaker itself.

    I would recommend using some kind of external amplifier. One of the Nuts and Volts Columns (#67) gives a simple circuit using the LM386 which is available from RadioShack along with the other parts needed. I think the whole thing should fit easily on the Homework Board.

    www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol2/col/nv67.pdf
  • eiplannereiplanner Posts: 112
    edited 2009-12-13 23:05
    Thanks for the fast reply Mike. I have looked extensively at these types of circuits that you referred me to, I am more than willing to build it, I just need to know if the Audio In comes directly from the Stamp's Output or if there is supposed to be other devices in between.

    " border="0">
    754 x 366 - 35K
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-13 23:09
    You could drive it directly from the Stamp's output or you could add the low-pass filter shown on the same page in the Manual for use with an external audio amplifier. The low-pass filter will improve the quality of the sound.
  • eiplannereiplanner Posts: 112
    edited 2009-12-13 23:23
    OK Mike, I'm gonna go to work on it and include the low-pass filter.

    Thanks for the info and I'll post the outcome ASAP
  • eiplannereiplanner Posts: 112
    edited 2009-12-14 02:14
    Alright, here's where I am at now.

    I have the below pictured Audio Amp Driver circuit currently configured on my homework board using pin 0 for my input to the driver.

    I also have the LM324 OpAmp IC on my board. I seem to be misplacing the inputs and outputs on the Amp because my sound never changes with the amp connected from when it is disconnected. It is a quad amp with the configuration in the other picture below.

    I am such an extreme novice that I need someone to tell me step by step wire by wire, where to connect these inputs and outputs on the amp as well as where my two speaker wires connect to this circuit.
    432 x 165 - 17K
    401 x 324 - 28K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-12-14 03:03
    You cannot substitute one of the LM324's amps for the LM386, if that's what you're trying to do.
    You can make an amp with one (non-inverting amplifier), but it won't work too well with a low-ohm speaker.

    Get the LM386.

    ·
  • eiplannereiplanner Posts: 112
    edited 2009-12-14 03:57
    Thanks PJ Allen,

    I will be getting the LM386 tomorrow.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-14 06:16
    An LM386 may be overkill for a half-watt speaker. I tried the following with an 8-ohm speaker I have, and it worked fine:

    attachment.php?attachmentid=65869

    -Phil
    287 x 313 - 2K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-12-14 12:45
    Overkill?· What overkill?·

    Crikey!

    There are various types of the·LM386, 300-700 mW depending.· Wow,·it's throw-weight major big-time.

    Post Edit --

    The nominal output powers: N-1 = 325mW, N-3 = 700mW, N-4 = 1000mW (rare)


    Post Edited (PJ Allen) : 12/14/2009 1:15:07 PM GMT
  • eiplannereiplanner Posts: 112
    edited 2009-12-17 00:52
    PhiPi,

    Your simple circuit worked for me. Thank you. At least I have an audible sound now that I can use to work on my program.

    However, it's a very raw sound that I will later get the proper components to clean it up. At least I am up and running.

    This link : http://sci-toys.com/scitoys/scitoys/computers/solderless/ic_amplifier/ic_amplifier.html

    that was provided by eod_punk earlier in this thread shows a pretty clear step by step how to for a 1 watt amplifier using the LM386.
    I will probably build that model for my final setup unless anyone knows of a problem or a safety issue with it.

    Thanks to all for the assistance!
  • eiplannereiplanner Posts: 112
    edited 2009-12-28 23:36
    Alright, I am back to working on this 8 ohm / .5 watt speaker amplifier circuit. I have built the circuit exactly as shown in the picture below.
    It does significantly amplify the sounds out of the speaker, but when my basic stamp program ends, my speaker continuously
    spills out noise. Can someone help me eliminate the noise on this circuit or do I have to build a different one?
    391 x 312 - 22K
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-28 23:45
    The problem isn't in your amplifier. The problem is with the END statement (or STOP statement). Try:

    hangHere: GOTO hangHere

    What happens is that the Stamp drops into a low power mode on an END or STOP statement where it goes to sleep for a while and wakes up periodically. When it goes to sleep, the I/O pin you're using (all of them actually) are put briefly into input mode, then re-initialized to whatever mode they were in. I think the constant switching of the I/O pin is causing the noise. One other thing to try is to put the speaker's I/O pin explicitly into input mode before the STOP or END statement. If you're using pin #5, do:

    INPUT 5
    END
  • PrettybirdPrettybird Posts: 269
    edited 2009-12-29 01:01
    ·I have recient experience with the LM 386 on my Mini Monster Boe Bot· (completed projects about 2 months ago). You may need a pull up resistor to get rid of noise but it renders the volume control almost useless. I use it to drive 2-8 ohm speakers and wanted as much volume as possable for outdoor use.· The LM380 is another audio amp chip I believe around 2.5 watts, but it is a 14 pin chip.

    Post Edited (Prettybird) : 12/29/2009 4:52:26 AM GMT
    3072 x 2304 - 1M
  • eiplannereiplanner Posts: 112
    edited 2009-12-29 01:01
    Well Mike,
    Neither worked. There is a brief (1/2 sec) period when the program gets to the INPUT or the GOTO statement that is totally quiet and then the noise comes back. It's as if the program is forcing an end on it's own.
  • eiplannereiplanner Posts: 112
    edited 2009-12-29 01:04
    Here is the program that I am running (it's the one from Parallax's site called 'School Days'):

    ' SchoolDays.bs2

    ' Play the 1907 hit "School Days" by Will Cobb and Gus Edwards with the

    ' piezospeaker.



    ' {$STAMP BS2}

    ' {$PBASIC 2.5}



    Notes DATA "D", "F", "C", "F", "b", "A", "b", "C", "b", "A", "R", "A",

    "e", "G", "A", "e", "G", "A", "R", "A", "A", "G", "D", "F",

    "G", "D", "F", "G", "R", "G", "G", "Q"



    Octaves DATA 7, 6, 7, 6, 6, 6, 6, 7, 6, 6, 6, 6,

    7, 6, 6, 7, 6, 6, 6, 6, 6, 6, 7, 6,

    6, 7, 6, 6, 6, 6, 6



    Durations DATA 2, 2, 2, 2, 2, 4, 2, 4, 2, 2, 4, 4,

    4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4,

    4, 4, 4, 4, 4, 4, 2



    Dots DATA 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0,

    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,

    0, 0, 0, 0, 0, 0, 1



    index VAR Byte

    offset VAR Nib



    noteLetter VAR Byte

    noteFreq VAR Word

    noteDuration VAR Word

    noteOctave VAR Nib

    noteDot VAR Bit



    DO UNTIL noteLetter = "Q"

    READ Notes + index, noteLetter



    LOOKDOWN noteLetter, [noparse][[/noparse] "C", "d", "D", "e", "E",

    "F", "g", "G", "a", "A",

    "b", "B", "R", "Q" ], offset



    LOOKUP offset, [noparse][[/noparse] 3186, 3435, 3699, 3978, 4274,

    4588, 4920, 5272, 5645, 6040,

    6459, 6902, 0, 0 ], noteFreq



    READ Octaves + index, noteOctave

    noteOctave = 8 - noteOctave

    noteFreq = noteFreq / (DCD noteOctave)



    READ Durations + index, noteDuration

    noteDuration = 1000 / noteDuration



    READ Dots + index, noteDot

    IF noteDot = 1 THEN noteDuration = noteDuration * 3 / 2



    FREQOUT 0, noteDuration, noteFreq



    index = index + 1

    LOOP

    hanghere: GOTO hanghere

    END
  • ZootZoot Posts: 2,227
    edited 2009-12-29 04:14
    To reduce noise or hiss when an audio circuit is not being actively driven, I usually set the speaker/piezo/freqout audio pin to 0 (LOW). Depending on how much analog noise, etc., is present, when you have the pin on INPUT the input to the audio amp can still get "driven" enough to generate low volume noise. (Caveat: this is for an amp circuit that does not use negative and positive voltage supply -- push/pull -- but one that uses just positive supply and ground).

    In an ideal world, such an analog circuit would be designed to be as noise free as possible, but that's an ideal smile.gif

    And of course, noise de-coupling caps (sometimes several of them) on the amp circuit, as close as possible to the amp, can reduce unwanted noise a great deal.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • eiplannereiplanner Posts: 112
    edited 2009-12-29 06:05
    Well, I still can't stop the noise. I have tried making the input LOW, I've tried putting in a 100K pull down resistor, I've tried a never-ending loop, and I have tried INPUT 0
    and I just keep getting the static noise. It's not a real faint noise, it's a fairly loud one. The circuit (pictured earlier on this thread) came from the manufacturer's data
    sheet. It's a circuit that produces a 200 gain. Do you all think the noise is specific to the high gain or am I still going to get it if I lower the circuit to a 50 gain?
  • ZootZoot Posts: 2,227
    edited 2009-12-29 06:08
    Lower your gain and see how it sounds. At 200, you would need to be very free from noise. With an 8ohm, .5w-1w speaker, I usually have a gain of around 20-35 on the amp, and that's annoyingly loud (at my place, anyway smile.gif)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • eiplannereiplanner Posts: 112
    edited 2009-12-29 06:20
    Now, I have taken the driver circuit shown below and introduced it to my existing circuit. It further amplified my sound but still didn't stop the noise.
    432 x 165 - 17K
  • ZootZoot Posts: 2,227
    edited 2009-12-29 06:25
    I don't see a DC filtering cap (series cap -- only allows AC to pass, like sound frequencies)? Maybe post your whole circuit.

    In the circuit below, to the left of the amp, you see the 10uf series cap -- this filters DC, as does the 220 on the final output wire to the speaker. The exact values of the series caps may depend on your particular setup or the amp itself.

    To the left of the 10k volume control and series cap, is the low pass filter that's good for a micro.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php


    Post Edited (Zoot) : 12/29/2009 6:32:49 AM GMT
    720 x 280 - 55K
  • eiplannereiplanner Posts: 112
    edited 2009-12-29 06:32
    OK, I lowered the gain to 20 and finally got rid of the noise. The sound is still pretty good. However, I would still like to know why there is so much leakage coming through the stamp input.
    I feel like I should be able to have the higher gain without the noise.
  • eiplannereiplanner Posts: 112
    edited 2009-12-29 07:05
    Zoot, I put my circuit together as your picture shows it and it works fine with the gain of 20 but still leaks the noise when I turn the gain up to 200.
  • PrettybirdPrettybird Posts: 269
    edited 2009-12-29 11:18
    Strange. I got my schematic straight from the data sheet too using min. parts. Running on 9v. Sure you have a good ground?
    Mabe throwing a 10 mfd cap or higher across the chip power leads. I found it noisy too at first.
  • ZootZoot Posts: 2,227
    edited 2009-12-29 15:08
    Is your circuit on a breadboard? Notoriously noisy. Do you have caps on the power rails at the amp? On the micro? You could try .01 AND .1 AND 10uf on all power rails, close to the chips.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.