Derelict48
Member
I am building a garden railway loco to be controlled by the Picaxe IR kit. The motor is an MFA 12v motor controlled by an L298 controller connected to a 20M2 chip.
Functions at the moment are: slow forward, fast forward, reverse, stop and horn.
Everything is installed in the loco and works well except for one thing:- Every time I press a key on the remote the loco takes a lurch forward as if it was receiving full power from the batteries. (8 NiMh cells) Nowhere in the programme is the duty cycle high enough to cause this.
Even if I press a non functioning button the motor take this lurch. Initially debug would not work and I read somewhere that putting a Pause 500 command at the beginning would help with this. If I put this in, holding ANY button down sends surges to the motor every half second. Changing the value changes the rate of this pulse. The desired functions still operate normally.
I have played about with this kind of thing for a while but this is the first time that I have used a decent motor to drive a loco.
Perhaps someone out there can tell me what I am doing wrong. I know my programming is probably clumsy but I really want to keep it simple at this stage
#picaxe 20M2 ;to make debug work
main:
Low B.0 ;to make debug work
irin C.7,b0
debug b0
if b0 = 16 then
gosub speed1
endif
if b0 = 19 then
gosub speed2
endif
if b0 = 17 then
gosub back
endif
if b0 = 8 then
gosub horn
endif
if b0 = 18 or b0 = 21 then
gosub still
endif
goto main
speed1: ;slow speed
low B.3
high B.2
pwmout C.3,14 ,30 ;last variable may be changed
let b1 = 30 ;to confirm current duty cycle
goto main
speed2: ;faster speed
high B.2
low B.3
pwmout C.3,14 ,40
let b1 = 40
goto main
back: ;reverse
high B.3
low B.2
pwmout C.3,14 ,35
let b1 = 35
goto main
still: ;stop
low B.3
low B.2
goto main
horn: ;horn sound
sound B.1,(100,80)
pause 100
sound B.1,(100,100 )
goto main
Functions at the moment are: slow forward, fast forward, reverse, stop and horn.
Everything is installed in the loco and works well except for one thing:- Every time I press a key on the remote the loco takes a lurch forward as if it was receiving full power from the batteries. (8 NiMh cells) Nowhere in the programme is the duty cycle high enough to cause this.
Even if I press a non functioning button the motor take this lurch. Initially debug would not work and I read somewhere that putting a Pause 500 command at the beginning would help with this. If I put this in, holding ANY button down sends surges to the motor every half second. Changing the value changes the rate of this pulse. The desired functions still operate normally.
I have played about with this kind of thing for a while but this is the first time that I have used a decent motor to drive a loco.
Perhaps someone out there can tell me what I am doing wrong. I know my programming is probably clumsy but I really want to keep it simple at this stage
#picaxe 20M2 ;to make debug work
main:
Low B.0 ;to make debug work
irin C.7,b0
debug b0
if b0 = 16 then
gosub speed1
endif
if b0 = 19 then
gosub speed2
endif
if b0 = 17 then
gosub back
endif
if b0 = 8 then
gosub horn
endif
if b0 = 18 or b0 = 21 then
gosub still
endif
goto main
speed1: ;slow speed
low B.3
high B.2
pwmout C.3,14 ,30 ;last variable may be changed
let b1 = 30 ;to confirm current duty cycle
goto main
speed2: ;faster speed
high B.2
low B.3
pwmout C.3,14 ,40
let b1 = 40
goto main
back: ;reverse
high B.3
low B.2
pwmout C.3,14 ,35
let b1 = 35
goto main
still: ;stop
low B.3
low B.2
goto main
horn: ;horn sound
sound B.1,(100,80)
pause 100
sound B.1,(100,100 )
goto main