Greg, been studying your tutorials, my most recent efforts, as ever, alterations, amendments and comments most welcome.
08M2 and Infra Red control.
In practice, works exceptionally well, quick and very smooth in operation, no time lag drag, motor control is very smooth, and runs cool.
To be powered by 4 AA 1.2v rechargeable batteries, 08M2 requires 5v, L293D drops 1.5v, so the Tamiya FA130 runs on approx 3.3v, these motors are susceptible to over voltage and are renowned for producing electrical spikes.
Led directional lighting using C.4, using the Picaxe's ability to source/ and-or /sink current from an output pin.
The flashing light sequence was a touch of 5 minute madness!
Universal IR Infra-red Receiver TSOP 2438 38kHz.
3 pin device, +, -, and OUT
Working voltage: 2.7 ~ 5.5 V.
Working current: 1.4 mA.
Frequency: 38 kHz.
Angle: 45 degree.
IR receiver OUT pin is connected to C.3 on the Picaxe 08M2, strip board circuit built from data sheet schematic, recommend use of capacitor and resistor, does increase sensitivity and range.
Does not need "line of sight to function” can be stood 15' directly behind and still operates, like wise from front, wide arc of field of reception, used remote some 30' distance from receiver, functioned correctly. IR will not penetrate solid objects.
Magnavox MRU0110/10 Universal Remote Control, fully SIRC (Sony Infra Red Codes) compliant, all transmitted codes are interpreted correctly by the 08M2, small ergonomic design easily held and operated in one hand.
To control motor speed, pulse the power to the motor with a variable width pulse. The Picaxe has a very convenient command for this, pwmout. It runs in the background once executed, so will permit the execution of other code whilst continuing to output the pulses.
The command pwmout will give a variable pulse duty cycle (on to off time), with 0 stopping the motor, and 1023 giving full speed, and anything in between giving part speed.
The frequency of the pulses is about 4 kHz. Other (higher) frequencies are possible by using different values in the pwmout command (refer to PWM Wizard in the Program Editor).
Using the L293D *, or a**, leg 16 5v, leg 8 Vcc2 (Motor voltage) ,legs 4,5,12,13 Gnd 0v, all other legs doubled up, thus the rating for the IC Motor Controller chip is now 1.2 amps (2 x 0.6 amp)
* L293D dual H bridge, switchable transistors with diodes in one 16 pin IC package.
**SN754410NE is a higher rated direct replacement 1 amp standard, doubled up takes it's rating to 2 amps.
Check motor specifications, a heat sink for the Motor IC Controller may be required, either on top of the IC, or below using the Gnd legs.
The pulses from the 08M2 (C.2) are fed into the two enable lines (legs 1&9).
C.0 & C.1 are the direction output pins connected to legs 2&15 (C.0) and legs 7&10 (C.1).
Motor outputs, legs 3&14 to one motor terminal, 6&11 to other terminal.
Referring to the above image, the circuit has four switches A, B, C and D.
Turning these switches ON and OFF can drive a motor in different ways.
Turning on Switches A and D makes the motor rotate clockwise.
Turning on Switches B and C makes the motor rotate anti-clockwise.
Turning on Switches A and B will stop the motor (Brakes).
Turning off all the switches gives the motor a free wheel drive.
Lastly avoid turning on A & C at the same time, or B & D at the same time, as this will short the circuit.
Simple, tested working Code for IR & 08M2, ongoing project.
#picaxe 08M2
#com 6
;C.0 motor direction
;C.1 motor direction
;C.2 PWM
;C.3 Infra Red
;C.4 Led lights
;Revision 01/05/2014
symbol counter = b1
symbol led = C.4
main:
irin C.3,b0
if b0 = 18 then forwards1 ; vol +
if b0 = 20 then stop1 ; mute
if b0 = 19 then reverse1 ; vol -
if b0 = 21 then lightsflash ; power
goto main
forwards1:
pwmout C.2, off
pwmout C.2,50,255
high C.0
low C.1
low C.4
high C.4
goto main
reverse1:
pwmout C.2, off
pwmout C.2,50,255
high C.1
low C.0
high C.4
low C.4
goto main
stop1:
pwmout C.2, off
low C.0
low C.1
goto main
lightsflash:
for counter = 1 to 4
low led
pause 250
high led
pause 250
next counter
goto main
****************************************************************************************************************************
;Controlling motor speed and direction with a 10K potentiometer
;Using a L293D quadruple half-H bridge motor controller chip, or an SN754410NE
;L293D max current 0.6 amp,C.1 connected to 1A&4A.C.0 connected to 2A&3A, making 1.2 amp
;C.2 pwm output from 08M2 connected to both 1-2EN & 3-4EN on the L293D
;Motor + connected to 1Y&4Y, motor - connected to 2Y&3Y on the L293D
;Revision 01/05/2014
#picaxe 08M2
#com6
#terminal off
setfreq m4 ;08M2 can run at 8,16 or 32
dirs=%00000111 ;Make Pins C.0,C.1 & C.2 outputs
symbol fwdmin = 511 ;Analog reading for minimum forward speed
symbol revmin = 513 ;Analog reading for minimum reverse speed
symbol aport = C.4

efine input port for potentiometer
symbol pwmport = C.2

efine output port for pulse stream output to L293D
symbol avalue = w0

efine word for analog reading
symbol pwmonper= w1

efine word for pwm dutycycle
output C.0 ;Set pin C.0 as output to L293D
output C.1 ;Set pin C.1 as output to L293D
do
readadc10 aport, avalue ;Read potentiometer position
select avalue
case 0 to fwdmin
pins = $02 ;Set motor direction forward
pwmonper = fwdmin - avalue *21/10 MAX 1023 ;Calculate on period
case revmin to 1023
pins = $01 ; Set motor direction reverse
pwmonper = avalue - revmin *21/10 MAX 1023 ;Calculate on period
endselect
pwmout pwmport,255,pwmonper
loop
*** There is also a L298N available, this can handle up to 4 amps, it does however require a much higher voltage battery power pack to operate.
This is now constructed and running as a manual speed controller, using the above code with minor modifications, replacing the LGB speed controller as supplied in the starter set.
Pictures and video are on Photobucket, which seems to have gone on a go slow at the present.