Shop OBEX P1 Docs P2 Docs Learn Events
Making A Trip Odometer — Parallax Forums

Making A Trip Odometer

G McMurryG McMurry Posts: 134
edited 2009-10-07 17:18 in BASIC Stamp
I am using the Basic Stamp BS2P24 to control a large scale gas/electric locomotive. The last feature I put installed was a speedometer. I have just enough time to use the COUNT function to accurately give me a speed in MPH. My Locomotive is 1/8 scale. Speeds vary from 0 to 10 mph. Any faster.... Not really.

I probably have the most accurate speedometer in the hobby with my Basic Stamp. I have steel wheels, 5 inches in diameter that are connected by a 2:1 gear reduction to a 36 tooth pulley. I have a Cherry Gear Tooth Sensor that gives me nice pulses that I sample and compute MPH. I love it...

It occurs to me that making a trip odometer or just about any type odometer is not so easy. I am already going out to the COUNT function for 40 ms and that works fine for the speedometer. My STAMP has other stuff to do...

I am operating 2 hobby servos, one for the Throttle and one for the choke. I am also doing a PWM that is converted to analog to operate the air brakes. Not a lot of time left for even the BS2P24. My servos can just tolorate that 40ms wait. They are much happier at 20ms updates.

Anyone have any good ideas for keeping track of miles traveled as a trip meter or odometer would do. Especially good would be something that would use the COUNT numbers I am already acquiring.

I would love to have the EEPROM store the info but with the 100,000 cycle limitation on the BS2P24 that doesn't seem practical. I could just upload the count every 10 minutes and probably get something close but I am thinking that there is a better idea out there.

Greg

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
AUTOMATE EVERYTHING
http://www.trainyard.net

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2009-09-21 10:22
    G McMurry said...
    I would love to have the EEPROM store the info but with the 100,000 cycle limitation on the BS2P24 that doesn't seem practical.
    If that's all that's stopping you, use an external EEPROM in a socket. If it goes bad, replace it with a new one for under $2.
  • dev/nulldev/null Posts: 381
    edited 2009-09-21 14:26
    Or use F-RAM:
    http://forums.parallax.com/showthread.php?p=842331

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Larry~Larry~ Posts: 242
    edited 2009-09-21 14:51
    You keep your value in a VAR and only write to it on shutdown, you read it on startup and keep it in your VAR
    so if you run 20 times a day it will be 13.69 years before there is a problem
    now if you write to 5 different locations (new one each shutdown) instead of just one spot then it's even longer.
    is there anything on this rig that you expect to last 13 years (includes you)??
  • RiJoRiRiJoRi Posts: 157
    edited 2009-09-21 15:34
    Ignoring things like the wheels slipping, etc., you go PI*d inches (about 31.4") every rotation (or 36 pules). There are 63,360 inches in a mile (5,280*12), and so 2,017.83... (63360/31.4) rotations in a mile. 0.83... *36 = 30, so there are 2,017 full rotations + 30 teeth per mile. Working it backwards, there are 72,642 pulses per mile.

    You may not want such insane accuracy. "Yes, I've traveled 141,578 inches today!" In that case, use a second gear counter, which will reset every 7,264 pulses. When it resets, it also increments the tenth-mile counter. You may also want another counter to correct for the missing 0.2 counts. Increment the tenth-mile counter every fifth update.

    There definitely are rounding errors in the numbers I've used. Go for all the precision you want, and good luck!

    --Rich
  • Larry~Larry~ Posts: 242
    edited 2009-09-21 16:45
    There was a thread just a couple of months ago on speedo and odom with some program hints
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-09-21 17:45
    Greg,

    It just happens that I have been discussing this very thing in a private thread with another individual from the forums. In order to get accurate odometry you cannot miss any incoming pulses. It is for this reason that in my original Z80-powered car computer from the nineties that I used a CTC chip. Incoming pulses were sent to the chip and it was read at specific intervals. This gave me both accurate odometer and speedometer readings. Since the BASIC Stamp does not have an internal counter and cannot process pulses while running other commands you will also need either an external counter or a co-processor such as an SX designed to do the same thing. For a revisit of the project I am instead going to use a Propeller chip. Also, you definitely don’t want to write to the EEPROM continuously. Instead consider some sort of battery-backed RAM or the suggested FRAM. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • G McMurryG McMurry Posts: 134
    edited 2009-09-23 05:45
    Thanks everyone for the well considered replies. I can see my instinct was correct. I would like to look into counter timer chips, I have never used one. I also can see this might cause me to experiment with some sort of on board battery. I like that idea. Something new to tinker with.

    Chris -- I have done many counter designs with Z80s, though it was decades ago. NMI is a great counter input. You are reminding me how old I am...

    I am also not familiar with FRAM. I found another thread that mentions the FM24C16A. Think this is a good part for me to start with in a new design?

    I am not using surface mount yet. Maybe this will force me to make the jump.

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net

    Post Edited (G McMurry) : 9/23/2009 5:56:45 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-09-24 16:18
    Greg,

    I was trying to remember exactly what I did back then and I believe I used an external CTC chip…it may have even been a Zilog chip designed for the Z80. It’s been a long time (yeah, age is setting in). I know I didn’t use the NMI line because that was connected to a 60 Hz source in all my designs to run an internal software RTC and to update certain specialized registers. In fact, I only used the IRQ input when an external chip used it. What I do remember is that I had at least a 16-bit CTC running and I remember that at max speed it would not roll over before I could read and reset it.

    I have a design coming up where I need a similar system and I will be using the Propeller, but if I was tied to a BASIC Stamp design it could be easily done using an SX or PIC or any cheap microcontroller with an internal counter. The concept is that you want the chips counter to be able to continue counting pulses while the last known data is being read. A PIC or SX design would (upon a read) copy the current count into another register, reset the CTC and then continue sending the data to the host MCU. I hope this helps. As usual, it won’t help you now, but once my system is completed I will be posting it on my project site as well as the forums here. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • stamptrolstamptrol Posts: 1,731
    edited 2009-09-24 16:46
    Hi guys,

    The external counter method is very reliable. One of my projects used 2 Stamps on board. One would run the control program and the second did nothing but count pulses and wait to be queried by the main controller. When triggered by the main controller, it would blast out (SEROUT) its current count and reset to zero.

    Some might call it a bit expensive, but in my case it meant only 1 spare chip in a fleet of 800 units and no learning curve.

    A second application was the log processor shown in my ID panel to the left. It used a Stamp to do the digital i/o and a commercially available industrial counter for the log positioning. For each log length, the Stamp changed the settings on the counter by a serial link and reset the counter after each log was cut.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • G McMurryG McMurry Posts: 134
    edited 2009-10-07 02:52
    Greetings...

    I am back on this project.. I would love some advice on picking a counter/timer that would be good for use with a Basic Stamp. The only devices I have ever used was over 20 years ago. There must be something out there..

    Any advice would be appreciated.

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-07 12:00
    ·Start with a simple counter chip like a 4024 or even 4017. Run them at 5 volts for compatibility with the Stamp.

    · That will let you get a feel for how they work and if they'll·do in your application.

    ·Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • G McMurryG McMurry Posts: 134
    edited 2009-10-07 14:37
    I was hoping for something with a serial read. Isn't there something designed for use on a micro that is small?

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-07 17:18
    ·· As I alluded to in a prior post, the simplest way to get a serial controlled counter is to use another Stamp as the counter.

    ·· The extra cost in hardware will be saved in ease of programming.

    ··· If you jumped to the Propellor you'd have lots of power to do the whole controller in one chip at the expense of learning a different (but similar)programming language.

    ·· Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
Sign In or Register to comment.