BS2 & Hall-Effect
gc3076
Posts: 44
I recently purchased a MLX90217 Hall-Effect sensor from Parallax, to play around with. Can anyone suggest some links to projects or simple code. I would like to start by just counting simple·shaft rotations and then progress to displaying on a LCD.
·
·
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
Http://www.parallax.com
·
I am looking to count rotations of a shaft (CW & CCW). I was thinking of using 1(qty) sensor and 2(qty) magnets to detect direction and to increment and decrement the shaft counts.
Would this be the best way to approach this ?
So long as your sensor has bi-polor or bi-directional capability (depending on the type) you can do what you want with one sensor. Otherwise, it may not be possible with only one sensor.
Regards,
Bruce Bates
Post Edited (gc3076) : 2/7/2006 12:47:37 AM GMT
i.e. COUNT : PULSIN
Please don't think I'm denegrating the Melexis Hall Effect Sensor sensor you purchased, it's just not designed what you seem to want to do with it. There are dozens of different types of Hall Effect sensors that are specifically designed for particular, and quite different applications. One of the keys to using them properly, is to select the specific Hall Effect sensor designed for the application where you're intending to use it.
This particular sensor (MLX-90217) seems to be mostly appropriate for determining gear or cam speed, with little thought towards rotational direction, unless a specialized gear or cam is used which will help to facilitate determining CW vs. CCW rotation. In other words, this is simply a gear tooth type sensor and little more, by design. In using it the presumption is made that the shaft rotation is uni-directional, or the user doesn't care about the rotation, unless they're prepared to design an appropriate gear or cam to promote such use. Please see the datasheet for details on such a design. I would loosely equate the specialized gear/cam to an escapement gear design, as might be found in a watch or other mechanical timepiece, which see.
Allegro Micro (among others) has a number of different Hall Effect sensors which can determine both shaft speed and direction, as well as gear tooth type sensors, similar to that above. You may want to take a look at them here:
http://www.allegromicro.com/hall/ (please note the extreme variety!)
One of the "bi-polar switch" Hall Effect sensors that Allegro offers offers will generate a dual channel, quadrature output, from which one CAN determine BOTH shaft speed and direction of shaft rotation fairly easily. Take a look here at the sensor:
http://www.allegromicro.com/sf/3425/
Now take a look at these applications notes, kindly provided by Dr. Tracy Allen, regarding the use of quadrature outputs and how to use them with the PBASIC Stamp:
http://www.emesystems.com/BS2fsm.htm#twobit
That should get you started.
Regards,
Bruce Bates
If I am thinking of this correctly a truth table for a dual Allegro A3425·Hall-effect would be ?
CW·· CCW
00···· 00
01···· 10
10···· 01
00···· 00
Again I must ask if I would use COUNT or PULSIN ? Any thoughts on a code approach ?
I have been viewing results of using (2) MLX90217 hall-effects and one magnet·with ·the below code. I am just wondering if there is a way to increment or decrement?
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Pins ]
LcdPin········ PIN···· 14 'pin 14 set to BS2 serout to LCD
hall_a········ PIN···· 15 'pin 15 set as input hall-effect sensor
hall_b········ PIN···· 13 'pin 13 set as input hall-effect sensor
'
[noparse][[/noparse] Constants ]
LcdBaud········ CON···· 84············· ' 9600 baud
LcdCls········· CON···· $0C············ ' clear LCD (use PAUSE 5 after)
LcdBaudMode···· CON···· 84 'LCD baud rate set to 9600
LcdStart······ CON···· 22 'activates the LCD
LcdOn········· CON···· 17 'turns on LCD, LcdOn must be entered in the Initialzation
Line0········· CON···· 128 'assigns Line0 to be top line of the 16x16 LCD
Line1········· CON···· 148 'assigns Line1 to be the bottom line of the 16x16 LCD
'
[noparse][[/noparse] Variables ]
index········· VAR···· Nib· 'value between 0-15, 4 bits, page 84
'
[noparse][[/noparse] Initialization ]
PAUSE 500 '500ms pause
SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls, LcdOn] 'values are from the constants heading numbers could also be used
· PAUSE 500···························· ' allow LCD to initialize
·'
[noparse][[/noparse] Program Code ]
· DO
· IF· hall_a = 1 THEN
··· DEBUG "A"
· ELSE
··· DEBUG "a"
· ENDIF
·IF· hall_b = 1 THEN
··· DEBUG "B"
· ELSE
··· DEBUG "b"
· ENDIF
· DEBUG CR
· SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]·· DEC hall_a, ",", DEC hall_b, " "]
··· PAUSE 3000
· LOOP
· sensors = IND & %0011
You don't need to wait 500 milliseconds after clearing the LCD.··On reset, you might want to wait about that long to let the LCD go through its own initialization sequence; after that, you're okay other than·that you need at least 2 milliseconds after an LcdCls command.· In your output section you may want to toss in an LcdHome instruction so that you display doesn't get corrupted.
And here's a trick you can use in·your program to replace the IF-THEN-ELSE structure you're using with DEBUG:
· DEBUG ("a" - (hall_a *·32), ("b" - (hall_b * 32), CR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 2/7/2006 9:22:31 PM GMT
Although the attached Nuts and Volts Article by Scott Edwards uses a BS-1 Stamp (different PBASIC syntax than the BS-2 series), the coding techniques contained therein should show (via the text) how to write the programming code to determine CW from CCW in a very simple manner using the XOR (exclusive OR) instruction.
The rate of rotation (shaft RPM) can be determined by using the COUNT command, as you suggested. Use COUNT to determine the number of "hits" on one channel, during a finite period of time (user specified duration period is part of the COUNT command) and then extrapolate that value to: per second, per minute, or per hour, as may be appropriate in your application. I've always been partial to furlongs per fortnight as a measurement of speed :-)
Don't forget if you're using more than one magnet on the shaft or axle (although there's certainly no need to), divide the result from COUNT by the number of magnets! I don't expect you'll get intermittant or flakey counts, but if you should, let me know, there may be a trick you can use to make the counts more solid. Just don't use SUPER-GLUE on anything before you ask, as it's an installation trick, as opposed to a programming trick!
How about a pronouncable name so we don't have to keep calling you gc3076? We're a friendly group, honest!
Regards,
Bruce Bates