servo and irin problems

JAX225

New Member
I've got a IR Rx strapped to a servo that I want to use to find an IR homing signal:

Code:
symbol pos = b1
symbol ir_code = b2

init:
servo 7,150
pause 250

ir_wide_scan2:
  let b3=1:debug:wait 3
for pos = 225 to 75 step -5 'increments servopos value
  let b3=2:debug:wait 3
servopos 7, pos 'starts servo full left, tried using "servo" command too
  let b3=3:debug:wait 3
let ir_code = 0 'reset any previous IR codes
  let b3=4:debug:wait 3
gosub ir_sense
  let b3=7:debug:wait 3
next pos
goto ir_wide_scan2
return

lock_on:
  let b3=100:debug:wait 3
low c.0 'powers an indicator LED
pause 2000
high C.0
goto ir_wide_scan2
return

ir_sense:
  let b3=5:debug:wait 3
irin [550,ir_timeout],A.0,ir_code 'look for IR signal
  let b3=99:debug:wait 3
if ir_code = 5 then goto lock_on
return

ir_timeout:
  let b3=6:debug:wait 3
return
The problem is after the three second wait is over following the debug b3=5 line, the servo will increment what looks like 75 pulses while running the "irin" command. After the 0.55 second pause it returns back to the position it should be in.

Two days of banging my head has given me quite the knot on my skull. Is there some timer conflict I'm not aware of? I've had my girlfriend confirm my hardware is setup correctly (and consequently taught her the pinout on a 28X2). I'm at a loss.

Thanks in advance for any help.
 
Last edited:

westaust55

Moderator
Welcome to the PICAXE forum.

It could well be a timer/interrupt conflict.

Servo comamnd uses Timer 1 & 2 interrupts
Timer comamnd uses Timer 1 interrupt

but I am not sure which mechanism is specifically used for the timeout feature for IRIN and SERIN comamnds.

Have a read about Appendix 4 - Possible Conflicting Commands in PICAXE manual 2 Appendix 4 on page 251.

Comms such as SERIN, SEROUT, IRIN and IROUT disable the interrupts which the comms is in progress.
 

JAX225

New Member
Ah, it seems I have an older version of the manual, sans appendix 4. Thanks for the lead.

I don't know if it's the drop to 4mhz or what it is but the irin command interferes with a few things. For instance, when motoring forward with an L293D, when I run irin, the bot comes to a halt while it processes.

If I run the servo command at all previous to an irin command, the servo will freak out from irin as described. If I don't initiate the servo, there are no reactions to irin. It must be something internal.
 
Last edited:

hippy

Ex-Staff (retired)
It may well be the drop to 4MHz during the IRIN and during the subsequent DEBUG command. One possibility may be to disable the servo ( "LOW B.7" ) before and have a restoring "SERVO 7,x" command after those which change operating speed.
 

JAX225

New Member
Mmm, that's a good idea. I tried using the pinsB command to turn the servo pin into an input and things went haywire. After that I put the idea of screwing with the pins out of my mind.

I'll have to try that when I get home, thanks hippy.
 

JAX225

New Member
Just finally got around to making the changes and I'm happy to say it works perfectly now.

Special thanks to hippy and thanks to all!
 
Top