Menu

Hall Sensor Edge detection

Help
Capaction
2010-04-03
2013-05-30
  • Capaction

    Capaction - 2010-04-03

    On a PIC 16F628A  I have  Port RB3 connected  on a Hall Sensor. with 0Volt in front of  the magnet and 5Volts elsewhere.

    CCP1 B'111' & B'110' are used to capture time on several turns (4 or 16 turns)
    https://sourceforge.net/projects/gcbasic/forums/forum/579126#bold
    How can I detect a Falling Edge on each turn ?

    The following code does not detect a Falling or Rising Edge.
    #Define SENSORon  PortB.3=off 'pullUp 5V Else OV in front of magnet
    If SENSORon Then do something

     
  • Nobody/Anonymous

    What type of Hall Sensor are you using.
    Hall sensors generally provide a very small change in output for
    Changes in magnetic flux density, as they are linear devices.
    You normally need some kind of amplifier between the Hall Sensor and the PIC.
    .

     
  • Capaction

    Capaction - 2010-04-21

    I use a TLE4905 Hall Sensor the voltage drops from 5V to 0V in front of the magnet. Of course the time in front of the magnet is dependant  on the speed.. With a very slow  RPM  it stays low for twice the magnet diameter, ie 12 milimeters.

     
  • Nobody/Anonymous

    Have you defined the B port as an input.
    If you replace the Hall device with a simple on / off switch
    what happens.

     
  • Capaction

    Capaction - 2010-04-22

    Of course the B port is defined as an input.
    The Hall sensor acts as a simple on/off switch. The problem is that the test "IF SensorON " will remain positive until the magnet is away from the sensor (around 12milimeters) I cannot detect a Falling or a Rising edge with this test.

     
  • Nobody/Anonymous

    It sounds like you want your program to be alerted when the sensor output changes state. To do this, you need to enable and configure PortB interrupts and write an interrupt handler that determines what action to take when the output changes state.

     
  • mmotte

    mmotte - 2010-04-24

    Your options are :
    1) Interrupt PortB on change on PortB 4-7  but this requires figuring out  which pin changed and we don't know what else is hooked up to these pins
    2) Port A has Interrupt on two comparators but these are more for looking at the analog signal and checking for when it crosses some level
    3) Best option is plain old Interrupt on PortB.0 .  Check out the spec sheet.
    OPTION REGISTER
    bit 6 INTEDG: Interrupt Edge Select bit
          1 = Interrupt on rising edge of RB0/INT pin
          0 = Interrupt on falling edge of RB0/INT pin

    INTCON REGISTER
    bit 4 INTE: RB0/INT External Interrupt Enable bit
          1 = Enables the RB0/INT external interrupt
          0 = Disables the RB0/INT external interrupt
          INTF: RB0/INT External Interrupt Flag bit
    bit 1
          1 = The RB0/INT external interrupt occurred (must be cleared in software)
          0 = The RB0/INT external interrupt did not occur

    So you can choose the direction of the pulse which you desired.
    Once in the interrupt you can do your desired response( read timer, set a port pin, inc a count,etc)
    don't forget to reset the interrupt.

    GCBasic makes it easy to do interrupts.
    First you will need a  interrupt intialization to set up the interrupt registers

    Then you will need an interrupt  subroutine
    sub INTERRUPT
    disable interrupts
    ….do stuff
    reset flags
    enable interrupts
    end sub

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.