Timer Question


Closed Thread
Results 1 to 2 of 2

Thread: Timer Question

  1. #1
    aywho's Avatar
    aywho Guest

    Unhappy Timer Question

    Hi,

    I'm never good at getting a timer to work. I'm wondering if anyone can provide some help.

    I want to do the following things:

    - when 2 copper sheets come in contact for OVER 2 seconds, the PIC sends a signal to its output pin and lights up a LED
    - if the contact is less than 2 seconds, ignore it

    I set up a counter variable in my code so that when the sheets first come in contact, the counter starts counting. When it reaches certain number e.g 250, I set the output pin to HIGH and reset the counter to 0. However, it doesn't work because once the sheets touch, the LED lights up right away.
    (by increasing the number from 250 to 300 doesn't work either. this time no LED is lit at all)

    Any suggestion or advice would be greatly appreciated! Thanks a lot!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    how about something like
    Code:
    OPTION_REG.7 = 0 ' Enable pull-up on PORTB
    
    CopperSheet var PORTB.0
    LED         var PORTB.1
    Delay       var word
    
    Start:
        delay=0
        while (coppersheet=0) and (delay!=2000)
              pause 1
              delay=delay+1
              wend
       
       if delay=2000 then 
          toggle LED       
          endif
       
       goto start
    untested but.. my last brain cell tell it's suppose to work or give you some pointers.
    Last edited by mister_e; - 23rd October 2005 at 01:00.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Simple Timer question
    By jimseng in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th September 2009, 23:12
  2. Watchdog Timer Question
    By kevj in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th March 2008, 01:56
  3. Timer Question 16f877
    By Bonxy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th November 2005, 08:40
  4. Timer / CCP Question
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd November 2005, 08:22
  5. timer question (probably for Mel)
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th September 2005, 06:52

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