Shop OBEX P1 Docs P2 Docs Learn Events
Strange IR detector behavior, using PEK bot code — Parallax Forums

Strange IR detector behavior, using PEK bot code

bulkheadbulkhead Posts: 405
edited 2007-08-05 03:52 in Propeller 1
Ok the program I am running is quite simple:
'' File: IRDetectTest.spin

VAR    
CON
    _xinfreq = 5_000_000                     ' 5 MHz external crystal 
    _clkmode = xtal1 + pll16x                ' 5 MHz crystal multiplied → 80 MHz
OBJ
    term   :       "PC_Interface"
    IRDetect:     "Ir Detector"
PUB mainMethod
    term.start(31,30)                          'init terminal and IR detect objects
    term.str(string("starting up"))
    IRDetect.init(26,27)
    repeat
      term.dec(IRDetect.object)

'print reading (1 or 0)
Here is the object method, which I'm assuming works since its from the PEK bot code:
PUB object :state | pin, freq, dur
{{IR object detection.
    Returns state - 0 indicates that an object was detected.
                    1 indicates no object}}
  pin  := ledPin
  freq := 38000
  sw.start(@pin)
  dur  := (38000 / 400)
  waitcnt(cnt + clkfreq/500)
  state := ina[noparse][[/noparse]recPin]                                  
  sw.stop



The code loads and runs fine, but the results I am getting are strange. I only see "0"s in the terminal window no matter how I try to reflect/cover the IR led. However, if I unplug and remove the IR led altogether, I get all "1"s. I then substituted a regular LED for the IR one and I still get the "1"s. When I put the IR led back, I get "0"s. It's like the IR led affects the detector's output, but not in the intended way (using reflected IR light). What's going on?

Alternately, I found something strange with the PEK bot's schematic. It shows the IR receiver wired like this:
+5V                                 
                                                             
               │  ┌┐                              
               └──┤│                                        
 P14 ──────────┤│‣                     
         10 kΩ ┌──┤│                               
               │  └┘                                  
                 PNA4602                     
              Vss

but a diagram I have (I'm pretty sure its from the boe-bot book) shows the lower 2 pin's reversed. A look at the PNA4602's datasheet also confirms the boe-bot wiring, which is the one I used. Could this have something to do with it?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm new to the propeller!

Comments

Sign In or Register to comment.