Shop OBEX P1 Docs P2 Docs Learn Events
Saving data for later use - Auto odometer — Parallax Forums

Saving data for later use - Auto odometer

franklin9090franklin9090 Posts: 59
edited 2007-05-24 19:06 in BASIC Stamp
I am in the process of creating an electronic speedometer using a BS2, but I need to consider the odometer also. A speedometer is interactive and is only in use during driving, but an odometer needs to constantly store the miles driven(even when the ignition is turned off).

What type of memory medium is available for interfacing with the BS2 for this type of use?
And, how is the data stored when the power is turned off.

Thanks.
«13

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-13 20:22
    I have done this before in a complete restoration of a 1980 Pontiac Grand Prix with a dashboard that resembled the Knight Industries Two Thousand (KITT) from Knight Rider. This car showed the odometer on a small 1 line LCD Display. But I stored the data in an RTC chip from Dallas Semiconductor which had RAM and a battery backup. If I was doing the same thing today I would use the DS1302 since it has 31 bytes of RAM. An EEPROM would seem like a great thing but you can’t continuously update it or you will wear it our. Of course, if you only updated every mile it would work since the EEPROM would likely outlast the car. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-13 20:33
    Chris,
    It sounds like your setup is very similar to my objective.

    May I ask, what BS board did you use, etc?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-13 20:52
    Hello,

    That was in 1998/1999 just before I got into Parallax products…That system was built around a Z80 Controller. That’s why I mentioned if I had to do it again…In any event, the DS1302 would serve the same purpose, or you could write the data once per mile to a special odometer location in EEPROM. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-14 18:55
    Chris,
    I have looked into the DS1302 and was thinking, is this a bit overkill for my application? Since I am only looking to store the data, other than the 30K Ram, the logic in using this solution is unclear to me. Plus, this is RAM right? What happens when I turn off the ignition?

    Are there other solutions that would perform the same function and retain the data overtime?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-14 19:06
    franklin9090,
    The DS1302 is a clock that happens to have a little extra storage in it that's usable directly. You normally have a backup battery attached to the DS1302, usually a "coin" lithium battery that keeps the clock going when there's no other power and incidentally maintains the extra RAM. It's always nice to have a clock in a car and the DS1302 is pretty cheap, even with a 32KHz crystal, battery, and battery holder.

    You certainly can store your odometer reading in the Stamp's EEPROM with the READ/WRITE statements. This doesn't need a battery, but can only be changed a limited number of times (100,000 is a typical guaranteed minimum). The trick is to change it only when the value actually changes. Typically, you read the saved value using READ, compare it to the new value, and only WRITE it when the value has changed. I believe the PBasic manual discusses this in the section on the WRITE statement.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-14 20:22
    Franklin,

    The DS1302 may or may not be overkill for your application. I seem to find a use for it in most of my projects but that is me. That was why I mentioned you could write to the EEPROM once per mile and be okay just using it. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-15 15:41
    Mike- thanks for your feedback. I haven't seen an examples of how to attach a lithium battery to a DS1302, so you have any recommendations?

    Mike/Chris,
    You have to admit, keeping odometer readings is a bit of a hassle. If I use the EEPROM, eventually I will run out of "writes", if I use a lithium battery with a DS1302 and the battery dies I lose my mileage.... hmm.....

    I guess I am more used to PC technology, where I can write to a static medium, like a disk. Is this possible with a BS2?

    Or, maybe my solution is in using a combination of the EEPROM and the DS1302.... need to think about this one a bit.

    Any thoughts?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-15 16:47
    My choice would be to go the EEPROM route. You eliminate the issues surrounding changing the 1302's battery, but have to deal with the EEPROM's limited writes. There are two ways to handle the latter:

    1. Write the data to EEPROM only before an imminent power-down condition. The following circuit will detect a power-down before the power to the Stamp actually fails. You need to poll the "power good" input often enough to ensure that you catch a power-off and can write the EEPROM before the capacitor discharges below the Stamp's reset level, plus the dropout voltage of the Stamp's 5V regulator.

    attachment.php?attachmentid=45925

    2. Write the EEPROM on changes only, but use "wear-leveling" to minimize the maximium number of writes to any given location. For example, if you were to store each digit in its own byte, the "ones-digit" byte would get hammered 100,000 times in 100,000 miles, but the "hundreds digit" would get written only 1000 times. With wear leveling the mileage data are encoded in such a way that each digit gets written at nearly the same rate. Some sort of Gray coding may be the answer here. (This is assuming that EEPROM bytes are written individually. In some EEPROMs, an entire page may be read and rewritten with each write.)

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 3/15/2007 4:58:39 PM GMT
    374 x 273 - 2K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-15 20:25
    Regarding the EEPROM Write limitation...It ocured to me after I posted (and I mentioned it above)...If you wrote a new value every mile you would have to drive 1 million miles or more to destroy the EEPROM location...I don't think that's going to be a problem. =)

    [noparse][[/noparse]Edit] - If you update every 10th of a mile you would only get 100,000 writes...That is always a possibility...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-16 02:12
    Phil.
    Thanks for the detailed explanation and the circuit. There was concern about having to smooth my power source in the automobile feeding the BS, so as not to damage my BS. Would this circuit provide that kind of power smoothing?

    Also, your explanation on #2 was very detailed and easy to understand. I am not sure if I can attain the Gray coding or if the BS requires it, I will definitely keep it in mind.

    I like the idea of only writing to the EEPROM upon shutdown (power loss).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-16 02:27
    franklin9090 said...
    There was concern about having to smooth my power source in the automobile feeding the BS, so as not to damage my BS. Would this circuit provide that kind of power smoothing?
    Yes to the "smoothing", but I'd be inclined to throw in an intermediate voltage regulator — say an 8V LM2940 — between the 1000uF cap and the Stamp, with a 22uF tantalum on its output. The '2940 will not only protect the Stamp from reverse battery situations, but will help to keep the Stamp's onboard regulator from overheating.

    -Phil
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-16 02:52
    Phil,
    I googled a 22uF tantalum (I didn't know what they were) and noticed that they are another type of capacitor. They seem to be rated by voltage i.e. cap 22uF tantalum 16V. Am I correct in my assumption and how do I determine which "v" version is right for me?

    Thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-16 03:03
    They are a type of electrolytic capacitor and the V is the maximum voltage they can have across them without damaging them. Usually on a regulated output, the voltage is not supposed to rise significantly above the rated output voltage of the regulator, but it can happen ... There's another thread discussing regulator instability with the Propeller Education Kit. A 16V tantalum should be an excellent choice for an 8V regulator output filter.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-16 03:05
    All caps have a voltage rating. Pick a rating that's at least twice the expected voltage on the cap.

    -Phil
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-16 14:30
    Mike/Phil,
    Thanks for the information on capacitor voltage. Does that mean that the 1000uF and .1uf caps in Phil's schematic should be at 24V (twice the automobile's input)?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-16 15:20
    I would use 35V capacitors myself, although the next standard voltage downward is 25V. I have seen automotive electrical systems reach 14.5V during normal operation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-17 17:15
    Chris,
    Thanks for the feedback on the 35V capacitors; that sounds like the way to go.

    I started to look at coming up with a list of parts (I would like to put in one order to save shipping costs) , but I ran into another snag. I looked on digikey.com for 1000uF 35V capacitors and they had all kinds(aluminun, electronic, etc.), and this was only the first vendor I went to. How is a novice to know, which one to choose?

    Also, I am going to try to take Phil's approach above, but doesn't that mean that I would have to construct an electronic circuit to monitor and regulate the power BEFORE it gets to the Super Carrier Board? I was over at RadioShack and they had some blank circuit boards with holes and copper plating on one side. Although I have some novice level electronics experience and have put kits together before, I have not had to create a circuit from scratch.... I guess there is always a first.

    Anyone have any links or tips on how to get up to speed.... Of course, this problem also relates to the Super Carrier Board that has through-holes in one corner ( I am not sure how to utilize them). I wish I had some examples or some simple how-to's....

    Any help you guys can provide would be much appreciated.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-17 17:24
    Generally the aluminum ones are cheaper. The tantalums have specific advantages in certain types of circuits and extreme temperature ranges (they were developed for space use). Pick one that will fit into the box you want to use. Use the radial lead version if you're going to put it on a printed circuit board..

    Lay out the circuit on graph paper using the actual components as templates. If it's easy, arrange the components so their own leads can be used to connect them on the underside of the board. Use individual wires (usually solid hookup wire) to make other connections. Use stranded wire to make connections off board (whenever there can be any mechanical movement). Look at some of the electronics hobbist magazines for examples and suggestions for construction. You might start with some simple projects from one of those.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-17 17:31
    Franklin,

    Electrolytic capacitors are what you need for the larger units. These come in both Radial and Axial lead styles, which just means the leads either come out of the same end or out of opposite ends, respectively. The .1uF capacitors are ceramic disc and most are rated to at least 50V. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-17 20:18
    Chris,
    Ok, I'll use electrolytic for the larger capacitors and ceramic for the ones in the .1uF range.

    Phil mentioned using a 22uF "tantalum" as part of smoothing the power. Is that another kind of capacitor?
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-17 20:19
    Chris,
    One other thing, should I "heat sink" the LM2940? Does it need it?
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-17 20:25
    oops... sorry guys, I didn't see Mike's response to my "tantalum" question...ignore my last post. Thanks.

    Mike,
    Thanks for the circuit board tips, I really need to brush-up on the subject. As I said before, I have assembled kits in the past, but they have always had a circuit board with them. This particular project is different, of course.

    On the solid hook-up wire and the stranded wire, where do I get those and what gauge?

    Thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-17 21:33
    Hookup wire ... Radio Shack is fine. I usually use 24G in different colors. I also use wire-wrap wire which is thinner and has tougher insulation. You really need a proper stripper for wire-wrap wire if you're going to use it.

    To heat-sink or not ... It depends on how much current you need for your circuitry. Get the datasheet for the regulator and look at the charts at the back. There'll be one for heat dissipation. It'll tell you how good a heatsink you need based on power to be dissipated (voltage drop x current flow) and ambient temperature. Mostly it'll tell you how much the regulator can handle without an external heatsink.

    Post Edited (Mike Green) : 3/17/2007 9:38:45 PM GMT
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-18 15:23
    Mike,
    I was looking at the datasheet for an LM2940 and realized I need to need to calculate the power dissipation (Pd) with some formulas. There were two:

    Iin = Il / Ig
    Pd = (Vin - Vout)Il +VinIg

    I wasn't sure how to determine the I values....
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-18 15:34
    Phil,
    You said that with your circuit above, you would probably put an 8V LM2940 between the 1000uF cap and the BS.
    Are you recommending an 8V regulator to dissipate some of the heat and to let the regulator on the BS to perform the 8V to 5v smoothing?

    Do I need to do anything to the "Power 'good' signal" output to the BS pin(I am assuming that the output is going to a pin)?

    Would installing the LM2940 at the point of input (12V) a purdent thing to consider? I'm thinking my circuit is not protected at this point, is it? Or, does it matter? And, if it is installed at the point of input, how does it change the circuit?
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-19 03:31
    Mike,
    I took another look at the charts and it looks like, if the ambient temperature is less than 90C or 194F, a heat sink is not needed (which is most likely my case). Is this correct?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-19 04:12
    franklin9090,
    I don't know. You'll find out. The regulator will just shut itself off to prevent overheating. If you find that happening, just try a small heatsink. Make sure to use some thermal conductive paste.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-19 06:43
    franklin9090 said...
    You said that with your circuit above, you would probably put an 8V LM2940 between the 1000uF cap and the BS.
    Are you recommending an 8V regulator to dissipate some of the heat and to let the regulator on the BS to perform the 8V to 5v smoothing?

    Yes. Going from 12V to 5V on-Stamp is asking a lot of that tiny 5V regulator. It should also help to keep any alternator noise at bay.

    Do I need to do anything to the "Power 'good' signal" output to the BS pin(I am assuming that the output is going to a pin)?

    No. Just connect it to a pin. But test it before you do to make sure the 4.7V zener diode is doing its job!

    Would installing the LM2940 at the point of input (12V) a purdent thing to consider? I'm thinking my circuit is not protected at this point, is it? Or, does it matter? And, if it is installed at the point of input, how does it change the circuit?

    'Not sure what you mean by "point of input". I'd put the LM2940 near the BAISC Stamp. It's always best to regulate near the load if you can. Besides, you're tapping the "power good" signal ahead of the '2940, so you want it close to the Stamp anyway.
    -Phil
  • franklin9090franklin9090 Posts: 59
    edited 2007-03-20 16:10
    Phil,
    Thanks for your feedback, always appreciated.

    On the zener diode, should I be testing for the zener current? Anything particular I need to be looking for?

    I am still grappling with how best to construct the circuit board. I think Mike's idea of using the leads off the components and laying it out on paper are good, but ultimately, I think I need to get the components on to a breadboard of some kind.
    I am trying to avoid the ferrite cl. route, seems to messy and don't seem to be able to source a small quantity.

    I tried my local library last night for magazines on electronics; I was shocked, they didn't have any.

    Any recommendations?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-20 16:27
    franlkin9090 said...
    On the zener diode, should I be testing for the zener current? Anything particular I need to be looking for?

    Just make sure the output voltage saturates at 4.7V before connecting it to the BASIC Stamp.

    -Phil
Sign In or Register to comment.