Help Measuring positive and negative values

Hello Everyone!
I am new to PICAXE and this is my first proper post. I have been been doing a lot of reading and have written one program so far. (only tested by simulation so far as I havent completed the hardware)

My overall goal is to build a digital dash for my old landcruiser. To do this (replacing all existing gauges) I need to have: Oil Pressure, Fuel Level, Engine Temperature, Charge Current and obviously vehicle speed and distance. I am planning on buying a small probe for the speedo cable which sends out pulses which I can then count with the count command to calculate vehicle speed and distance. I have the oil pressure and fuel level program done. Temperature will be just like the fuel and oil pressure but I am stumped on how to read the charge current simply because it has the possibility of being both positive and negative (I think the standard meter in dash goes between -50A and +50A from memory). I am planning on using a current shunt which is calibrated to 1mV/A. This way I can use the readadc command to read a voltage from it. The problem is that depending on the battery load / charge current, this voltage could be either positive or negative.
Can someone please give me an idea of how I can monitor this value and keep track of whether it is positive or negative? I have an idea of trying to convert negative values back to positive and then using a separate input as a polarity indicator.....

Thanks in advance.
 
Last edited:

hippy

Ex-Staff (retired)
Once you've got the current converted to a voltage, you can then add an offset voltage to that so it becomes a positive only voltage which the PICAXE can read. For example, -50A to +50A becomes -5V to +5V, add 5V and it becomes 0V to +10V.

You'll have to ensure the final voltage is below the PICAXE supply voltage but that should be easy enough. If using an op-amp in the circuit you can add the offset there plus adjust the gain.
 

Dippy

Moderator
Can you indicate (with a sketch) where you are going to install this shunt, the value/rating and where you are going to connect to your ADC input.
 

Jaguarjoe

Senior Member
Linear Technology and Maxim and others I'm sure, have current sense IC's which are made to take the mv level across the shunt and give you a much higher output for the ADC. There are many application notes for these chips, bidirectional current sensing should be covered in one of them.
If you do try to measure a negative current, you may need a negative power supply. An ICL7660 (and its cousins) will generate a negative output voltage from a positive input. Whatever positive voltage you feed it will return a negative voltage of the same amplitude. You can use a 555 oscillator and a diode pump to create negative voltage too. None of these supply substantial current but they'll easily do a few op-amps or similar IC's.
 
hi guys, thanks for the replies. I am not all that familiar with op-amps to be honest. I am an electrician by trade but have always had a liking to electronics. I have just never gone too deep into them untill now. I will certainly start reading up on them if they can help with this issue.

The current shunt I was looking at was going to be this one:
http://www.altronics.com.au/index.asp?area=item&id=Q0470

as for a diagram, I am currently after from home for another week but found this online which is the correct diagram for my car. I was planning on using the shunt in line with / as replacement (with series fuse or circuit breaker) to the fusible link that I have circled as this is what the existing ammeter reads.

cheers guys,

Dave
 

Attachments

Op-Amps

I have been doing a bit of reading and come up with an idea. Using an Op-Amp in a voltage summing setup I could get the offset as suggested by Hippy. My understanding is that the output would then be negative so I would then have to run through another Op-Amp to invert this back to a positive value....
I have attached a diagram I found when readin up on these. What values would I need for the resistors- R2 and Rref? My understanding is that R1 will be the current shunt....is that correct?

Reading about these has brought back a lot of memories because I did know how to use these once upon a time!

Cheers,

Dave
 

Attachments

Jaguarjoe

Senior Member
The car battery should have 2 wires coming off of the (+) post, a large fat wire going to the starter motor and a less fat wire going to the rest of the car. Put your shunt in line with that less fat wire so you will be able to measure all of the current going into and out of the battery except for the very high current starter motor.

Unless your electrical system was designed by Joe Lucas, you should not need any more fuses or circuit breakers.

If your alternator can only provide 50 amps maximum then just use a 50 amp shunt. This will give you more current sensing voltage to work with. A 0.5% industrial shunt is overkill for an automobile. You can save money if you want by finding a 1 or 2% shunt.

The shunt will require a differential amplifier to accurately measure its very small shunt voltage especially when it floats above ground potential. A summing amplifier can't do that.

Here is a Maxim application note that pretty much maps everything out to get you going:

http://www.maxim-ic.com/app-notes/index.mvp/id/1949
 
thanks Jaguarjoe,

That should sort it out! The output of that setup could then go straight into the PICAXE ADC pin...correct?

The reason for thinking of putting fuses / circuit breakers in was just to get rid of the fusible link. I am planning to rewire the whole car and put circuit breakers in place of the fuses in the fuse box also.

Thanks for the help!
 

JoeFromOzarks

Senior Member
Unless your electrical system was designed by Joe Lucas, you should not need any more fuses or circuit breakers.
I just have to ask, who is this fellow "Joe Lucas?"


From: http://en.wikipedia.org/wiki/Lucas_Industries

In 1850s the jobless father of six, (Joseph) sold paraffin oil from a barrow cart around the streets of Hockley, The company was then founded by Joseph Lucas in 1860 with his son Harry, joining his father around 1872, aged 17.[1] Initially called Joseph Lucas & Son from 1882 it was based in Little King Street, later Great King Street Birmingham. At first it made general pressed metal merchandise including plant pot holders, scoops and buckets and later in 1875 lamps for ships, later moving into oil and acetylene lamps for bicycles from 1879.

In 1902, what by then had become Joseph Lucas Ltd, incorporated in 1898, started making automotive electrical components such as magnetos, alternators, windscreen wipers, horns, lighting, wiring and starter motors.[1] The company started its main growth in 1914 with a contract to supply the Morris Motor Company with electrical equipment.[1] During the First World War Lucas made shells and fuses, as well as electrical equipment for military vehicles.
This guy?

:) joe
 

Dippy

Moderator
I go along with JJ.
This was why I asked where you proposed to put the shunt - to see if you were sticking it in line with the starter too, which could be a problem.

Using one of the many Diff Amp methods is the best way.
BUT please incorporate any filtering/suppression methods that are suggested in App Notes - often simple RC stuff.
Without them you could damage the Diff Amp and/or your PICAXE.
The power supply to your circuit should be bullet-proof.
It's fairly easy and remember that spending an extra hour and an extra quid/buck now could save your project and your hair.

Any device Data Sheets should be read cover to cover, because some shunt diff-amp combos can go a bit wobbly at the extremes esp bottom end where you may have to use some twiddiling to extend the range (if needed).



And obviously you will be studying the ratings and failure behaviour of any fuses and CBs you add.
 
Maxim MAX4377 / MAX4198

Jaguarjoe,

Where could I buy the Maxim chips you have mentioned? None of the electronics suppliers near me seem to stock them and Maxim's website basically tells me they are too busy dealing with big business to sell to me!

Regards,

Dave
 
Last edited:

Dippy

Moderator
Many manufacturers make suitable devices.
TI (e.g. INA200 range and INA139 , INA169 may be OK)

Go to Diodes Inc (they absorbed Zetex).
The Zetex AN39 "Current measurement applications handbook by Peter Abiodun Bode, Snr. Applications Engineer" is handy reading.
They also make current sensing diff amps.

Have you tried Farnell?
http://uk.farnell.com/jsp/search/browse.jsp?N=500006+1004429&Ntk=gensearch_001&Ntt=current&Ntx=mode+matchallpartial
- something amongst that lot might be appropriate and/or available.
 

hippy

Ex-Staff (retired)
as for a diagram ... I was planning on using the shunt in line with / as replacement (with series fuse or circuit breaker) to the fusible link that I have circled as this is what the existing ammeter reads.
It would seem logical to me to put the shunt ( or whatever ) across the ammeter connections which is separated from the rest of the wiring by two fuses.

Usual safety and regulatory caveats apply.
 
pyrogaz,

I quite like the look of that hall effect unit you have suggested. it would take quite a bit of the work out of the job since it is all fairly well self contained. it has a 6.3mm cable opening which should be enough for a decent cable considering it will not be monitoring the starter current, only accessories. the good thing about the old landcruiser is that being a diesel, once the engine has started, there is very little current draw from anything. you can remove the battery (and alternator output) and the engine stills runs!
 

Jaguarjoe

Senior Member
That Devicecraft part just took all the fun out of this! It would be ideal for application. It looks like you can get a 1/2" hole unit for almost the same price.
One caveat- make sure the temperature spec of the unit can handle the temperature range of its environment in the LR's engine compartment.
 

geezer88

Senior Member
I'd use a device such as the Allegro A1351. Here's the data sheet:

http://www.datasheetarchive.com/Indexer/Datasheet-068/DSA00291021.html

It is a linear Hall effect device that can measure a +/- magnetic field and output a pulse width modulated signal that the Picaxe can measure. You would need to make a field concentrator to go around one of the battery wires similar to that described near the end of the above data sheet. This will allow the current to be measured going in either direction.

tom
 

pyrogaz

Member
One caveat- make sure the temperature spec of the unit can handle the temperature range of its environment in the LR's engine compartment.
We have one of the Devicecraft units on an electric endurance racer mounted within a couple of centimetres of the motor in a very restricted space, 70c-90c is about the normal operating temperature; probably not as extreme as a 4x4 in Oz but might be useful to know.
 

inglewoodpete

Senior Member
Over 20 years ago, I designed and built a fully electronic ammeter based on the LM3915 (log bargraph chip) and a couple of op amps. The concept was to monitor the voltage across the earth strap (usually connected between the battery 0v and the engine casting or car body). Even a fat cable will develop a small voltage along it's length when current flows through it.

The advantage of this design is that you add no series elements to your vehicle's critical charge and discharge circuits. There are no sensors in the engine bay to overheat. Just two wires at earth potential, carrying practically no current, each with a brass ring-type lug at the end secured under the securing bolts at each end of the earth strap (cable).
 

Jaguarjoe

Senior Member
If you can calibrate it, you'd be all set. The longer the ground strap the more sense voltage you have to work with.
OP's LR has an existing amp gauge. If it's accurate, he could do this.

I like the $8 non contact sensor. I'm intrigued over how the sensor is only $8 but the LED readout is $80. You can buy LED meters all day long for $12. Also, I don't know why anyone would pay $140 to servo control their windscreen wiper motor:)
 
I have ordered one of the Devicecraft units so I will let you know how I go with it. Of all the options mentioned so far I think it will be the easiet to get working and heat shouldnt be a problem as I will mount it inside a sealed box with cable glands at each end.

My next hurdle is the speedo side of things but that should probably go in a separate thread. I wanted to run a curve of LED's, 1 for every 2km/h and have them light up as speed increases. I will be reading vehicle speed from a unit which sends out pulses. I was looking at daisy chaining 8, LM3914 LED bar / dot driver chips together and feeding them with the output from a DAC or using the ladder network setup I have seen on these forums using 7 outputs. 7 bit resolution is plenty since I would only need 80 steps to get 160km/h.

Any other ideas? (Let me know if I should start this thread separately)

Cheers everyone, this forum is awesome. I havent built anything yet but want to get all the theory sorted beforehand so I can buy the best parts for the job.
 

inglewoodpete

Senior Member
7 bit resolution is plenty since I would only need 80 steps to get 160km/h.
Since our speed limit is 110kmh, you could save on LEDs and just have the remaining ones emit some smoke if you go over the limit:D

Be aware that you will converting digital to analogue back to digital and the result could a lumpy result. Especially is you are relying on minimal resolution.
 
Last edited:
haha, yeah I realise that 160km/h is overkill (I certainly wouldnt want to be behind the wheel of this thing at 160km/h - 1984 Landcruiser....) but I'm just trying to keep a semi-orignal feel to the new dash.
I am also open to other ideas about driving the LED's without the need to convert from digital to analogue and back again but my limited electronic / programming knowledge has led me there.
I plan to output the vehicle speed to an LCD display as well so the LED's are more for show! (and giving a sense of the original speed markings the needle would normally point to)
 

hippy

Ex-Staff (retired)
A standard 8 x 7-seg LED driver will give 64 LED control. up to 128kph, and you could leave the 130-160kph LED's not connected, or leave some of the lower not connected if you need more top end. The fewer driver chips the better I would have thought.

There are also a number of serial to parallel LED controllers which can control 32 LED's.

If using a dot rather than bargraph you could do the whole lot with a 28X2.
 
off the record I have had the old girl up to 145km/h (for comparison testing pre and post turbo install).....but yeah, 128km/h is really enough

I would be happy enough with DOT I think....
 

inglewoodpete

Senior Member
The method used will be up to you. With a digital input (Eg 2 or 3 magnets wired to a drive shaft and a logic-output Hall effect sensor, or a disk-and-photointerruptor) you can either count pulses over a period (command = Count....) or the period of a pulse (command = PulsIn).

It's a matter of doing the maths a working out what gives the best range and/or resolution. There are a hundred members here who are itching to give an opinion on some code, or even write it for you if you massage them the right way:)
 

inglewoodpete

Senior Member
this is the gearbox probe i plan to use. there isnt much info available but basically it runs on 5 volts and sends out pulses which increase as vehicle speeds up. i wont know the rate until i buy one and try it i think

http://www.revolutionracegear.com.au/index.php?PCID=10453&PSO=245&PSID=343103&PSV=Primary&CDO=
Don't you love it? "Click above image to enlarge" produces a smaller image in the popup!

I have to say I have no idea what that thing does, senses or outputs. I'll leave others to comment.
 

MartinM57

Moderator
It's called a "Japanese" sensor as all (most?) gearboxes in Japanese vehicles have the same thread fitting - which I can't recall at the moment.

It has three wires, +5v, GND and OUT. OUT pulses from 0v to 5v as the gearbox output shaft rotates.

The pulses relate to:
- distance travelled, if you count them
- speed, if you measure the time between the leading (or trailing) edges of two (or any n) pulses, (or the leading and trailing edge of one pulse)

The number of pulses per unit distance (km or miles) and the width of the pulses is specific to the gearbox it's fitted to and the sensor's internal design ...the car manufacturer and the sensor manufacturer know both, but you will have to find out by experimentation/calibration ;)
 
yeah, stupid website

i have a "manual" of sorts for it but it is really suposed to be used with a trip computer by the same manufacturer. it outputs a signal. my guess is that is will have either a photointerupter or hall effect setup inside it. however the manual stragely says that while testing (in your hand) it will produce a varying voltage from 0 to 0.45 when turned slowly. so i'm not sure if perhaps this would increase closer to 5 volts at full speed, meaning that it could basically be read as an analogue input with the readadc command.
(i had mistakenly said it outputs pulses before...oops, unless it does and the manual is just not technical enough)
 

Attachments

Last edited:
Martin,
Pulses-that is what I had first thought but then the troubleshooting part of the manual confused me a little. Pulses are good. Hopefully I can get an accurate result by using Count to count the number of pulses in half a second or something and calculate distance and speed. although wouldnt I lose track of distance given that I couldnt monitor (ie:Count) the pulses constantly since I would be needing to count them over some set duration and then perform calculations for speed?
 

MartinM57

Moderator
Probably more accurate to say that it produces a stream of highs and lows rather than "pulses" e.g. if not rotating, the output can be high or low depending on where it has stopped.

You would normally use edge-triggering on its output and have either:
- a background (reasonably high speed) timer that you read and zero on each (say rising) edge - to give time between pulses (turnable into speed) - with maybe some averaging since there might be jitter in the system which will have a noticeable effect
- a low speed timer (say 1 per second) and a running counter that you read and reset on each timer click - which can then be turned into speed also

Distance is just a matter of counting in your edge triggered interrupt and calculation
 

pyrogaz

Member
Sparkydave: May be of use to you, our calibration tests with the nominally -80A to +80A Devicecraft sensor suggest every 1 Amp is 4.83 ADC units when using 10-bit resolution. So more like a 100A sensor really!
 

Jaguarjoe

Senior Member
I don't know if the LR's speedo is similar to the one in my Jaguar, but at the very bottom of the speedo dial there is a number. This is the number of pulses per mile. I had one that was 760, the one I have now is 1000pulses/mile.

You could probably glue 4 or 8 magnets around the driveshaft and look at them with a simple Hall sensor.
 
Last edited:
the speedo does have a calibration marking on it. From memory (I wont be able to check for another week) it is X number of turns=60km or something similar. The only problem is I've had larger diameter wheels put on it and then had to have the speedo re calibrated to suit. (the marking is for the factory setup)
the good thing with the Japanese gearbox probe is that it can be used while still have the original speedo cable in place. this way I can have someone drive the car while I adjust PICAXE settings / debug to calibrate it.
With regards to the distance measurement, how should I go about keeping track of the number of pulses while still being able to take processor time to make calculations?? I would have thought that I would miss a lot of pulses while calculating / saving the result to a variable...
 
Top