14M PWMOUT problem

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.

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
 

boriz

Senior Member
"it clears the output pins"

Does it do the same thing on the actual Picaxe, or just the simulator? Could be a simulator bug?
 

lanternfish

Senior Member
Haven't got around to breadboarding the circuit yet - next day or two. I was wondering if it was a simulator bug, also. Cheers
 

lanternfish

Senior Member
Thanks hippy. Just breadboarded and will test tomorrow. As you have identified this as a possible simulator bug, I will carry on with writing the code.

Cheers
 

hippy

Ex-Staff (retired)
Correction

Or rather a re-correction, there does seem to be a problem with the simulator which we will investigate.
 
Last edited:
Top