Elapsed Timer Demo


Closed Thread
Results 1 to 40 of 112

Hybrid View

  1. #1
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Darrell,
    You should have put the stop at 1 sec in the code, and make people pull it out otherwise. Just a little step towards keeping the knuckle-heads from causing trouble.

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


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    LOL Steve, I like that idea.

    But as it is, they have to be holding the button down for it to count down.
    If they're still holding it when it reaches 0 ... well ...

    I know it can be bypassed, but don't tell them how
    DT

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Code:
    IF PORTA.2 = 1 OR PORTA.3 = 1 AND DIM = 1 AND timerrunning = 1 THEN
    PORTA.0 = 1
    ENDIF
    IF PORTA.2 = 1 OR PORTA.3 = 1 AND DIM = 2 AND timerrunning = 1 THEN
    PORTA.1 = 1
    ENDIF
    IF PORTA.2 = 1 OR PORTA.3 = 1 AND DIM = 3 AND timerrunning = 1 THEN
    PORTA.0 = 1
    PORTA.1 = 1
    ENDIF
    Looking for a more efficient way of doing this. I need to monitor 2 inputs and turn on the correct outputs only when the timer is running. This does compile but I havent tested it to see if it actually works. This snippet will go in the main loop of the program that runs while the timer counts down.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Here's one idea
    Code:
    Temp VAR BYTE
    
    If TimerRunning = 1 THEN
      If (PortA.2 = 1) OR (PortA.3 = 1) THEN
        Temp = PortA & %11111100
        PortA = Temp + DIM
      ENDIF
    ENDIF
    /Henrik.

  5. #5
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Henrik I see what you are doing but wouldnt this create an issue with the higher bits? For instance if I am understanding correctly, the higher bits are always at 1, which would indicate a high, which in the program would stop and reset the timer. If I were to make them 0 in the loop, they would never change to 1 when the switch was closed. Switches are on bits 4, 5, 6 and 7.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Hi,
    No, the high bits are not always 'at 1'.
    When doing a bitwise AND both "inputs" must be true for the "output" to be true. Thus Temp = PortA & %11111100 will do a 'copy' of PortA except the two LSB's will be forced to zero. All the other bits will be left as they are when PortA is read.

    Besides, it doesn't really matter what you write to the port/pins which are configured as inputs. If, for example, PortA.5 is an input and you write '1' to it it will still read the actual state that whatever is connected to it drives it to - which isn't neccesarily '1'. If you look at the schematic for the I/O pins you'll see that the output driver for the pin is disabled when TRIS is set (ie. pin is made an input). If it wasn't it would short out whatever drives the pin to either Vdd or Vss.

    /Henrik.

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 23:14
  2. Get elapsed time while TIMER samples pulses
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th March 2009, 17:27
  3. Elapsed Timer Demo in a PIC12F675
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 21st November 2008, 01:01
  4. Totally Baffled with Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th June 2008, 22:01
  5. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 02:22

Members who have read this thread : 5

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