Can someone tell me where I went wrong

Marcwolf

Senior Member
Hi Folks.
I'm ok with digital but analogue sometimes gives me a headache. Can someone look at this and tell me where my thoughts went wrong

I am using an AH1802 which is a hall effect switch. It has a ground, a Vcc (5v) and an output that is open collector so you need to put a 10K resistor between the Vcc and the output. The output measures 0 until a magnetic field is applied and then it goes to Vcc.

What I want to do is to create a chain of 8 of these feeding into a resistor divider so that I can get an analogue voltage out of it. This will go to a 08M2 where it will be read and the output send as a serial string.
For design sake I cannot put the picaxe on the same board as the rest of the components.

I have only shown 5 stages here and I have 8 in total.

If someone can offer some advice I'd be really grateful.
Marc
 

Attachments

Last edited:

Billo

Senior Member
I don't think your resistor network works out correctly. It does not provide a linear voltage change.

See the attached schematic. This should work. Each of the free resistor legs , including the straight through wire (bottom) would go to the open collector output of one of the AH1801s. The values shown are the closest match for 1% resistors, use the closest thing you have. The top one would be the one nearest to the magnetic source, the bottom one the furthest.

This should produce the 9-step series Vcc, .857Vcc, .75Vcc, .625Vcc, ...., .125Vcc, 0V as you go from no Hall devices in the field to all devices in the field

RESNET.jpg


Edit: Just re-read your post. The bottom one will actually need to to be the nearest to the magnetic source and the series will go from 0V to Vcc as the hall sensors enter the field. I should mention this assumes that more and more sensors enter the field as the array approaches the magnetic source. If there is only one sensor in the field at a time, the same approach would work, but the resistor values would need change to guarantee a sufficiently distinct reading for each sensor.
 
Last edited:

techElder

Well-known member
Marcwolf, the actual voltage values of your ladder won't matter. You just need values distinct enough to select after the 08 does it's A/D conversion. Makes resistor selection much more simple.
 

techElder

Well-known member
Oh, I forgot. Design for CURRENT since you are separating the sensor from the 08. Use a suitable resistor at the 08 A/D pin to convert the current to a voltage.
 

hippy

Technical Support
Staff member
I think a lot depends on whether one or multiple hall sensors can be active at any one time. Trying to create a 256 step ADC voltage depending on 8 inputs and have a PICAXE discriminate those 256 states can prove challenging.

Th easiest solution is perhaps to have two sets of four-per-ladder.
 

AllyCat

Senior Member
Hi Marc,

Your top stage (U1) has 10k in parallel with 330 ohms, so basically just 327 ohms to Vcc! The other stages don't have values marked, but I think we can assume that it won't work as hoped or intended. The fundamental issue is that an "open collector" output has "high" impedance, so the output impedance of each stage is 10k and trying to drive a 330 ohms load is likely to be doomed to failure.

"Ladder" D/A conveters are indeed a very interesting arrangement but they generally rely on being driven by a LOW source impedance. You might do better with a "current-summing" design, but as hippy says, you're very unlikley to be able to resolve 256 levels, or even discriminate a change in level at the "wrong" (attenuated) end of the chain.

The first thing to discover is how LOW (and high) a value of pullup resistor to Vcc that a 1801 can tolerate. Then (again as hippy says) split the A/D conversion into a suitable number of stages (or inputs).

Cheers, Alan.
 

MPep

Senior Member
Hi Marc,

Reading your request, the first thing that comes to mid is the R2R ladder. More info http://www.eecs.tufts.edu/~dsculley/RCX.
They discuss a few options, but for digital interfacing such as yours, the R2R ladders appears the easiest to implement.
As discussed though, you may need multiple ladders to get good results regarding resolution.
 
Last edited by a moderator:

Rick100

Senior Member
You could use a buffer , like a 74hc14 inverting Schmitt trigger , between your hall effect switches and the R2R ladder . It would get around the open collector output problem .
 

Billo

Senior Member
The R2R ladder is great for a system that has 8 independent inputs and will produce a 256 state system. We'll have to hear from Marc, but I got the impression this was a 9 state system where the hall sensors from 1 to 8 turn on one after the other, going from all off to all on in 9 steps. Admittedly it was an assumption on my part. An R2R ladder would certainly not produce a linear response in this case and uses a lot more resistors than would be required.

If it is a 9 state system, the resistors in the scenario I gave do not have to be exact. What ever you have in your kit that is close will do.


Edit: Also, it should be noted that one needs very precise resistors for an R2R network to be truly linear and not have overlapping values. Usually 0.1% precision is needed. One more point, if it is a 9 state system, the circuit I gave would work just fine with open collector devices.
 
Last edited:

premelec

Senior Member
Without more info from OP - I'll suggest using a 20M2 with 8 inputs used for the 8 hall effect [or reed switches or whatever] inputs and then an 8 bit DAC IC serially connected [there are many] to develop the analog signal in any form you want [weighted, monotonic etc]. There is also a possibility you'd use one of the new chips that senses a rotating magnet [like Melexis] - but OP hasn't said just what is being done with magnetic field etc.
 

MPep

Senior Member
Also, it should be noted that one needs very precise resistors for an R2R network to be truly linear and not have overlapping values

Not have over-lapping values????
:confused: You're kidding right.

They can't be over-lapping by design. You only need 2 values, one is double the other. Hence, R-2xR. 1% resistors are not that difficult to get hold off and should work fine. For PICAXE use I'd consider using 5k and 10k resistors.

My impression is that the OP wants to have minimal inputs on his
Main Controlling PICAXE, and hence use an ADC input.


Admittedly, I'd be tempted to use a separate PICAXE with enough inputs and read the sensors directly, and then serially send the value through to the Main Controlling PICAXE.
 

Marcwolf

Senior Member
Hi Folks
Many thanks for all of you suggestions. I will be going through them when I am at my bench tonight.
I'll explain what the project is

One of the issues when being in a full costume is controlling things. So I have made a mold of my upper palette and cast it in resin. Think of one of the old style upper dentures but without the teeth.

Now around the edge of this I have the hall effect switches, and with surgical superglue (yes it does come off after a few days) glue a tiny magnet to the tip of my tongue. Now by pressing the magnet against one of the hall effect switches I can activate it. Only ONE switch will be turned on at a time.

This way I can have 8 switches and only 3 wires coming out from the corner of my mouth to a 08M2. Hence using the resistor network to create an analogue voltage to determining which switch has been activated.

Again thanks for your help..
Dave
 

techElder

Well-known member
I reemphasize my previous comments about "current" and not needing to have any precise voltages for the 08. Just create 9 or 10 different current levels and detect those in programming in the 08.
 

cravenhaven

Senior Member
How about a simple resistor ladder as shown. I represented the hall switches as simple pushbuttons to earth. Even with the resistors all being the same value you would get voltage levels that should be reasonably easy to discriminate via the ADC.

Assuming All resistors are equal and Vcc=5v
Sw1 closed - Vo=0
SW2 closed - Vo=2.5
Sw3 closed - Vo=3.3
Sw4 closed - Vo=3.75
Sw5 closed - Vo=4.0
Sw6 closed - Vo=4.16
Sw7 closed - Vo=4.28


Allan

resistor-ladder.jpg
 

Attachments

Billo

Senior Member
Not have over-lapping values???? [/COLOR]:confused: You're kidding right.
No, I'm really not.

They can't be over-lapping by design.
Yes, they actually can.

For example, if the 2R value for the MSB is off by 1% low, there will be a distinct step down in the response curve. For a lark, build one with 5% or 10% resistors and then output 0 to 255 to it repeatedly and look at the result on an oscilloscope. You will see what I mean very clearly. Also, you can read this article. A google search on "R2R ladder precision" will get you more to read on the subject as well if you're not a fan of Wikipedia. The resistors on the successively more significant bits need to be very precise to avoid this (better than 0.4% on the MSB to avoid overlapping values and better than 0.1% to maintain reasonable linearity).
 

Marcwolf

Senior Member
How about a simple resistor ladder as shown. I represented the hall switches as simple pushbuttons to earth. Even with the resistors all being the same value you would get voltage levels that should be reasonably easy to discriminate via the ADC.

Assuming All resistors are equal and Vcc=5v
Sw1 closed - Vo=0
SW2 closed - Vo=2.5
Sw3 closed - Vo=3.3
Sw4 closed - Vo=3.75
Sw5 closed - Vo=4.0
Sw6 closed - Vo=4.16
Sw7 closed - Vo=4.28


Allan

View attachment 15259
Hi Allan Thanks for the info but looking at your circuit I'd only be reading the voltage between vcc and the first resistor all of the time. Many thanks Dave
 

Marcwolf

Senior Member
Hi Billo. Only one sensor will be active at a time. But your network should work. I will try tomorrow. Many thanks
 

elanman99

Senior Member
Hi Allan Thanks for the info but looking at your circuit I'd only be reading the voltage between vcc and the first resistor all of the time. Many thanks Dave
Which is exactly what you want!

As long as the resistor all have different values, the voltage you will see will be different for each switch.

For your (rather ingeneous) application, linearity, precision resistors, and mathematical theorems are all irrelevant. I imagine the hardest bit will be controlling the resolution of your tongue!

Good luck and remember not to swallow the magnet


Ian
 

Billo

Senior Member
Hi Billo. Only one sensor will be active at a time. But your network should work. I will try tomorrow. Many thanks

Then I'd change the resistor values to something like 68K, 30K, 16K, 10K, 6.2K, 3.3K, 1.5K, 0k. That will give you the best separation in voltages. Let us know how things work out.
 

Billo

Senior Member
Regarding the precision required for an R2R DAC and the possibility of overlapping values I had time today to do a little experiment to demonstrate what I'm talking about.

See the attached images. I built a 8-bit R2R DAC using selected 680 ohm resistors. The two scope shots show two errors. One is a digital scope the other analog. In both pictures, the error on the lower left represents a ~0.5% error on bit 5. Instead of 1360 ohms, the 2R on bit 5 measured 1367 ohms. The error shown on the upper right was induced for demonstration purposes by replacing one of the 680 ohm resistors on bit 7 with a 740 ohm so that the 2R value measured at 1418 ohms representing a ~4.3% error. Both errors result in overlapping values (where different inputs result in the same output)

Edit: The experimental setup and code used are in the next post.
 

Attachments

Billo

Senior Member
Here is the experimental set-up and the code.

Code:
b0 = 0
dirsB = %11111111
setfreq m32

Start:
let outpinsB = b0
inc b0
goto Start
 

Attachments

rq3

Senior Member
If someone can offer some advice I'd be really grateful.
Marc
Here's what the LM3914 device looks like internally. It may give you some ideas.

LM3914.jpg

Your hall effect devices would take the place of the comparators, and your picaxe ADC would
take the place of the input, but the ladder network is the take away item.

Rip
 

cravenhaven

Senior Member
Hi Allan Thanks for the info but looking at your circuit I'd only be reading the voltage between vcc and the first resistor all of the time. Many thanks Dave
Actually you would read the values I quoted in my post. I think you are misunderstanding the resistor divider process. Each switch changes the divider ratio which is why the output voltage changes as the switches are closed.

So for the sake of simple maths lets assume all resistors are equal at 1K.
Sw1 Closed, Vo=0
Sw2 closed, Vo = Vcc*R/2R =5*1/2 = 2.5
Sw3 closed, Vo = Vcc*2R/3R=5*2/3 = 3.3
.
.
.

It might be easier to examine the current through the network to realise the voltage at the output.
So if Sw5 is closed then you would have a total of 5 resistors between Vcc and ground, 4 resistors between Vo and ground:
Ir = Vcc/5R = 5/5000 = 1mA, (Ir is current through the resistor chain)
Vo =Ir*4R = 1mA * 4000 = 4V.

Allan
 

Buzby

Senior Member
All these experimental efforts, and the resulting graphs are really cool.

But I would like to see the long term effects of superglueing a magnet to a tongue !

Cheers,

Buzby, + Monkey Shoulder.
 

Marcwolf

Senior Member
Hi Folks. Here is a picture of the shield. The round think at the end is a tiny earphone speaker so I can get feedback as a toned beep. After completing it will be given a coating of silicon or nail varnish to protect it.SDC10226 (Small).JPG I apologise for formatting but with IE I cannot put in linefeeds :)
 

Marcwolf

Senior Member
Actually - with experiments with paraplegics it has been shown that the tongue is rarely affected by the spinal injury, it highly flexible, and the tip can be accurately place anywhere in the mouth (within reason). Try it for your self - just start tapping your teeth with your tongue. In addition there will be bumps added to the final coating so that I can track what button is what before activating. The center button is a emergency 'stop' for cancelling a command before it fully activated.
 

Marcwolf

Senior Member
Many thanks everyone for all of your advice. I realized in the end I was constructing the resistor array incorrectly and that the hall effect switches were not the one's I though they were (Damd SMD components)

Anyway - here is the finished item and it works. I have worn it for testing several times

SDC10240.JPG
 
Top