BS2, MMBe, Melexis 90217 and COUNT
Bill Chennault
Posts: 1,198
All--
I am successfully experimenting with the MMBe (with a LOT of initial help from Parallax!) and·the Melexis 90217. I may have the wrong concept about using the Melexis 90217, however. What I really want to do with the Melexis 90217 is to count magnets as they pass on a wheel. I don't really care about RPM. (Currently, I am using a BS2; I have a BS2px24 and a BS2p40. I will move to one of them when the correct wall transformer gets here. In the meantime, the BS2 is fine.) RPM will always be low. The no-load max is 654 rpm and I will never run it that fast. Maybe half that speed or a little more, say 450-500 rpm.)
My example has 8 magnets glued on a 3" diameter circle on a wheel. (The magnets are glued directly to the wheel.) My goal is to count how many magnets pass the Melexis 90217 Hall Effect sensor. By doing so, I will know where the wheel is within 45 degrees (360/8 = 45). Since the wheel is 3" in diameter, this means that I will know how far it has moved the robot to within 1.178". That is close enough.
My problem is how to count "magnet pass events." Obviously, PBASIC's COUNT command is not what I want. What I would like to do is simply know when a magnet has passed the Hall Effect sensor. So, what I really need to do is count each low-high-low (or vice versa) transistion, which the Melexis 90217 is designed to do.
I can't figure out the code. It seems like I would monitor the state of an input pin to see if it went 0-1-0 (or 1-0-1) as the magnets pass by. Each time one of these transitions took place, I would simply increment a counter.
How do I do this?
Thanks!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I am successfully experimenting with the MMBe (with a LOT of initial help from Parallax!) and·the Melexis 90217. I may have the wrong concept about using the Melexis 90217, however. What I really want to do with the Melexis 90217 is to count magnets as they pass on a wheel. I don't really care about RPM. (Currently, I am using a BS2; I have a BS2px24 and a BS2p40. I will move to one of them when the correct wall transformer gets here. In the meantime, the BS2 is fine.) RPM will always be low. The no-load max is 654 rpm and I will never run it that fast. Maybe half that speed or a little more, say 450-500 rpm.)
My example has 8 magnets glued on a 3" diameter circle on a wheel. (The magnets are glued directly to the wheel.) My goal is to count how many magnets pass the Melexis 90217 Hall Effect sensor. By doing so, I will know where the wheel is within 45 degrees (360/8 = 45). Since the wheel is 3" in diameter, this means that I will know how far it has moved the robot to within 1.178". That is close enough.
My problem is how to count "magnet pass events." Obviously, PBASIC's COUNT command is not what I want. What I would like to do is simply know when a magnet has passed the Hall Effect sensor. So, what I really need to do is count each low-high-low (or vice versa) transistion, which the Melexis 90217 is designed to do.
I can't figure out the code. It seems like I would monitor the state of an input pin to see if it went 0-1-0 (or 1-0-1) as the magnets pass by. Each time one of these transitions took place, I would simply increment a counter.
How do I do this?
Thanks!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Comments
Syntax: PULSIN Pin, State, Variable
Function
Measure the width of a pulse on Pin described by State and store the result in Variable.
Quick Facts
Explanation
PULSIN is like a fast stopwatch that is triggered by a change in state (0 or 1) on the specified pin. The entire width of the specified pulse (high or low) is measured, in units shown above and stored in Variable.
Many analog properties (voltage, resistance, capacitance, frequency, duty cycle) can be measured in terms of pulse duration. This makes PULSIN a valuable form of analog-to-digital conversion.
PULSIN will wait for the desired pulse, for up to the maximum pulse width it can measure, shown in the table above. If it sees the desired pulse it measures the time until the end of the pulse and stores the result in Variable. If it never sees the start of the pulse, or the pulse is too long (greater than the Maximum Pulse Width shown above), PULSIN "times out" and store 0 in Variable. This operation keeps your program from locking-up should the desired pulse never occur.
Regardless of the size of Variable, PULSIN internally uses a 16-bit timer. Unless the pulse widths are known to be short enough to fit in an 8-bit result, it is recommended using a word-sized variable. Not doing so may result in strange and misleading results as the BASIC Stamp will only store the lower 8-bits into a byte variable.
Thank you so much for the clue. I will study PULSIN (of course, I already have, but do not have the experience to generalize it, yet) and see if I can make it do what I want . . . which may not be what I need! But, that is part of the learning process.
I remain wide open to more suggestions from anyone and everyone.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.