Problem with pause command

Wasserflo

Member
Hi,
I have build a small 'robot', based on two motors and a L293 Motor IC and two bumper switches at the front, left and right.
It's a really simple program.
When starting it will go forward until one bumper PIN get's down.
Then it should go backward for 2 seconds, make a little turn and go forward again.
This works for a couple of seconds. After that it seems that the 2000 delay is only a 2 delay.
I see that the motor stops, but it goes immediatly forward again.
Any ideas what happens here?
I use a 14M2 for this.

Code:
main:
    pullup on
    pwmout pwmdiv64, B.2, 124, 0
    pwmout pwmdiv64, B.4, 124, 0
    pwmout pwmdiv64, C.0, 124, 0
    pwmout pwmdiv64, C.2, 124, 0
    gosub vor
    do
        if pinB.1 = 0 then
            gosub rueck
            gosub drehL
            gosub vor
        endif
        if pinB.3 = 0 then
            gosub rueck
            gosub drehR
            gosub vor
        endif
    loop

vor:
    pwmout pwmdiv64, B.2, 124, 0
    pwmout pwmdiv64, C.0, 124, 0
    pwmout pwmdiv64, B.4, 124, 249
    pwmout pwmdiv64, C.2, 124, 249
    return
    
rueck:
    pwmout pwmdiv64, C.2, 124, 0
    pwmout pwmdiv64, B.4, 124, 0
    pwmout pwmdiv64, B.2, 124, 249
    pwmout pwmdiv64, C.0, 124, 249
    pause 2000
    return
    
drehL:
    pwmout pwmdiv64, B.2, 124, 0
    pwmout pwmdiv64, B.4, 124, 0
    pwmout pwmdiv64, C.0, 124, 0
    pwmout pwmdiv64, C.2, 124, 249
    pause 500
    return

drehR:
    pwmout pwmdiv64, B.2, 124, 0
    pwmout pwmdiv64, C.0, 124, 0
    pwmout pwmdiv64, C.2, 124, 0
    pwmout pwmdiv64, B.4, 124, 249
    pause 500
    return
 

Technical

Technical Support
Staff member
If it keeps going forwards you've probably got electrical noise resetting the microcontroller. If a motor stalls this could potentially cause this. Add a command at the start of your program (e.g. flash an LED) to see if it is resetting.
 

inglewoodpete

Senior Member
Further to what Technical has said, above, the wiring interconnect for a microcontroller operating a motor is critical.

While the motor and microcontroller can run off the same power source, they should not share the power wires. In the case of battery operation, separate + & - wires should be run for the microcontroller and the L293's motor power/ground pins.
 
Top