PDA

View Full Version : Timer Question



aywho
- 22nd October 2005, 21:45
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!

mister_e
- 22nd October 2005, 21:54
how about something like


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.