Shop OBEX P1 Docs P2 Docs Learn Events
Bicyle Speedometer Project — Parallax Forums

Bicyle Speedometer Project

luong45luong45 Posts: 8
edited 2005-05-06 21:48 in Learn with BlocklyProp
I'm working on a senior design project building a bicycle speedometer. I'm using a Reed switch to produce the input signal.· How would i go about processing this signal to the BS2-BOE·and measuring the time between pulses? Would i need an oscillator or a clock before the signal is being input into the BS2-BOE? Thanks in advance.

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2005-02-24 20:26
    Best way I feel would be to use the COUNT command to count the number of pulses in a given period of time, and from their work your math to convert to velocity.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel

    Electronic Systems Technologies
    Southern Illinois University Carbondale
    Personal Links - ·Lot of BASIC Stamp info
    and
    SelmaWare Solutions
    StampPlot Pro Version 3 Release 4
    Graphical Data Acquisition for your Micro and Imagination!
    Now allows additional controls to be added, or developed.
    ·
  • luong45luong45 Posts: 8
    edited 2005-02-28 22:50
    I also wanted to know what would be the best way to output a 4 digit 7-segment LED? I'm thinking of using a 2-to-4 multiplexer. Do I need a driver or can i·display it straight from the BS2?
  • GadgetmanGadgetman Posts: 2,436
    edited 2005-02-28 23:31
    You should definitely use a driver, yes.
    4 8bit latchingdrivers and a 2-to-4 decoder should do the trick

    You might want a Shcmitt trigger or something on the input signal (a 74HC14 worked OK for me when I built something similar)

    The problem with building something like this is that you need a reliable timebase.
    (I built mine with an old PDA where I could be certain about when exactly one second had passed)

    You may want to look up chips that can be used for timing. Watchdog-timers, counters and such.

    You can see my project here:
    http://home.c2i.net/trygveh/english/download/org2/t2bike.html

    It also includes the complete sourcecode, and while it's not in PBasic, it might help show how it can be done.

    Note, in my version I send the input signal into an 8bit counter and just checks that once every second so my computer could use the time to do all kinds of nifty things (like a 'last minute average speed' and so on)
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2005-03-01 01:17
    While the 7-Segments are a great learning experience, I would seriously consider spending some bucks and getting a serial LCD from Parallax.· Well worth the grief and battery suckage.

    My 2-cents.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel

    Electronic Systems Technologies
    Southern Illinois University Carbondale
    Personal Links - ·Lot of BASIC Stamp info
    and
    SelmaWare Solutions
    StampPlot Pro Version 3 Release 4
    Graphical Data Acquisition for your Micro and Imagination!
    Now allows additional controls to be added, or developed.
    ·
  • luong45luong45 Posts: 8
    edited 2005-03-08 22:38
    I am currently in the testing stage. I want to write a program that will light up an LED everytime a magnet passes through the Reed switch, which will go from 5 volts to approximately 3 volts which corresponds to binary-1 and binary-0. so far this is what i have and it doesn't work.

    note: i'm designating pin 0 as the input and pin 1 as the LED output

    Main:
    IF (PIN 0 LOW) THEN
    HIGH 1
    ELSE
    LOW 1
    ENDIF
    GOTO Main
    END
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-03-08 22:47
    The problem is that you need to get the voltage below 1.6vdc for it to be considered low. I don't know how to do that, but perhaps one of the others will offer a suggestion.

    Jim
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2005-03-08 23:51
    A simple resistor voltage divider should work. You could use two resistors of the same value, or skew it a bit with slightly different
    valued resistors.


    
                        4.7K         3.3K 
    3-5 Volt input >----/\/\----o----/\/\----> GND
                                |
                                o------------> I/O pin
    
    
    If the input is 3V then the I/O pin "sees" about  1.24V
    If the input is 5V then the I/O pin "sees" about  2.06V
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe - Mask Designer III

    National Semiconductor Corporation
    (Communication Interface Division)
    500 Pinnacle Court, Suite 525
    Mail Stop GA1
    Norcross,GA 30071
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-03-10 01:03
    Beau,

    Would there be a way of doing it that expanded the range? 2.06 - 1.6 leaves only 0.46vdc between a high and perceived low. It wouldn't take much in the way of noise to create false readings. What about using a comparator like proposed by KenM in the thread http://forums.parallax.com/showthread.php?p=528895. You could reverse the +/- connections to generate the desired logic.

    Jim
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2005-03-10 06:40
    I suppose you could do it with 4 or 5 diodes in series, assuming each diode had a voltage
    drop of about .6V. That way you would have close to 0v and 2V.

                                 10K
    3V-5V >-->|-->|-->|-->|--o--/\/\--> GND
                             |   
                             0--------> I/O pin
    
    
    If the input is 3V then the I/O pin "sees" about  0.6V
    If the input is 5V then the I/O pin "sees" about  2.6V
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe - Mask Designer III

    National Semiconductor Corporation
    (Communication Interface Division)
    500 Pinnacle Court, Suite 525
    Mail Stop GA1
    Norcross,GA 30071
  • upand_at_themupand_at_them Posts: 61
    edited 2005-03-10 14:45
    Why wouldn't he just have a pulldown on the I/O pin to ground and put the reed switch between the I/O pin and 5V?· Then it would be...switch on: 5V, switch off: 0V.

    Mike
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2005-03-10 16:11
    both of you said...

    luong45 said...

    I am currently in the testing stage. I want to write a program that will light up an LED everytime a magnet passes through the Reed switch, which will go from 5 volts to approximately 3 volts which corresponds to binary-1 and binary-0. so far this is what i have and it doesn't work.
    Mike said...

    Why wouldn't he just have a pulldown on the I/O pin to ground and put the reed switch between the I/O pin and 5V? Then it would be...switch on: 5V, switch off: 0V.


    Mike, this would be fine, but luong45's current setup for whatever reason goes form 3V to 5V....not 0V to 5V.

    I did not question the 3V and 5V output, but perhaps we should ask luong45 why 3V is being generated in a LOW
    condition rather than 0V. It does seem a little odd now that you mention it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe - Mask Designer III

    National Semiconductor Corporation
    (Communication Interface Division)
    500 Pinnacle Court, Suite 525
    Mail Stop GA1
    Norcross,GA 30071
  • upand_at_themupand_at_them Posts: 61
    edited 2005-03-10 17:34
    I think he's confused about what he's trying to do.· He wants one of these, we're just not sure which:



    1) An LED at the switch to indicate switch status.· Stamp not used.

    2) An LED at the Stamp, where the Stamp reads the switch status and lights the LED.

    3) Both.



    There is no voltage drop across the switch so he should only have 0V and 5V conditions.



    -Mike
  • luong45luong45 Posts: 8
    edited 2005-03-10 23:16
    Thanks for all the input. We were able to get the bs2 to count RPM. We have the Reed switch setup according to Mike's specifications. I/O pulling down to ground. We were able to get RPM to display but during the conversion to MPH, it would display zero. This is what we have so far:

    counts VAR Word
    RPM VAR Word
    counts = 0

    DO
    COUNT 0,1000,counts
    RPM = counts * 60
    MPH = RPM * 88 * 60 / 63360
    DEBUG DEC? RPM
    DEBUG DEC? MPH
    LOOP

    note: 88 = circumference of the wheel in inches
    60 = mins per hour
    63360 = inches per mile

    we think it might be a syntax error but we're not sure.

    Thanks in advance, i appreciate all the help and suggestions
  • upand_at_themupand_at_them Posts: 61
    edited 2005-03-11 02:37
    Always try to simplify math expressions.

    This expression: (RPM * 88 * 60) / 63360

    is the same thing as this: RPM / 12

    -Mike
  • luong45luong45 Posts: 8
    edited 2005-05-03 23:25
    update on the bicycle speedometer...
    I decided to still use the count function however, with the use of an external oscillator, and a T-flip flop, it will count the number of pulses from the oscillator. The number of pulses counted will then correspond to a certain speed. also, i orderd a serial lcd and that will be used for the output.

    I have a question about how i would program a subroutine to calculate total miles. since there is that limitation on integer math only, i'm not sure how i would go about writing this portion of hte program? I'm thinking of using a counter (not COUNT function) to increment everytime a magnet passes through the Reed switch. Since it would take awhile before you would reach a whole integer, say 1 mile or 2 mile and so forth, what about inbetween? i was hoping to display .2 or .3 of a mile. Thanks in advance.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-05-04 03:53
    one revolution of the wheel is 1/720th of a mile, so there are 720 pulses per mile or 72 per 1/10th mile. By keeping a variable which keeps track of the multiples of 72 pulses gives you how many tenths of a mile have been traversed. The other thing you need to do is carry the fraction of 72 pulses to the next count, this is done with the modulus operator //. Then you add the fraction in with the count before computing the next update to tenthmile.

    counts VAR Word
    tenthmile VAR Word
    countremain VAR Word
    RPM VAR Word
    counts = 0
    countremain = 0
    tenthmile = 0

    DO
    COUNT 0,1000,counts
    countremain = countremain + counts
    tenthmile = tenthmile + (countremain/72)
    countremain = countremain // 72
    RPM = counts * 60
    MPH = RPM /12
    DEBUG DEC? RPM
    DEBUG DEC? MPH
    LOOP

    WRT to your MPH issue, the equation for MPH given your wheel is 5/s where s is the time between pulses in seconds. This is gotten from calculating a bycicle going 1 mile/hour would have 720 pulses/hour or .2 pulses/second or 5 seconds between pulses.

    The problem with using count with a 1 sec timeframe, any speed less than 5 mi/hr possible could show 0 mi/hr since a pulse may not have been captured, and speeds higher than that will have a large amount of error since 10 mi/hr means 2 pulses/timeframe,·3 pulses/timeframe is 15 mi/hr, there is no way with your code to measure speeds between 11 and 14 mi/hr, they'll all read as 10 mi/hr. To get more accurate results you should measure the time between pulse and calculate the value using the above equation, you can get away with multiplying a fraction by using the multiply middle operator */. But PULSIN cannot measure that long of a period, however you can subdivide the time period by running consecutive PULSIN commands until a value other than 0 is returned, the equation for time between pulses in microseconds is

    (PULSIN overflows)*13,107 + (Last PULSIN*2)

    you can keep a counts variable by incrementing it each time a pulse is received.

    Post Edited (Paul Baker) : 5/4/2005 3:57:14 AM GMT
  • MacGeek117MacGeek117 Posts: 747
    edited 2005-05-05 02:18
    just use this circuit.

    bugg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Boe-bot: $229


    Toddler: $249

    Learning Google is your friend: priceless
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-05 02:20
    Bugg,

    ·· That's not a good example circuit, since when the reed switch closes, it will effectively SHORT the Vdd and Vss rails.· You would need a resistor inline between the Vdd and the input pin, since currently the input is always going to read high, and when the switch closes the Stamp will most likely reset due to brownout.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-05-05 03:43
    luong45, I reread the first paragraph of your last post. I dont completely understand your description of your external circuit, can you post a schematic?

    Unless you need to do some "background processing" of data on the stamp, using an external circuit is not nescessary, using the PULSIN method I described you can aquire extremely precise data to use. Your measuring time between pulses that at thier shortest are maybe 1/8 a second apart (40 mph) in microseconds! Thats roughly 5 significant figures of precision. Thats knowing your speed down to 1/1000th of a mph (and mileage down to the inch, though thats updated in 88 inch increments).
  • GadgetmanGadgetman Posts: 2,436
    edited 2005-05-05 08:19
    Paul Baker said...
    one revolution of the wheel is 1/720th of a mile, so there are 720 pulses per mile or 72 per 1/10th mile. By keeping a variable which keeps track of the multiples of 72 pulses gives you how many tenths of a mile have been traversed. The other thing you need to do is carry the fraction of 72 pulses to the next count, this is done with the modulus operator //. Then you add the fraction in with the count before computing the next update to tenthmile.

    If there's something I know, it's that not all wheels are created equal.
    I use 26" rims on my bicycle, but I can assure you that the circumference of the 1.75" tires I use in the summer is not the same as the 2.1" tires I use in the winter.
  • steve_bsteve_b Posts: 1,563
    edited 2005-05-05 20:05
    And if you eat too many donuts you'll find that your tires squash while on it, thereby reducing your circumference as well!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://ca.geocities.com/steve.brady@rogers.com/index.html
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • MacGeek117MacGeek117 Posts: 747
    edited 2005-05-06 01:13
    Sorry about that , Chris. Oops! Here is a revised circuit.

    bugg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Boe-bot: $229


    Toddler: $249

    Learning Google is your friend: priceless
  • luong45luong45 Posts: 8
    edited 2005-05-06 02:29
    Hi, thanks for all the input. Here is a schematic of the project so far.
    727 x 498 - 30K
  • KenMKenM Posts: 657
    edited 2005-05-06 02:34
    luong,

    What is the purpose of the 4024 into the AND gate?
  • luong45luong45 Posts: 8
    edited 2005-05-06 03:28
    The 4024 reduces the oscillator to a lower frequency (256Hz) so that the COUNT function on the BS2 won't be counting as many peaks. The purpose of the AND gate is that the output will be high only if both inputs are high. therefore based on the drawing, when the magnet passes the reed switch, Tflip flop will be high. The AND gate will start outputting, then when the magnet passes again, the T flip flop goes to low meaning the AND will not be outputting. the pulse train's lenth will be the length the T flip flop is high. The BS2 will then count the number of peaks. dont know if this makes any sense? but i've constructed it and it works.
  • luong45luong45 Posts: 8
    edited 2005-05-06 03:29
    The 4024 reduces the oscillator to a lower frequency (256Hz) so that the COUNT function on the BS2 won't be counting as many peaks. The purpose of the AND gate is that the output will be high only if both inputs are high. therefore based on the drawing, when the magnet passes the reed switch, Tflip flop will be high. The AND gate will start outputting, then when the magnet passes again, the T flip flop goes to low meaning the AND will not be outputting. the pulse train's lenth will be the length the T flip flop is high. The BS2 will then count the number of peaks. dont know if this makes any sense? but i've constructed it and it works.
    640 x 400 - 9K
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-05-06 21:48
    Yes your circuit works, its bit of an overkill, but its working, so I don't suggest changing it. As you have figured it generate a pulse train·every other rotation of the tire. The time base resolution is 4 ms.

    Have you thought of how to perform the COUNT to make sure you have captured the pulses of a single wheel rotation without bleeding into the next train over the entire range of speeds? For a bicycle traveling 1 mph, the wheel rotates once every 5 seconds, meaning the pulse train is 5 seconds long followed by 5 seconds of deadtime. To accurately measure this speed, your count duration needs to be at least 5 seconds and less than 10 seconds. For a bicycle traveling 40 mph (likely traveling downhill) the pulse train lasts for 1/8th of a second, if you used the same 5 second duration to count the wheel, you would be capturing 40 wheel rotations or 20 pulse trains, if you tried to calculate this using the number of pulses counted over the 5 seconds you would calculate a speed of 2 mph since the number of pulses generated by 2.5 seconds on, 2.5 seconds off is the same as the number of pulses generated by 20 pulse trains lasting for 1/8th a second each.

    To accurately measure the speed, you would need to have different windows of count times to measure the speed, the stamp documents do not state if this parameter of COUNT can be a variable or not.

    Post Edited (Paul Baker) : 5/6/2005 9:55:09 PM GMT
Sign In or Register to comment.