Let's Make Robots!

picaxe08M - using pin 5 for ADC input AND speaker output. problems.

Hello people.

update:

The problem, as always is situated between the chair and the keyboard.

Telefox mentioned that a pizo is actually capacitor-like, not resistor like as I had assumed. The diode therefore, prevents the pizo from discharging. A proposed solution was to buffer the pizo with a transistor and pulldown resistor, or a double transistor (i.e an inverted inverter), with a pull up. 

I'll try these, and see how it all works out. 

original post:

-------------------------------------

Like most people, I was drunk when I took my electronics classes (everyone else was drunk too right?). I have a hazy recollection of trying to recall ohms law in the middle of the final exam.

 But enough of my bacchinalian lifestyle - onto the problem:

I'm putting together a machine that does very little other than wander around and avoid walls, using the IR sensor circuits that Oddbot wrote up. I suppose it's a bit like the start here robot in it's functionality.

(Just as an aside, the sensor circuits work very well- mine picks out a surface from about 20 cm away, and as close as 5 cm - which is as good as the SHARP sensors.)

 

Picture_2.png

This creation is using a picaxe 08, because I want it to be small and compact, and I want to be efficient in using pins - the problem is I'm trying TOO hard to be efficient.

The outputs are:

1, left motor

2, right motor

3, sensor-rotate servo

4. IR lamp high/low 

5. speaker.

the inputs are:

1. bumper switch

2. ADC input from IR sensor 

Picture_2_0.png

since the 08 only has 5 in/out pins (three are both adc AND in and digital out, one is digital in, one is digital out) pins, I have to multitask on some pins. i.e. I use  the same pin for the IR lamp and servo, however I ALSO want to use pin 5 to output to speaker AND read the ADC input from the IR sensor. And this is where the difficulty lies.

Here's the circuit I'm using, Since I was largly incoherent for my basic electronics labs, I've just used diodes to try to separate out the input and output signals, as seen by pin 5. The pizo also sees the output from the transistor - but that's no problem because it's zero for most of the time.

 

 

 

Now, when I connect this up, and read from the ADC, I get a lot of jitter on the ADC output. I thought it might be some problems to do with impedance mismatching, and the pulses from the transistor circuit might be reflecting off the the diodes, so I goofed around with some resistors to try to get the resistance of the pizo circuit to match that of the transistor circuit - as seen by pin 5 - but I rapidly descended into alcholic fog with complex numbers embedded in it and I had to go get a drink. Realising that I am now clueless about what is going on, I'm posting the situation and hoping that people who were NOT drunk during their electronics classes might be able so share a few pearls of wisdom or other thoughts. Pearls of ignorance are also acceptable. 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

No expert in electronics - never did study that at school (other than valves!)

 

I wonder if you need more than 1 diode in the speaker side - try 3 or 4 in series (one after the other).  At the moment you will see only ADC voltages greater (roughly) than 0.6v, assuming silicon diodes. But that is also passing through to the speaker.  As soon as the ADC is greater than 0.6v it will be clipped to 0.6v by the speaker diode. This, I belive could be the reason for the jitter. 

By increasing the number of diodes in the speaker side you should at least get some usable range on the ADC.

Just the way I see the circuit working - any relationship with reality would be totally coincidental :)

Pete

Piezo speakers pretty much ignore DC signals anyway. When you connect a regular speaker to an output, you often protect it with a capacitor, but a piezo passes DC without noticing, so a capacitor is not needed.

It occurs to me that the diode on the piezo side of the circuit is totally unnecessary. It allows signals to pass from the output or the transitor circuit, so why even include it?

 

I like trying to get as much out of the 08 chips too. I like your approach with diodes, so I hope you get it working!

I'm planning on using a 4PDT relay or 4 channel mux to allow the 08 to have more I/O. One of the 5 pins will be used as the control for the relay/mux, leaving me with 4 inputs/outputs to switch between functions.

Can you test your ADC with the piezo circuit disconnected to see if the problem is really interference or something else?

 

In case you missed the note I left in the shout box:
Do you have any spare inverter channels left over from your motor driver lines? One of those would be great for driving your piezo while keeping it buffered from the IR side of the pin5 circuit.