Counter Using A Hall Effect
Bob Robinson
Posts: 1
Hello, I am totally new to working with electronics. I purchased a board of education with the basic 2 stamp.
I work for a municipal water department. We are going to have a local community expo and I have been ask to setup a booth. What I plan to do is to take a water meter and hook it up and flow a trickle of water thru it. To show the customers that the meter can register that small amount of water flowing thru the meter. I took a meter register apart and placed a South Pole Hall Effect Sensor next to the magnet. When the south pole of the magnet stars approaching the sensor it detects it. Then after the south pole leaves the area the sensor drops it.
I·wrote a simple program that will light an led and·display a (number)·on an 4X20 LCE display when the sensor is activated. My problem is·that·the·magnet moves·slowly past·the sensor and the program loops so fast that insted of only advancing 1 number per revolution it·advances many times. Also the·number resets back to 0 when it counts 254.
Could someone write a sample loop script to help me with this problem?
Also how to keep counting above 254.
Thank you.
Robert Robinson
I work for a municipal water department. We are going to have a local community expo and I have been ask to setup a booth. What I plan to do is to take a water meter and hook it up and flow a trickle of water thru it. To show the customers that the meter can register that small amount of water flowing thru the meter. I took a meter register apart and placed a South Pole Hall Effect Sensor next to the magnet. When the south pole of the magnet stars approaching the sensor it detects it. Then after the south pole leaves the area the sensor drops it.
I·wrote a simple program that will light an led and·display a (number)·on an 4X20 LCE display when the sensor is activated. My problem is·that·the·magnet moves·slowly past·the sensor and the program loops so fast that insted of only advancing 1 number per revolution it·advances many times. Also the·number resets back to 0 when it counts 254.
Could someone write a sample loop script to help me with this problem?
Also how to keep counting above 254.
Thank you.
Robert Robinson
Comments
It sounds like you need to change your variable to a word not a byte and use pulse in.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike2545
This message sent to you on 100% recycled electrons.
But, basically what you want to do is have your Stamp watch for the sensor to close. As soon as it does, enter a loop to increment your count. However, don't let the loop complete until the sensor goes back to its idle state. By doing this, you will only increment once per occurance of the sensor becoming active.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Mike and Tom probably set you on your way, but here below is a code snipet from an bike odometer program that I wrote. For my purposes, I implemented odometer "wheels" and calibrated it through experimentation to match a known accurate bike odometer. In any case, as Tom points out, you need to go off to a loop that cycles as long as the sensor hasn't changed it's state. In the case of a bicycle, this is when the magnet is sitting just adjacent to the sensor. We don't want to count miles if the wheel happens to stop right at this point while the bike is parked for example, or at a stop sign, etc. My sensor is hooked to pin 12 so you see that the program loops as long as there is no activity at the sensor. Once the magnet moves in proximity to the sensor, we jump to the second DO WHILE loop. Once the magnet moves away from the sensor, the program proceeds to increment counters, do some calculations and display the results, then go back and DO LOOP waiting for a sensing again. The biggest concern I had with this approach is missing a count at high speeds if the code was complicated enough that it didn't get back from other processes in time to look for activity on the BASIC Stamp pin. For this application, it seemed to work ok, but my calibration process may have accounted for missed counts here and there by tweaking the multiplier to come out close to a known accurate bike odometer in the long run. I suppose I could have broken down the code and determined the execution times versus the fastest I would typically ride a bicycle. Even the BS2 runs at 4000 instructions per second. If a wheel could revolve several times per second, my code would need to be able to catch all of those and update the LCD every couple times. Note that I only update the LCD display if 100th of a mile is traveled. There isn't any point in me displaying if no change in the display would result and I had hoped to save on execution time in the process. But if I were to add temperature readings, time, or GPS data on top of that, I think I might be looking at lost counts. Would have to test it. In any case, your situation should be more straight forward. Use a Word variable for your counter and incorporate the two DO LOOPS and it should work fine.
'
variables for ODO
cnt1 VAR Word
miles VAR Word
ten VAR Nib 'tenths
hun VAR Nib 'hundreths
flg VAR Bit '10th change flag
cnt1=0
miles=0
ten=0
hun=0
SEROUT 14, 84, [noparse][[/noparse]22] ' start LCD 19200 baud
SEROUT 14, 84, [noparse][[/noparse]12] ' clear display
SEROUT 14, 84, [noparse][[/noparse]148,DEC3 miles,".",DEC ten,DEC hun]
STRT:
DO WHILE IN12=0 ' do nothing if magnet is not next to sensor
LOOP
DO WHILE IN12=1 ' do nothing until magnet moves away from sensor
LOOP
cnt1=cnt1+2627 ' 10/1000ths multiplier (vary value for ODO wheel diameter)
IF cnt1/10000>1 THEN
hun=hun+1
cnt1=cnt1//10000
flg=1 ' set flag that determines if LCD is updated
ENDIF
IF hun>9 THEN
ten=ten+1
hun=0
ENDIF
IF ten>9 THEN
miles=miles+1
ten=0
ENDIF
IF flg THEN
SEROUT 14, 84, [noparse][[/noparse]148,DEC3 miles,".",DEC ten,DEC hun]
flg=0 ' reset flag after displaying
ENDIF
GOTO STRT