Shop OBEX P1 Docs P2 Docs Learn Events
BS2 & Hall-Effect — Parallax Forums

BS2 & Hall-Effect

gc3076gc3076 Posts: 44
edited 2006-02-07 21:08 in BASIC Stamp
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

  • dandreaedandreae Posts: 1,375
    edited 2006-01-31 19:35
    Here is a link to sample project with code:· http://www.parallax.com/html_pages/robotics/machining/RPM_display.asp

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    Http://www.parallax.com

    ·
  • gc3076gc3076 Posts: 44
    edited 2006-02-06 20:08
    This was great asistance for my understanding of the sensor.
    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 ?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-06 21:29
    gc3076 -

    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
  • gc3076gc3076 Posts: 44
    edited 2006-02-07 00:22
    I purchased the Melexis 90217 Hall-Effect Sensor from Parallax. I don't see in the spec sheet if it is·bi-polor or bi-directional capable ?

    Post Edited (gc3076) : 2/7/2006 12:47:37 AM GMT
  • gc3076gc3076 Posts: 44
    edited 2006-02-07 13:51
    Thoughts anyone ?? I am trying to determine if I should use this sensor and if so what would be the best code approach.

    i.e. COUNT : PULSIN
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-07 16:02
    gc3076 -

    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
  • gc3076gc3076 Posts: 44
    edited 2006-02-07 20:00

    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



  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-07 20:17
    One of our techs, Chris,·showed me a trick with rotary encoders that you can probably use in your program.· I've attached a project that I did for Nuts & Volts that uses this technique -- you should be able to fold it into your program.· I would create holding variable for the sensor inputs and re-map the inputs to P12 (A) and P13, then you could do this:

    · 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
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-07 21:08
    gc3076 -

    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
    pdf
    528K
    nv8.pdf 528.4K
Sign In or Register to comment.