Simple ebike 'fuel gauge'

Get all your technical information about electric bikes here.

Re: Simple ebike 'fuel gauge'

Postby Jeremy Harris » Tue Nov 23, 2010 2:48 am

otas wrote: I cannot quantify price at this stage, I am looking at an alternative to INA122, perhaps just an op-amp. and other ways to save money. With 10% display resolution it may be an overkill to use precission instrumentation amp. What do you think Jeremy?
otto



I only used the INA 122 because I had a few already, left over from another project. It was the only device I had to hand that worked on a single 5V rail, had a fairly low offset drift and had a common mode input range that includes the 0V rail. The latter point is important, as the voltages being sensed are only a few mV above 0V.

If you can find a cheaper device that will do this then I'm sure it'll work OK, as you say, you don't really need the precision (although be aware that Ah errors are cumulative, so you need a fair bit better than the display resolution).

Jeremy
Please ask questions on the forum, rather than by PM, as it helps others and you'll get a better range of answers.
User avatar
Jeremy Harris
10 GW
10 GW
 
Posts: 4635
Joined: Tue Oct 23, 2007 4:15 pm
Location: Salisbury, UK

Re: Simple ebike 'fuel gauge'

Postby fechter » Tue Nov 23, 2010 11:13 am

Jeremy Harris wrote:
otas wrote: I cannot quantify price at this stage, I am looking at an alternative to INA122, perhaps just an op-amp. and other ways to save money. With 10% display resolution it may be an overkill to use precission instrumentation amp. What do you think Jeremy?
otto



I only used the INA 122 because I had a few already, left over from another project. It was the only device I had to hand that worked on a single 5V rail, had a fairly low offset drift and had a common mode input range that includes the 0V rail. The latter point is important, as the voltages being sensed are only a few mV above 0V.

If you can find a cheaper device that will do this then I'm sure it'll work OK, as you say, you don't really need the precision (although be aware that Ah errors are cumulative, so you need a fair bit better than the display resolution).

Jeremy


Yikes! the INA122 is a spendy little bugger. Nice specs though.
I suspect you could use a much cheaper op amp like a LM358 and a trim pot to get the offset down to near zero. This would change the schematic a bit.
"One test is worth a thousand opinions"
User avatar
fechter
100 GW
100 GW
 
Posts: 9347
Joined: Sun Dec 31, 2006 3:23 pm
Location: California Bay Area, USA

Re: Simple ebike 'fuel gauge'

Postby otas » Tue Nov 23, 2010 11:33 am

fechter wrote:Yikes! the INA122 is a spendy little bugger. Nice specs though.
I suspect you could use a much cheaper op amp like a LM358 and a trim pot to get the offset down to near zero. This would change the schematic a bit.


Yup, I am looking at the CA3140 BIMOS op amp, works on a sigle rail and the input can go down to minus 0.5V. Too busy to sit at the breadboard to do it now. Watch this space...
otto
User avatar
otas
1 W
1 W
 
Posts: 50
Joined: Wed Nov 10, 2010 6:30 pm

Re: Simple ebike 'fuel gauge'

Postby NRG » Thu Nov 25, 2010 11:11 am

just wanted to post and say thank you to Jeremy, I've now tested the gauge and it seems to work. I just need to house it neatly and tidy the wiring up. I'm only drawing 21amps peak but the gauge correctly measured this giving a two thirds FSD reading. I haven't calibrated the shunt but I suppose I could measure use with my Watts Up and tweak the s/w setting for the shunt value so the gauge corresponds with a depleted battery....
NRG
10 mW
10 mW
 
Posts: 20
Joined: Mon Oct 26, 2009 12:29 pm

Re: Simple ebike 'fuel gauge'

Postby gwhy! » Thu Nov 25, 2010 12:53 pm

NRG wrote:just wanted to post and say thank you to Jeremy, I've now tested the gauge and it seems to work. I just need to house it neatly and tidy the wiring up. I'm only drawing 21amps peak but the gauge correctly measured this giving a two thirds FSD reading. I haven't calibrated the shunt but I suppose I could measure use with my Watts Up and tweak the s/w setting for the shunt value so the gauge corresponds with a depleted battery....


Very pleased to hear you have it working .. nice one.
User avatar
gwhy!
100 kW
100 kW
 
Posts: 1233
Joined: Tue Jan 13, 2009 8:32 am
Location: UK, Bristol

Re: Simple ebike 'fuel gauge'

Postby NRG » Mon Nov 29, 2010 3:27 am

Some pictures as promised, hopefully they may be of use to some. Fitting was tight in the controller, in hindsight I should have used smaller .25w resistors and also removed the DIL sockets to lower the height. I could have reduced the strip board size a touch as well...anyhow it works, so far it seems to be quite accurate (and above all very useful ;) ) but I've not run my 10Ah Turnigy pack fully down yet. For the PD in the gauge I've ended up with 58K (62K ¦¦ 1M) / 18K for FSD on the meter.

Board:

Image

Gauge:

Image

Image

Image

Fitted to controller, picked up the +5v, VBatt and 0v from convenient points on the PCB.

Image
NRG
10 mW
10 mW
 
Posts: 20
Joined: Mon Oct 26, 2009 12:29 pm

Re: Simple ebike 'fuel gauge'

Postby yopappamon » Mon Nov 29, 2010 7:01 pm

Great project! Thanks Jeremy.

Quick quesiton, the (-V in / current sense / +V in) connection, where are you picking that up? From the controller or are you adding a shunt?
User avatar
yopappamon
10 kW
10 kW
 
Posts: 771
Joined: Wed Mar 31, 2010 1:05 pm
Location: Most dangerous city in the USA, Flint, MI

Re: Simple ebike 'fuel gauge'

Postby spinningmagnets » Mon Nov 29, 2010 10:42 pm

NRG, thanks for the pics, but...you didn't make just ONE, did you?
User avatar
spinningmagnets
10 GW
10 GW
 
Posts: 4641
Joined: Fri Dec 21, 2007 10:27 pm
Location: Ft Riley, NE Kansas

Re: Simple ebike 'fuel gauge'

Postby Jeremy Harris » Tue Nov 30, 2010 2:37 am

Very nice work, NRG. Mine was pretty much the same size as yours, maybe a bit shorter, but was slimmer as I didn't bother with sockets. I made a small PCB (using the 'iron-on' laser toner method) for mine, which may have saved a few mm over a stripboard layout.

Spinningmagnets, the + and - current sense wires go to either side of the existing shunt on the controller, with the + lead going to the FET side and the - side going to the battery negative side. The existing code is set for a 5 mohm shunt, but the values can be changed pretty easily to suit any other value. You could just as easily use an external shunt, it would work just as well, but would introduce a tiny bit of extra loss into the system (only a couple of watts at 20A).

Jeremy
Please ask questions on the forum, rather than by PM, as it helps others and you'll get a better range of answers.
User avatar
Jeremy Harris
10 GW
10 GW
 
Posts: 4635
Joined: Tue Oct 23, 2007 4:15 pm
Location: Salisbury, UK

Re: Simple ebike 'fuel gauge'

Postby NRG » Tue Nov 30, 2010 12:02 pm

Thank you Jeremy!

spinningmagnets, sorry only the one...
NRG
10 mW
10 mW
 
Posts: 20
Joined: Mon Oct 26, 2009 12:29 pm

Re: Simple ebike 'fuel gauge'

Postby gwhy! » Thu Dec 02, 2010 6:03 am

Jeremy Harris wrote:
gwhy,

That display looks neat and has the overwhelming appeal of being much cheaper than the meter I used. The one thing to watch is that the low battery indication method I used (driving the meter into overload mode by applying more than 1V to it) may not work with the bargraph, so may need to be disabled or modified in the code. I like the idea of including the LVC warning in the meter.

Jeremy


I Have been thinking about a small mod in your code that will allow a led to be used for a LVC warning. I will have a play and report back. Basically use the calibration pulse to drive a led, Im not sure if it will fit into the 1sec time slot but it might be worth having a look. I have been playing around with the 18X as this can be overclocked 8) .
User avatar
gwhy!
100 kW
100 kW
 
Posts: 1233
Joined: Tue Jan 13, 2009 8:32 am
Location: UK, Bristol

Re: Simple ebike 'fuel gauge'

Postby Jeremy Harris » Thu Dec 02, 2010 6:55 am

Should work OK, gwhy, and has the advantage of not needing another pin. I did think of using the 14M to get a few more ports, but liked the challenge of fitting this into as small a space as possible, inside the controller. I'm not sure I could have managed to squeeze the bigger chip in.

There's another way to make a low battery warning, using the "bar display with alarm flasher" circuit in the National data sheet for the 3914. I think this should work in dot mode, if the capacitor and resistor (C1 and R1 in the figure) are connected to LED 1 instead of 10. What should then happen is that the last LED will flash on and off as a warning (I think, I've not tested it). It would have the side effect of flashing the last LED when the meter is reading a low current in current mode, which may be a snag.

Jeremy
Please ask questions on the forum, rather than by PM, as it helps others and you'll get a better range of answers.
User avatar
Jeremy Harris
10 GW
10 GW
 
Posts: 4635
Joined: Tue Oct 23, 2007 4:15 pm
Location: Salisbury, UK

Re: Simple ebike 'fuel gauge'

Postby gwhy! » Thu Dec 02, 2010 6:34 pm

I have just been reading about the 08M and this can also be over clocked to 8mhz !! how cool is that..

This is my mod'ed and re-vamped display.
new dot display.jpg
new dot display.jpg (57.92 KiB) Viewed 506 times


And this is the very nearly finished ( prototype) picaxe18x pcb to drive it.. I have moved some stuff around on the pcb and have now made it even slightly smaller. The meter will monitor battery voltage ( in 4 stages ) and also has a 2 stage low capacity led ( 20% and 10%) :
bat meter.jpg
bat meter.jpg (85.16 KiB) Viewed 509 times
User avatar
gwhy!
100 kW
100 kW
 
Posts: 1233
Joined: Tue Jan 13, 2009 8:32 am
Location: UK, Bristol

Re: Simple ebike 'fuel gauge'

Postby gwhy! » Sat Dec 04, 2010 9:36 am

Jeremy or NRG,
Did you have any problems with the current amp with saturation ?. It appears that the input needs to be biased to use on a single supply rail .. I have only just noticed this when I started to do some measurement testing with it.

Edit:
Scrap that... school boy error , I had the wrong chip in the socket :oops:
User avatar
gwhy!
100 kW
100 kW
 
Posts: 1233
Joined: Tue Jan 13, 2009 8:32 am
Location: UK, Bristol

Re: Simple ebike 'fuel gauge'

Postby gwhy! » Sun Dec 05, 2010 3:11 pm

Ok, Final, Final display for my meter ....
final design.jpg
final design.jpg (82.4 KiB) Viewed 453 times

rear.jpg
rear.jpg (119.9 KiB) Viewed 404 times

new meter.jpg
new meter.jpg (98.96 KiB) Viewed 404 times


Small vid of the whole meter Initialising :
User avatar
gwhy!
100 kW
100 kW
 
Posts: 1233
Joined: Tue Jan 13, 2009 8:32 am
Location: UK, Bristol

Re: Simple ebike 'fuel gauge'

Postby magudaman » Tue Dec 07, 2010 12:21 am

Oh no not another project I must start!!! Very Very cool, I was looking to do something similar my self since I was finding nothing on the market that could pull this off inexpensively. Thank you very much Jeremy for putting this up and sharing with everyone :D PS where did you get that rocker switch that is in the photo near your throttle in the first post?
Lightning Moto Prototype:
4100w BMC 2 Stage Reduction
16s2p Headway 10ah
70a Ecrazyman Custom
User avatar
magudaman
10 kW
10 kW
 
Posts: 759
Joined: Tue Jul 10, 2007 5:41 pm
Location: Bay Area, CA

Re: Simple ebike 'fuel gauge'

Postby yopappamon » Tue Dec 07, 2010 12:38 am

My meters were delivered today. A little smaller then I imagined.

You know if we moved this to an Arduino platform, added a gps and Bluetooth module and we can use a cell phone for a dash board.
User avatar
yopappamon
10 kW
10 kW
 
Posts: 771
Joined: Wed Mar 31, 2010 1:05 pm
Location: Most dangerous city in the USA, Flint, MI

Re: Simple ebike 'fuel gauge'

Postby Jeremy Harris » Tue Dec 07, 2010 3:04 am

magudaman wrote:Oh no not another project I must start!!! Very Very cool, I was looking to do something similar my self since I was finding nothing on the market that could pull this off inexpensively. Thank you very much Jeremy for putting this up and sharing with everyone :D PS where did you get that rocker switch that is in the photo near your throttle in the first post?


Thanks for the kind words.

The rocker switch came with the bike, it was an ebay buy, the details are in this thread: viewtopic.php?f=6&t=21945

I've seen similar switches on other ebikes, so I'm guessing that they are a generic Chinese part. I've not seen a supplier of them yet, though.

Jeremy
Please ask questions on the forum, rather than by PM, as it helps others and you'll get a better range of answers.
User avatar
Jeremy Harris
10 GW
10 GW
 
Posts: 4635
Joined: Tue Oct 23, 2007 4:15 pm
Location: Salisbury, UK

Re: Simple ebike 'fuel gauge'

Postby magudaman » Wed Dec 22, 2010 10:26 pm

Alright I have been working on my own version of this little circuit for the last week but have changed the code quite a bit to allow for up to 30ah packs and would be independent of the controller. I am using a hall effect open loop current sensor to give the current readings. I would really like to add an LCD display to just interpret serial and give a percent and a fullness gauge. Since I have ditched the voltage sense part of the circuit I do have an extra output line. Is this within the capabilities of the 08, I do see that it can only do 4800 baud out the serial connections and all the cheap lcd units I see only have 9600 baud.

I was thinking about dropping the average current sampling rate to 50 so I can save to eprom each round so users can shut down at any time. Is there enough time in a cycle for this in your experiences?

I see that you dump out a calibration pulse but how did you actually interpret that and calibrate your setup?

I am also trying to get a consistent 5v and picked up some linear regulators that are good from 20-125v. So far in testing them they are consuming about 1.3 watts while my 5v output is only needing 0.075w. Is there any more efficient way to get 5v at such low power levels?

Thanks Jeremy again for this great project!
Lightning Moto Prototype:
4100w BMC 2 Stage Reduction
16s2p Headway 10ah
70a Ecrazyman Custom
User avatar
magudaman
10 kW
10 kW
 
Posts: 759
Joined: Tue Jul 10, 2007 5:41 pm
Location: Bay Area, CA

Re: Simple ebike 'fuel gauge'

Postby Jeremy Harris » Thu Dec 23, 2010 2:55 am

magudaman wrote:Alright I have been working on my own version of this little circuit for the last week but have changed the code quite a bit to allow for up to 30ah packs and would be independent of the controller. I am using a hall effect open loop current sensor to give the current readings. I would really like to add an LCD display to just interpret serial and give a percent and a fullness gauge. Since I have ditched the voltage sense part of the circuit I do have an extra output line. Is this within the capabilities of the 08, I do see that it can only do 4800 baud out the serial connections and all the cheap lcd units I see only have 9600 baud.


The only two serial displays I've driven from this chip are the AXE003 from the Picaxe people and the Cat's Whisker Textstar display that's in this thread: viewtopic.php?f=2&t=14498 Both work OK from any output pin on the 08M, in my experience.

magudaman wrote:I was thinking about dropping the average current sampling rate to 50 so I can save to eprom each round so users can shut down at any time. Is there enough time in a cycle for this in your experiences?


I think it should work, the reason I only write to eeprom every power shutdown was just to limit the number of write cycles to it, but the reality is that it should last a long time even if writing to it once a second. There should be time for this, you just need to adjust the pause values (coarse adjustment inside the repeated measurement routine, fine adjustment in the loop) to get back to 1 second (or whatever value you choose to use) for correctly calculating remaining capacity. In practice the shutdown routine very reliably detects power off and saves data in plenty of time before the power supply dies. If you wanted to make it independent of the controller, then adding a bit of capacitance to the supply will hold it up for the very short time that the Picaxe needs to save and shut down.

magudaman wrote:I see that you dump out a calibration pulse but how did you actually interpret that and calibrate your setup?


I hooked mine up to a USB 'scope, looked at the calibration output pulse edges and adjusted the two pauses to get as close as I could to 1 second between them. I managed to get mine to 999.8mS, which was plenty good enough. You could do the same with a counter/timer hooked up to this pulse, or even set it very roughly with a LED on the output and a stop watch.

magudaman wrote:I am also trying to get a consistent 5v and picked up some linear regulators that are good from 20-125v. So far in testing them they are consuming about 1.3 watts while my 5v output is only needing 0.075w. Is there any more efficient way to get 5v at such low power levels?


What's really needed to do this efficiently is a switch mode regulator, but they are hard to find at these high input levels. LFP pointed out in the simple controller thread that there are some cell phone chargers around that do the job, maybe gutting one of these might get you what you're after. If you can cope with a lower input voltage, then I think johnrobholmes has some for sale.

Sounds like you're having fun with this, I look forward to seeing how it turns out.

Jeremy
Please ask questions on the forum, rather than by PM, as it helps others and you'll get a better range of answers.
User avatar
Jeremy Harris
10 GW
10 GW
 
Posts: 4635
Joined: Tue Oct 23, 2007 4:15 pm
Location: Salisbury, UK

Re: Simple ebike 'fuel gauge'

Postby texaspyro » Thu Dec 23, 2010 11:45 am

One thing that you should do to extend EEPROM life in micros is first read the EEPROM value and compare to what you want to write. If they are the same, don't bother writing it. Very simple, very obvious, and for some strange reason it is seldom done. I know of one commercial product was killing its micro in under a month because of this very issue.

Another useful thing to do is after reading or writing an EEPROM location or page, read an EEPROM page that is not used by your code (for several reasons the page starting at address 0 is usually best... i.e. some micros are know to corrupt this page). This will leave the EEPROM address pointer pointing to unused data. This will minimize the chance of useful data being corrupted during power cycles/glitches.
texaspyro
1 MW
1 MW
 
Posts: 1539
Joined: Wed May 12, 2010 6:53 pm

Re: Simple ebike 'fuel gauge'

Postby Jeremy Harris » Thu Dec 23, 2010 12:23 pm

texaspyro wrote:One thing that you should do to extend EEPROM life in micros is first read the EEPROM value and compare to what you want to write. If they are the same, don't bother writing it. Very simple, very obvious, and for some strange reason it is seldom done. I know of one commercial product was killing its micro in under a month because of this very issue.

Another useful thing to do is after reading or writing an EEPROM location or page, read an EEPROM page that is not used by your code (for several reasons the page starting at address 0 is usually best... i.e. some micros are know to corrupt this page). This will leave the EEPROM address pointer pointing to unused data. This will minimize the chance of useful data being corrupted during power cycles/glitches.


Good tips. It the obvious things like this that are so dead easy to miss. In my case it only writes to eeprom on a power loss event, where the value will almost certainly have changed since the last save, but it might still be worth doing the check I guess, as it doesn't take any headroom, that code is only run at power on.

For the "save every second" idea then it'd be a great saving in write cycles, because I bet that a lot of the time the bike is powered up it's not drawing any appreciable power (stopped at junctions, powered up but no moving while you get on/off etc or even just free wheeling down hill).

Jeremy
Please ask questions on the forum, rather than by PM, as it helps others and you'll get a better range of answers.
User avatar
Jeremy Harris
10 GW
10 GW
 
Posts: 4635
Joined: Tue Oct 23, 2007 4:15 pm
Location: Salisbury, UK

Re: Simple ebike 'fuel gauge'

Postby magudaman » Fri Dec 24, 2010 1:45 pm

I definitely am having fun with this stuff! It's pretty awesome learning how to code these little beasts and really seeing how powerful simple code like this can be. My mind starts to swirl with all the idea I can make possible so easily now with just simple programs.

Any how I did the math and saving each cycle doesn't seem like a good idea at all. It appears I would burn up my 100,000 writes in something like 27 hours?!?! SO, maybe I will go back to using your voltage line sensor on mine to do the saves and get that figured out.

I checked out that textstar LCD and that is a very cool module but they are quite pricey at about $45usd! They do save you from having to do the graphing code though which proves to be pretty darn nice. I just might have to pick one up. It would be pretty cool to be able to show a fuel gauge, percent remaining, and current with no display changing.

You mentioned the switch mode regulator and I cringed a bit since I know I am not able to build on my self and usually prove to be quite expensive if purchased in a DC-DC form (new that is). And since I wanted to keep the costs down for this project and keep the possibility of small scale production for members I thought that was out. But then I did remember I can get those switch mode Ipod supplies that measure about 24x24x24mm and provide up to 500ma at 5v for something like 3usd. I figured I would crack one open and hook it up to DC. Sure enough good to like 15v dc and seems to regulate pretty well to 5.34v just varying by 7 thousands. The unit seems to consume about .125w + the load so it sure beats the linear regulators

Here are a couple crappy photos:

Image

Image
Lightning Moto Prototype:
4100w BMC 2 Stage Reduction
16s2p Headway 10ah
70a Ecrazyman Custom
User avatar
magudaman
10 kW
10 kW
 
Posts: 759
Joined: Tue Jul 10, 2007 5:41 pm
Location: Bay Area, CA

Re: Simple ebike 'fuel gauge'

Postby BenMoore » Thu Jan 06, 2011 9:28 am

Regarding cheap and effective display options, could these units be employed?
Image
Price is about $9 (inc post):
http://cgi.ebay.com.au/Digital-Thermome ... 2367wt_918

Just cut off the sensor and feed it a (biased and scaled) analogue voltage?
The numerical display and scale (-10 to 80C or the F equivalent mode) wouldn't be so helpful, but could simply be masked to leave the 19 segment LCD dot graph.
Weather proofing would also be required.

BTW, I'm a long time fan of your work here on ES Jeremy!

- Ben
"If we knew what it was that we were doing, it wouldn't be called research would it?" - Einstein
eBike 1: Crystalyte 408/4012 in 20" rear, 72V LiPo, 20A controller on Trek Y dual suspension
eBike 2: Avanti Electra (axial flux motor) overvolted - very noisy!
eBike 3: 2kW RC motor with wye/delta switching (Turnigy SK6374-170, modded ecrazyman controller, 12S LiPo) - under construction...
BenMoore
10 mW
10 mW
 
Posts: 32
Joined: Thu May 07, 2009 12:25 am
Location: Melbourne, Australia

Re: Simple ebike 'fuel gauge'

Postby Jeremy Harris » Thu Jan 06, 2011 12:21 pm

BenMoore wrote:Regarding cheap and effective display options, could these units be employed?
Image
Price is about $9 (inc post):
http://cgi.ebay.com.au/Digital-Thermome ... 2367wt_918

Just cut off the sensor and feed it a (biased and scaled) analogue voltage?
The numerical display and scale (-10 to 80C or the F equivalent mode) wouldn't be so helpful, but could simply be masked to leave the 19 segment LCD dot graph.
Weather proofing would also be required.

BTW, I'm a long time fan of your work here on ES Jeremy!

- Ben


Thanks for the kind words, Ben.

To be honest, I'm not sure if those displays could be made to work or not. It'd be neat if they could, but it all depends on what sort of sensor they use to measure temperature. If the meter can be adapted to accept a voltage input, then the simple answer is yes, they could be made to work. I guess the answer would be to get one and experiment with it to see how it works.

Jeremy
Please ask questions on the forum, rather than by PM, as it helps others and you'll get a better range of answers.
User avatar
Jeremy Harris
10 GW
10 GW
 
Posts: 4635
Joined: Tue Oct 23, 2007 4:15 pm
Location: Salisbury, UK

PreviousNext

Return to E-Bike Technical

Who is online

Users browsing this forum: Bing [Bot] and 12 guests