Electronics and filters and things, help please!

The Joy of Tech - Anything and everything about all things shiny..
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Electronics and filters and things, help please!

Post by Kamineko »

I've got the first and second editions of the Art of the Electronics on my shelf, and I've come to the realisation that after studying them on and off for almost ten years I still don't know a damn thing about filters and couldn't design one if my life depended on it.

What I'm thinking about is building a small circuit that can detect audio and light an LED if there's something playing. Like one of those volume bars, but with only a single segment.

This would be for the Ocelot's audio output: if I rebuild the circuit on a bigger board, I can add in new elements that will show when each of the four channels is outputting audio, so you get nice blinky lights while the music is playing.

Image
The Ocelot's output looks like that on the left. Four 0V-3.3V square wave sources in the audio range that are summed together and then read off a pot to produce a value that's sent to the amp board.

I'm thinking I can read a value from each channel at their respective point X, hopefully without distorting their audio signals, and perform my detection.

* Since I don't want distortion the impedance looking into X should be >> the impedance looking down into the audio mixing section, so I want whatever I put at point X to be at least 1M.

What I think I need is to:
* Rectify/half-rectify the signal.
* Smooth it.
* Amplify it if I need to.
* Use that on the base of an NPN transistor to put it into saturation to allow the LED to light.

So here's my plan (on the right):
* I've got a capacitive coupling to start with producing a value at point 1. I need this in case the audio signal is left high after a note. This looks like a high-pass filter to me, so I want it to pass anything greater than say 100Hz.
* 2 is an emitter follower which will stop any further influence on the audio stuff while I do detection. I'll end up with a half-wave low-output-impedance 1V choppy signal at point 2.
* Then I need a low pass filter to smooth out this choppy signal. I want to get rid of anything less than 60Hz - the note on-off is controlled by code in the frame loop, so a nice neat on-off per frame would be good here.
* I need to present some kind of load to this output filter or it'll just immediately discharge right out the final transistor, I think? That's what the resistor between 3 and 4 does.
* So -if- there's an input signal that's > 100Hz, it'll be captured, rectified, isolated, smoothed, turned into a nice 'is a note playing' signal which I can then throw into the final transistor to put it into saturation and power the led.

Does that make sense? :/

The input impedance of this thing would be impedance looking into the first transistor parallel to the resistor preceding it. And the impedance of the after-transistor stage would be the network of resistors and capacitor, treating the final transistor as a direct ground.

I've mucked this up in a circuit simulator and it kind of works but I don't know if I'm thinking about this the right way.
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4598
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Electronics and filters and things, help please!

Post by Little stoned kiwi »

Kamineko wrote:What I think I need is to:
* Rectify/half-rectify the signal.
* Smooth it.
* Amplify it if I need to.
* Use that on the base of an NPN transistor to put it into saturation to allow the LED to light.

Does that make sense? :/
It does to me, for what that's worth.

Some diodes to rectify it, a capacitor to even it out (or a low pass filter). Then use a transistor to provide the correct voltage/current you need to the LEDs.
If you want to have LEDs that flicker the signal could be used as noise and overlaid DC voltage to the LEDs. Some give off different colours at different voltages.

I'm not sure if you want the high-pass filter (1) before the first transistor. It could chain off the low-pass filter on the other side. The first transistor is just to amplify the current from the square wave input? After the filters you'll have an AC waveform. If you want to just turn the LED on fully, rectifying that signal and make the second transistor sensitive enough (darlington pair?) to turn on hard.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Firefox
Sheepie Whore
Sheepie Whore
Posts: 11412
Joined: Fri Apr 26, 2002 6:15 pm 0
Location: Sheffield

Re: Electronics and filters and things, help please!

Post by Firefox »

I don't get why it needs rectifying. Isn't it already a 3V3 logic signal?
"I am a very considerate person. If I want to go out all night on my miniature golf course and shoot lizards, well, no reason to keep the neighbours awake..."
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4598
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Electronics and filters and things, help please!

Post by Little stoned kiwi »

AC is AC. Passed through the capacitors in the filters, it will end up as a wave with a +/- voltage. The DC biasing get's filtered out (you could say there's a 1.65v bias on a +/-1.65 square wave to start with).
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Firefox
Sheepie Whore
Sheepie Whore
Posts: 11412
Joined: Fri Apr 26, 2002 6:15 pm 0
Location: Sheffield

Re: Electronics and filters and things, help please!

Post by Firefox »

Oh, I see what you mean: you'll get alternating +ve and -ve pulses out of the cap.

Please excuse me - my analogue electronics is very rusty, and was my wobbliest subject even back when I was a student.
"I am a very considerate person. If I want to go out all night on my miniature golf course and shoot lizards, well, no reason to keep the neighbours awake..."
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4598
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Electronics and filters and things, help please!

Post by Little stoned kiwi »

This problem would be simpler without the analogue component at the end. That could be leveraged as a feature though.

I'm only sounding confident myself because I've been dealing with these challenges making my Class D amp.
Where' I've hit exactly the same problem. I've treated the power supply as +80/0v instead of a centre tapped +/-40v. Feeding DC80v pulse density modulation into a filter, but the waveform coming out from the filter stabilises down to +/-40v after 5ms. Fortunately the transformer is centre tapped so I can use that as ground for the speakers.
So I learned there is a good reason they use centre tapped transformers in amplifiers. It's just how AC and audio works.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Electronics and filters and things, help please!

Post by Kamineko »

Little stoned kiwi wrote:
Kamineko wrote:What I think I need is to:
* Rectify/half-rectify the signal.
* Smooth it.
* Amplify it if I need to.
* Use that on the base of an NPN transistor to put it into saturation to allow the LED to light.

Does that make sense? :/
It does to me, for what that's worth.

Some diodes to rectify it, a capacitor to even it out (or a low pass filter). Then use a transistor to provide the correct voltage/current you need to the LEDs.
If you want to have LEDs that flicker the signal could be used as noise and overlaid DC voltage to the LEDs. Some give off different colours at different voltages.

I'm not sure if you want the high-pass filter (1) before the first transistor. It could chain off the low-pass filter on the other side. The first transistor is just to amplify the current from the square wave input? After the filters you'll have an AC waveform. If you want to just turn the LED on fully, rectifying that signal and make the second transistor sensitive enough (darlington pair?) to turn on hard.
Thanks a lot for having a look. :)

The RC high-pass was intended as a coupling capacitor (but it's the same as a high-pass since I'd need a resistor to ground there too) since I was thinking of things in the order I'd write them as a program: step one, detect wiggles not flats.

I'll draw up a transistor -> lowpass -> highpass -> darlington design and run this into the simulator-o-tron (I'm using the falstad one since life's too short to learn spice right now :P ) and see what happens. Then I just need to figure out all the correct values given the low and high knees I want and the impedance I want it all to have. Also ideally I'd want the LED to be stable fully on during a wiggle and react to being fully-on/fully-off within 1/90s of the wave appearing.
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4598
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Electronics and filters and things, help please!

Post by Little stoned kiwi »

Impedance wise it doesn't matter. The resister you select for X creates a current divider with the 200k resistor. Since it's a DC signal at that stage, stealing a little won't mess with the frequencies encoded in the digital signal. You need enough current to turn on the first transistor.
There could be a danger from attempting to draw too much current from your source. Probably not but something to keep in mind.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Electronics and filters and things, help please!

Post by Kamineko »

Yeah I definitely don't want to draw any current at all from the signal pin.

Code: Select all

$ 1 0.000005 3.5993318835628396 50 5 50
R 208 128 208 48 0 2 2000 1.7 1.7 0 0.5
r 208 224 208 352 0 220000
r 208 432 208 480 0 25000
g 208 480 208 560 0
r 208 432 208 352 0 25000
w 208 432 352 432 0
O 352 432 416 432 0
162 688 160 688 192 1 2.1024259 1 0 0 0.01
R 688 112 688 48 0 0 40 3.3 0 0 0.5
r 688 112 688 160 0 280
s 208 224 304 224 0 0 false
s 208 160 208 224 0 0 false
r 208 224 128 224 0 1000000
g 128 224 128 304 0
f 144 144 208 144 0 1.5 0.02
R 144 144 64 144 0 2 60 5 0 0 0.5
t 304 224 352 224 0 1 0.0702048139723015 0.6162883943852138 100
r 352 240 352 320 0 2000
r 352 240 464 240 0 2000
c 464 240 464 320 0 0.000002 1.0065429291808357
g 464 320 464 352 0
g 352 320 352 352 0
R 352 208 352 112 0 0 40 3.3 0 0 0.5
t 544 240 688 240 0 1 0.5394087506201404 0.630583028880976 10000
w 688 224 688 192 0
g 688 320 688 352 0
w 464 240 544 240 0
O 352 240 416 160 0
O 464 240 480 160 0
r 688 256 688 320 0 100
o 0 8 0 4099 5 0.00009765625 0 2 0 3
o 6 8 0 4098 0.3125 0.1 1 1
o 7 8 0 4099 2.5 0.00625 2 2 7 3
o 27 8 0 4098 5 0.1 3 1
o 28 8 0 4098 1.25 0.1 4 1
o 26 8 0 4097 5 0.00078125 5 2 26 3
http://www.falstad.com/circuit/circuitjs.html

These values look nice, but I don't really have any mathematical basis for them... The discharge speed of the capacitor is through the first and last emitter resistors (though only the last one if its above a diode drop), I put one at the end because I want the capacitor to charge up to a volt at least otherwise trough of the wiggly waveform might dip below enough to turn on the final transistor and it'd flicker instead of staying on nicely for a tiny bit longer.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Electronics and filters and things, help please!

Post by Dio »

Yes, you need to avoid distorting the input, so using purely passive components is workable but not trivial.

I'd use a low gain, high input impedance amplifier, feed it to a diode to rectify, that charges a capacitor. Put a resistor across the cap so it discharges at a predictable rate of a second or so, then another high-gain amplifier that detects any voltage in the capacitor and if so lights an LED via a resistor. Simplest method is likely a dual op-amp with the couple of discrete components.

I wouldn't bother too much about the maths. This is a qualitative process not a quantitative one. Pull components out of the bits box until it works, and use a couple of variable resistors to set the sensitivity and discharge rate.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Electronics and filters and things, help please!

Post by Kamineko »

Not wanting to draw any current from the signal pin (this is a gpio from a dsPIC) is why I picked the big resistances for the audio summer. As long as this thing has a similar or greater impedance all should be good (as long as no weird reverse voltages come shooting out of it).
I wouldn't bother too much about the maths. This is a qualitative process not a quantitative one. Pull components out of the bits box until it works, and use a couple of variable resistors to set the sensitivity and discharge rate.
I've already messed about for too long. This is the perfect time for maths since it doesn't get any simpler than this.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Electronics and filters and things, help please!

Post by Kamineko »

If I make the last transistor a mosfet I don't have to account for current discharging through it or the thing failing to charge beyond a diode drop making the light would immediately go out when the input is zero instead of lingering since it couldn't charge beyond the v drop of the output transistor.

That means if I only have a smoothing capacitor I'll only have one passive filter so I only have one path to ground so I can make it look more like this.

Image

All I need to do now is make sure that the discharge rate is appropriate so that it'll decay quickly from chip-logic-output-high minus transistor-diode-drop to below mosfet-activation-voltage within the space between notes if they're activated in adjacent 60Hz frames. Input impedance is beta * complex impedance of cap|res.

The 1 resistor could go I just haven't taken it out yet.

---

Though that does raise the question of whether the output voltage of the gpio pins at high minus a diode is even enough to trigger the mosfet!

Image

So... hmm...
DO20 gives the current boundaries that you can approach to have a guaranteed 2.4V showing.
DO20A gives the voltage variations that you can expect for different current usages.
It's like those annoying table pairs from statistics in maths that give you the values of the integrals for the normal distribution together with the bounds values if you already know the integrals.

2.4 through a transistor drop isn't going to be enough.

Maybe I can have two inverting transistor stages to doubly flip and isolate the output so I get a nice 0-3.3v guaranteed input (or a normal buffer chip...). (or invert everything to make a system that prevents the LED lighting on a voltage low rather than enabling it to light on a voltage high)

Or just replace the first bjt with a mosfet too! Mosfets everywhere! No wait then I'll have fiddly nonsense with the GS voltage of the first section being insufficient when the cap voltage rises. I hate three terminal transistors a whole lot. : s
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4598
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Electronics and filters and things, help please!

Post by Little stoned kiwi »

Being some variant of pulse width/density modulation, it will have an average duty cycle of 50%. Expect 1.65v.
If you're going to cut out the filter stages, could you smooth out the input and amplify that to rail voltage? As it is, the first transistor is going to have a duty cycle of 50% as well.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Electronics and filters and things, help please!

Post by Kamineko »

Little stoned kiwi wrote:If you're going to cut out the filter stages, could you smooth out the input and amplify that to rail voltage? As it is, the first transistor is going to have a duty cycle of 50% as well.
Could you give me an example of the kind of circuit you're describing please?
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Electronics and filters and things, help please!

Post by Kamineko »

latest falstad sim
Spoiler: show
$ 1 0.000005 15.472767971186109 50 5 50
R 208 128 208 48 0 2 600 1.7 1.7 0 0.5
r 208 224 208 352 0 220000
r 208 432 208 480 0 25000
g 208 480 208 560 0
r 208 432 208 352 0 25000
w 208 432 352 432 0
O 352 432 416 432 0
162 688 160 688 192 1 2.1024259 1 0 0 0.01
R 688 112 688 48 0 0 40 3.3 0 0 0.5
r 688 112 688 160 0 330
s 208 224 304 224 0 0 false
s 208 160 208 224 0 0 false
r 208 224 128 224 0 1000000
g 128 224 128 304 0
f 144 144 208 144 0 1.5 0.02
R 144 144 64 144 0 2 60 5 0 0 0.5
t 304 224 352 224 0 1 -3.2999999999984713 -2.698167558134767 100
g 464 320 464 352 0
g 352 320 352 352 0
R 352 208 352 112 0 0 40 3.3 0 0 0.5
w 688 224 688 192 0
g 688 320 688 352 0
r 352 240 352 320 0 2000
c 464 320 464 240 0 0.000009 -2.6981675581362956
w 464 240 544 240 0
w 352 240 464 240 0
f 544 240 688 240 0 2 0.02
O 464 240 464 144 0
w 688 256 688 320 0
o 0 8 0 4099 5 0.0125 0 2 0 3
o 6 8 0 4098 0.625 0.1 1 1
o 27 8 0 4098 5 0.1 2 1
I should put the resistor back in in between the resistor and capacitor on the right because if I dont there's a direct line from the signal output towards the capacitor so a lot of current could go out of my signal pin briefly there. Maybe make it 10R.
Post Reply