lanternfish
Senior Member
Despite reading the manual(s) from cover to cover; and having searched picaxeforum I cannot solve this litle problem:
When simulating the routine below - Main: - the PWMOUT 2 , 25, 105 command is seen to be active on Input 2 (seems to be what the manual says should happen). However the PWMOUT 2 , 25 , 0 command not only stops the PWM on Input 2, it clears the output pins.
The PWM signal modulates a IR LED. An IR receiver then outputs to TTL "1" if it senses the IR signal. This is read on Input 0. The control to a L293 are ouput on Outputs 5,4,3,1.
Can anyone see where I have gone wrong.
When simulating the routine below - Main: - the PWMOUT 2 , 25, 105 command is seen to be active on Input 2 (seems to be what the manual says should happen). However the PWMOUT 2 , 25 , 0 command not only stops the PWM on Input 2, it clears the output pins.
The PWM signal modulates a IR LED. An IR receiver then outputs to TTL "1" if it senses the IR signal. This is read on Input 0. The control to a L293 are ouput on Outputs 5,4,3,1.
Can anyone see where I have gone wrong.
Code:
'********************************************************************************
'* *
'* Atom-1R Robot v0.1 *
'* *
'* L Gordon - 2009 *
'* *
'********************************************************************************
'Directives
#PICAXE 14M
#GOSUBS 16
#SIMSPEED 100
'Constants
SYMBOL obstruct = 1
SYMBOL noobstruct = 0
SYMBOL lfwd = %00100000 ;bit5 & bit4 = Left motor
SYMBOL lrev = %00010000
SYMBOL rfwd = %00001000 ;bit3 & bit1 = Right motor
SYMBOL rrev = %00000010
SYMBOL mstop = 0
SYMBOL turndelay = 500
'Variables
SYMBOL motors = b0
SYMBOL sensin = b1
SYMBOL rdg = w1 ; Used by Random direction generator
SYMBOL direct = b4
SYMBOL nextb = b5
Initialise:
motors = mstop ; Stop motors
pins = b0
'PWMOUT 2 , 25 , 105 ; 38kHz 100% Duty Cycle
Main:
PWMOUT 2 , 25, 105 ; 38kHz 100% Duty Cycle
sensin = pins ; Obstruction?
PWMOUT 2 , 25 , 0 ; Save some power
IF sensin = noobstruct THEN GOTO NoTurn
WhereAmI:
sensin = pins ; Obstruction?
IF sensin = 1 THEN Obstruction
NoTurn:
motors = lfwd OR rfwd
outpins = motors
GOTO Main
Obstruction:
PWMOUT 2, OFF
sensin = 0 ; Clear - no obstruction
motors = mstop ; Stop moving
outpins = motors
RANDOM rdg ; Choose a turn direction
direct = rdg // 2 + 1
IF direct = 1 THEN TurnLeft ; 1 = Turn Left
IF direct = 2 THEN TurnRight ; 2 = Turn Right
GOTO Main
TurnLeft:
motors = lrev OR rfwd
outpins = motors
PAUSE turndelay
motors = mstop
outpins = motors
GOTO Main
TurnRight:
motors = lfwd OR rrev
outpins = motors
PAUSE turndelay
motors = mstop
outpins = motors
GOTO Main