Am developing a PIC microcontroller app that generates audio tone that varies between 350 and 750 hz.
What kind of low cost circuit using no more than 3 volts can be used to filter, attenuate, and drive 16 - 32 ohm headphones?
Any ideas?
What kind of low cost circuit using no more than 3 volts can be used to filter, attenuate, and drive 16 - 32 ohm headphones?
Any ideas?
Try making a voltage divider with two low value resistors between 0v and 3v to get 1.5v. Make this the headphone ground. Then you could connect the headphone + to a data line. The chip should be able to handle the current, if not, use a buffer. If your clock speed is high enough, you should be able to generate the wave using software.
Driving headphones with PIC microcontroller
You are saying that the walkman-type headphones need around a 1 1/2 volt signal. OK, so I generate a square wave with the PIC, then I could use a bndpass filter to smooth it to a sine wave to sound better, then direct drive the phones, using the voltage divider you describe.
But, need a way to adjust volume, and prefer to use two PIC lines to read two pushbuttons, then maybe drive I/O lines to a transistor somehow to control volume.
Any ideas on how to do this?
You are saying that the walkman-type headphones need around a 1 1/2 volt signal. OK, so I generate a square wave with the PIC, then I could use a bndpass filter to smooth it to a sine wave to sound better, then direct drive the phones, using the voltage divider you describe.
But, need a way to adjust volume, and prefer to use two PIC lines to read two pushbuttons, then maybe drive I/O lines to a transistor somehow to control volume.
Any ideas on how to do this?
Well if you want a sinewave then sure, use a filter but be aware that it will be frequency dependent and won't be a perfect sinewave at all frequencies.
For volume control you can use a data port as a DAC. I'm assuming you are working with 8 bits here. If you want to use all 8 bits of precision for volume, between your headphone line and data lines use resistors like this:
1 ohm on D0
2 ohm on D1
4 ohm on D2
8 ohm on D3
16 ohm on D4
32 ohm on D5
64 ohm on D6
128 ohm on D7
Values don't have to be exact and you'll probably need 2 resistors in series to get close. If you don't need this much precision you could leave out as many as you wanted. Anyway for silence on the output, you could set the output to 128. if you wanted a quiet signal you could write 130 and 126 to the output alternately. For the loudest signal, you would write 0 and 255 alternately. You would probably need a comparator and latch to hold the output and assign a memory address to the sound output.
For volume control you can use a data port as a DAC. I'm assuming you are working with 8 bits here. If you want to use all 8 bits of precision for volume, between your headphone line and data lines use resistors like this:
1 ohm on D0
2 ohm on D1
4 ohm on D2
8 ohm on D3
16 ohm on D4
32 ohm on D5
64 ohm on D6
128 ohm on D7
Values don't have to be exact and you'll probably need 2 resistors in series to get close. If you don't need this much precision you could leave out as many as you wanted. Anyway for silence on the output, you could set the output to 128. if you wanted a quiet signal you could write 130 and 126 to the output alternately. For the loudest signal, you would write 0 and 255 alternately. You would probably need a comparator and latch to hold the output and assign a memory address to the sound output.
Thanks for helping again!
What is the reason for 2 resistors in series "to get close"?
Why set output to 128 for silence? Is setting it to any value continuosly the same result - silence? Wouldnt I just set all PIC pins to input mode or low to get silence?
For quiet signal you suggest "130 to 126 alternately". Why not 0 and 4 - is it the same result?
I understand your suggestion to use memory address for each sound level, but what is the purpse of a comparator and latch? If the PIC pins are simply held in the chosen state (on or off) for the right amount of time there is not need for the latch and comparator, right?
I have 4 I/O pins available, and think I can come up with two more, toal 6. As you advise limit of filter across frequency 300 to 800 hz, want to use the 4 - 8 pins to control volume and make pseudo sine wave - step function. Im thinking about how to do this now.
Thanks again for helping,and if you could help with my questions here I would surely appreciate it.
Ransom Peek
What is the reason for 2 resistors in series "to get close"?
Why set output to 128 for silence? Is setting it to any value continuosly the same result - silence? Wouldnt I just set all PIC pins to input mode or low to get silence?
For quiet signal you suggest "130 to 126 alternately". Why not 0 and 4 - is it the same result?
I understand your suggestion to use memory address for each sound level, but what is the purpse of a comparator and latch? If the PIC pins are simply held in the chosen state (on or off) for the right amount of time there is not need for the latch and comparator, right?
I have 4 I/O pins available, and think I can come up with two more, toal 6. As you advise limit of filter across frequency 300 to 800 hz, want to use the 4 - 8 pins to control volume and make pseudo sine wave - step function. Im thinking about how to do this now.
Thanks again for helping,and if you could help with my questions here I would surely appreciate it.
Ransom Peek
What is the reason for 2 resistors in series "to get close"?
Well first I suggested starting with a 1 ohm resistor. I have no ideas what the current drive capabilities of your PIC are so you may want to take all those values and multiply them by 10 to be safe. What I meant with two resistors to get close is this: You can probably find a 10 ohm resistor for D0. For D1 it may be difficult to find a 20 ohm resistor so put 2 10 ohm resistors in series. For the 80 ohm resistor you'll have to use 33 and 47 ohm resistors in series.
Why set output to 128 for silence? Is setting it to any value continuosly the same result - silence? Wouldnt I just set all PIC pins to input mode or low to get silence?
Yes, you could. I was assuming there weren't any caps in the picture. The reason for setting the output to 128 is becase it would give 1.5v on the output and 0v across the headphone leads.
I understand your suggestion to use memory address for each sound level, but what is the purpse of a comparator and latch? If the PIC pins are simply held in the chosen state (on or off) for the right amount of time there is not need for the latch and comparator, right?
My suggestion was to use a single memory address for sound output. I'm used to processors like 68000 or Z80, I've never done anything with a PIC so if you have dedicated data lines then you would not need a comparator for the address.
If you are sure that the value is held throughout the complete clock cycle then there is no need for the latch. On most processors, the data lines go dead on a low clock cycle which would introduce noise in your output. If your PIC holds the output and changes the value immediately with no dead time on the output then you don't need the latch either.
I have 4 I/O pins available, and think I can come up with two more, toal 6. As you advise limit of filter across frequency 300 to 800 hz, want to use the 4 - 8 pins to control volume and make pseudo sine wave - step function. Im thinking about how to do this now.
You should use all the pins available as simply "audio out" and treat it like a DAC. You can control the volume in software.
For quiet signal you suggest "130 to 126 alternately". Why not 0 and 4 - is it the same result?
With a capacitor, it will probably have the same result, but remember that your headphone's ground is at 1.5v. Switching between 0 and 4 will alternate the output between -1.5v and -1.45v (with 1.5 as a reference). So you have a large DC voltage being fed into the headphones that could be fixed either in software or with a cap. The reason going between 130 and 126 is better is because it will cause a 0.05VAC signal on the output with no DC offset.
- Status
- Not open for further replies.