Little Project: Long Rang PIR Sensor
Sniper King
Posts: 221
This is weird.· Attached are my schematic and code.
This is what happens.· It works good for a while.· Then out of no where the propeller stops working or so I thought.· I found when the PIR sensor goes high, the propeller comes on.· I can program it but when the PIR sensor goes off the propeller goes off.· The·PIR sensor connects to pin 10 only!· The PIR sensor stays high for 2 seconds.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
This is what happens.· It works good for a while.· Then out of no where the propeller stops working or so I thought.· I found when the PIR sensor goes high, the propeller comes on.· I can program it but when the PIR sensor goes off the propeller goes off.· The·PIR sensor connects to pin 10 only!· The PIR sensor stays high for 2 seconds.
{{ PIR UDA Sensor.spin, v1.1,Michael King ┌──────────────────────────────────────────┐ │ Copyright (c) 2008 Michael S. King │ │ See end of file for terms of use. │ └──────────────────────────────────────────┘ }} CON
CON _clkmode = rcslow '_xinfreq = 5_000_000
OBJ Send : "FullDuplexSerial"
PUB main clkset(%00000001 , 0) ' Set internal oscillator to RCFast and set PLL to start waitcnt(cnt+120_000) Dira[noparse][[/noparse]10]:=0 ' Set internal oscillator to RCFast and set PLL to start Dira[noparse][[/noparse]15]:=1 repeat waitpeq(%010000000000, %010000000000, 0) 'Wait port Port 10 to go high clkset( %01101000,80_000_000 ) 'Set to XTAL1 waitcnt(220000+cnt) clkset( %01101111,80_000_000 ) 'Set to XTAL1 + PLL16x waitcnt(1000000+cnt) outa[noparse][[/noparse]15]:=1 'turn on Xmitter send.start(16,17,0,9600) ' start FullDuplexSerial waitcnt(20_000_000+cnt) 'Wait a bit for the XTEND to be ready send.str(string("<*00000001*S*>")) 'Send activation of sensor Message waitcnt(20_000_000+cnt) ' Wait for message to be sent send.stop 'Close down FullDuplexSerial outa[noparse][[/noparse]15]:=0 'Turn off Xmitter outa[noparse][[/noparse]17]:=0 'Ground 17 to prevent leakage. waitcnt(cnt+500_000) clkset(%00000001 , 0) ' Set internal oscillator to RCslow waitcnt(cnt+80_000)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
1. The outa[noparse][[/noparse]17] := 0 I dont believe will do what you are expecting, you dont set the pin to be an output in the cog anywhere. The serial port code sets output in its own cog which makes no difference to the main cog
2. The last 2 waitcnt should have cnt last.
I dont believe either of these is causing your problem though. So I would separate the functions as try to isolate the problem. Remove the output code and the clock changing code and just have the pir input code in a loop that does nothing. If that still has a problem its definitely the pir. If not try thr clock chaning stuff in a loop by itself. Try the xmitter on/off in a loop (with delays) by itself. i.e. try each piece until you understand which piece causes the problem. It all are ok, combine each in pairs, etc.