How do I detect a polarity change on an input?


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    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.

  2. #2
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Looking good

    Thanks BobK and Darrel,

    I tried Darrels code snip and it works great to lite Led's and extinguish them when I phone my LabXT board and enter the correct DTMF's from my cell phone, now all I have to do is connect the wires from my X10 transmitter when I get off work tonight. Thanks a lot Darrel, I really appericate your input, could you please explain the logic as to how the <> works and why you set each byte variable to 255? I'd sure be interested to be able to understand how and why that works.

    Also thanks for your code snip BobK, I'll go over it in detail when I get home tonight. That's great guys....

    Thanks Again
    jessey

  3. #3


    Did you find this post helpful? Yes | No

    Default

    The <> just means the two values are not equal.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Right, it's not equal to.
    By means of being either Less Than or Greater Than, just like >= would be greater than or Equal to.

    It's initialized to 255 to make sure it always triggers on the first pass.
    If it were left at 0 (assuming there's a CLEAR statement), and the first Request was also a 0, then the code wouldn't execute and the output state would be left Undefined.

    hth,
    DT

  5. #5
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Your The Man!

    Very Clever Darrel,

    Thanks for the explanation and the code, I totally understand it now. It took me a few minutes to fully get it and once I did I could see with-out a doubt that it's fool proof.

    Thanks Again
    jessey

  6. #6
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Jessey, although your original query has been answered, I thought I would add my opinion as well.

    When you speak of the X10 transmitter I assume you are referring to an X10 RF transmitter, right?

    In which case, why not get rid of the X10 remote altogether, and drive an RF transmitter module directly with your 877? The RF protocol used by X10 is well documented (its actually the NEC IR protocol) and I could send you the URL(s). Besides the hardware being much simpler, you could send as many different commands and addresses as you wish without having to add more transistors.

    Regards,

    Anand

  7. #7
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Forgot to add, there are readymade basic snippets on the web that directly let a stamp drive an X10 firecracker as well; would achieve the same objective you seek.

    Regards,

    Anand

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