How do I detect a polarity change on an input?


Results 1 to 22 of 22

Threaded View

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


    Did you find this post helpful? Yes | No

    Smile

    Hi Jessey,

    Probably what you want to do is set up flags for each input and make them a bit in the PICs EEPROM. (By storing them in the PIC's EEPROM, you can restart your program pretty much where your left off.) For example, let's call your first switch Input0. We'll call the flag for this switch In0. The same setup would be used for the other switches. You can also set a flag for "new start" and "restart" and have a routine check for the status of this bit before continuing on with the program.

    When your system is first setup, In0 will be set to 0. When the switch condition = 0 and the flag = 0 nothing would be done as it was already setup as normal. Now your loop that checks the inputs would "scan" all the switches. When there is a difference between Input(x) and Flag(x) your IF..Then sequence would select the appropriate subroutine to go to. If the current loop value (either 1 or 0) is the same as the flag, then nothing really needs to be done. If there is a change the program would then handle it, change the status flag and resume the normal program.

    I do most of my programs like this and for me it works quite well.

    HTH,

    BobK

    I know there must be several ways to handle this type of programming but I like to keep my programs real easy to follow. Maybe someone else will jump in here during the day an enlighten you AND ME! When I get off of work this evening I see if I can send you a sample of code that I used.
    Last edited by BobK; - 13th January 2008 at 15:56. Reason: After thoughts!

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