Shop OBEX P1 Docs P2 Docs Learn Events
Little Project: Long Rang PIR Sensor — Parallax Forums

Little Project: Long Rang PIR Sensor

Sniper KingSniper King Posts: 221
edited 2008-09-02 19:23 in Propeller 1
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.

{{
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
1329 x 727 - 144K
PIR.jpg 143.6K

Comments

  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-09-02 18:14
    is it going off or just going really slow?
  • Sniper KingSniper King Posts: 221
    edited 2008-09-02 18:58
    It stops working when this anomaly occurs. I have to let the thing sit for a while and then add power. It has been working all day so far.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D
    Digital Technology Group
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-02 19:23
    couple of comments on your code
    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.
Sign In or Register to comment.