How do I detect a polarity change on an input?


Results 1 to 22 of 22

Threaded View

  1. #4
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Jessey,
    Here are the code snippets I created to handle the inputs to my project. I used a 4051 with 8 inputs feeding into a window comparator. The two outputs of the window comparator gave me one signal for loop open condition and another for loop shorted condition. PortC pins 5,6, and 7 were the bcd out to select one of 8 inputs to be tested by the micro. First is tested for an open loop, then it tested for a shorted loop. If either condition was already handled then a bit flag is set when the condition is first handled and the bit flag gets reset when the reset of the condition is handled. I did this code 3 years ago and was my first big project so the coding is rather crude and I'm sure it can be done some other way but it did the job and has been working great in the field since so I guess that's all that matters.

    loop0op:
    portC.5 = 0: portC.6 = 0: portC.7 = 0 'set portC to look at 1st loop
    pause delay 'take a short break
    If portA.0 = 0 Then G0on 'if loop is open turn led on
    If portA.0 = 1 then G0off 'if loop is normal turn led off
    goto loop0sh 'go test for shorts

    loop0sh:
    If portA.1 = 0 then R0on 'if loop is shorted turn led on
    If portA.1 = 1 then R0off 'if loop is normal turn led off
    Goto loop1op 'goto next loop


    G0on:
    If Bit0 = 1 then loop0sh 'if already open goto next test
    Portb.0 = 1 'turn led on
    Bit0 = 1 'set flag that loop is open
    Goto loop0sh 'go test for shorts

    G0off:
    If Bit0 = 0 then loop0sh 'If loop is normal goto short test
    Portb.0 = 0 'turn led off
    Bit0 = 0 'reset flag
    Goto loop1op 'goto next test

    R0on:
    If Bit8 =1 then loop1op 'if already tripped goto next loop
    PortD.0 = 1 'turn led on
    B2 = 120 'set apt #
    gosub Sendata 'send apt # to main display board
    Pause 10
    Bit8 = 1 'set flag that we're tripped
    Goto loop1op 'goto next test

    R0off:
    PortD.0 = 0 'turn led off
    pause 10
    if bit8 = 0 then loop1op 'if flag already cleared then next loop
    B2 = 280 'restore code for 1st zone
    gosub Sendata 'send restore report to main board
    Bit8 = 0 'clear flag so we're back to normal
    Goto loop1op 'goto next test


    Hope this helps you!

    BobK
    Last edited by BobK; - 14th January 2008 at 01:51.

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. Replies: 1
    Last Post: - 7th November 2007, 20:36
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  4. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  5. detect oscillating input
    By fester addams in forum General
    Replies: 1
    Last Post: - 22nd November 2004, 18:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts