PDA

View Full Version : PIR startup weirdness



dfletch
04-22-2008, 03:17 PM
Hi all.

I just picked up a PIR motion sensor from Radio Shack (how neat that some Parallax toys are waiting for me around the corner!).

I hooked it up to my protoboard and I'm having a strange startup issue. It seems that I need to wait the 10-60 seconds calibration/setup time and reset my Prop before it will work. If I don't, my little program here doesn't detect motion. It's weird though, the reset button doesn't always work. Reprogramming with f10 or f11 seems to do the trick sometimes.

I noticed a little bit of a pattern to it, don't know if that helps isolate.

1) During this "frozen" startup the pin seems high when I first read it. Then it goes low and never seems to go high again.

2) After waiting say 60 seconds and resetting, the pin is low when first read, goes high due to the motion of me messing around near the sensor and is now in normal operation.

I'm pretty darned positive that I'm doing something wrong with waitpne, because when I do this the ham-fisted way - display.dec(ina[12])) in a tight loop - it works great. Can anyone see the prob?




CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

OBJ
display : "GDM1602K"

PUB start | state, count

display.start(0)

dira[12]~

count := 0
state := 2

repeat

if ina[12]
if state <> 1
count++
display.clear
display.str(string("on: "))
display.dec(count)
state := 1

else
if state <> 0
count++
display.clear
display.str(string("off: "))
display.dec(count)
state := 0

waitpne (state << 12, %100_0000_0000, 0)





Thanks in advance if anyone has a hint.

Cheers,

--fletch

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto (http://propeller.wikispaces.com/Join+us+on+IRC%21)
spinc - open source Spin compiler (http://sourceforge.net/projects/spinc)

Harrison.
04-22-2008, 04:08 PM
Looks like you may be looking at the wrong pin. Your mask has bit 10 set (P10), not P12 as you seem to want...

Try:



waitpne (state << 12, %1_0000_0000_0000, 0)




Or, if you want to make it all readable:



waitpne (state << 12, |< 12, 0)

dfletch
04-22-2008, 11:20 PM
Wow thanks Harrison I switched pins a while back and did find/replace. Forgot about that mask!

Perfect!

Thanks,

--fletch

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto (http://propeller.wikispaces.com/Join+us+on+IRC%21)
spinc - open source Spin compiler (http://sourceforge.net/projects/spinc)