LGB Side Rod Diesel "Original Build"








LGB 0-6-0 Side Rod Diesel.



This is an LGB American outline side rod diesel, 



It eventually will de-Americanised and be made to look more like an Australian Sugar Cane Loco to tow my Sugar Cane Bins.


It has been converted to Battery Power Radio Control using HobbyKing model aircraft components.

Radio Control & Electronic Components

  • HobbyKing 2.4Ghz 4Ch Transmitter (Tx) Version2 Mode 1, (Throttle on the RIGHT)
    NOTE: The Tx servo switch for the throttle must be in the “REV” position for it to work.
  • HobbyKing 2.4Ghz Receiver  (Rx) T6A-V2, compatible only with HobbyKing T4A & T6A Version2 transmitters, (a 4 channel Rx comes with the Tx/Rx combo but any extra Rx’s have to be 6 channel, because that is all that is offered by HobbyKing)
  • HobbyKing Turnigy TGY-20A Brushed Electronic Speed Controller (ESC). 
    Note on ESC: - There are 2 small blue plugs used to select either LiPo or NiMH batteries. (It has a low voltage detection circuit so it needs to know what types of batteries are connected) and Brake On/Off.  Select brake off i.e. when the throttle returns to stop it does NOT put a brake on the motor.

  • HobbyKing HXT 9g/1.6Kg/.12 Micro Servo operating a Double Pole Double Throw (DPDT) toggle switch for direction control.

  • Nine (9), 2700mAH NiMH, tagged 1.2V AA cells, used to give a nominal 10.8V Battery. 
  • A 3A Polyswitch, used as a circuit breaker mounted on the battery. 
  • A 4W Diesel Sound board, the circuit of which appeared in the Book “Electronics for Model Railways No 2” that I found on the internet as free download from “Talking Electronics” in Australia.

Note; This sound board is also available as a kit from “Talking Electronics” in Australia 
http://www.talkingelectronics.com/te_interactive_index.html
  • An 8 ohm 2.5Watt Speaker taken from an old laptop computer.

  • A Picaxe 08M2 microcontroller mounted on an interface board is used to delay the Transmitter (Tx) signal to the Electronic Speed Controller (ESC) so that the motor speed signal is delayed behind the Sound Card output; this allows the revs sound to build before the loco begins to move. 
Component locations; 
  • The Battery, ESC and Servo are mounted in the long hood.
  • The Receiver, Sound Card, Picaxe Interface board and Speaker are mounted in the cab.
Power Supply

The unregulated battery powers the Radio Control components, the sound board, Front and Rear Lights, and the Motor.

Battery Charging

  • Charging studs are mounted on the back buffer beam, for use with alligator clips.
  • These are switched in and out by a DPDT Centre Off switch which has three positions being “On”, “Off” and “Charge”. 
Functional Description of delay;

The PICAXE is used to provide a delay in the motor speed signal; this allows the revs to build up before the loco begins to move.

The throttle output of the RX feeds into pin1 (leg6) of the PICAXE and uses a PULSIN command to decode the pulses.

The PICAXE produces a PWM (not PWMOUT) voltage signal on pin4 (leg3), to control the throb rate of the sound board.

The speed O/P of the PICAXE is filtered by a 50ms RC circuit with large capacitor, to remember the required voltage during the approx 500ms scan time of the PICAXE.

The voltage outputted is not linear with throttle speed – it has a faster throb rate at lower speeds than a linear relationship would give – uses a LOOKUP table.

A second LOOKUP table provides the throb rate when slowing.

The voltage is fed to the 1-2 sec delay on the sound board to give the inertia effect of the diesel engine.

The decoded throttle speed signal in the PICAXE is delayed by around 1-2 sec and fed out as a PULSOUT command on pin2 (leg5) to the ESC without alteration, so the motor starts to move after the engine sound has increased.

The Turnigy TGY-20A Brushed ESC used provides the 5V needed for the Rx power, for the PICAXE board the power wires are split and the board inserted between the ECS and the Channel 3 pins of the Rx.  (Right stick up/down).

The ESC switches the Negative side while the battery positive is connected to the motor positive.

Output goes via the reversing switch. 

NOTE: The TX servo switch for the throttle must be in the “REV” position for it to work.

The PICAXE determines if the throttle signal is increasing or decreasing and sets the volume.

Pin0 controls the volume of the sound board via a transistor and a 1 uF capacitor.

Pin0 turns on a BC548 transistor for soft, which connects the 1uF capacitor to the volume control network.

Direction control and Lights

Direction control is done via a DPDT switch glued to a servo which controls motor direction and the lights.
The lights are two white LEDS and a dropping resistor connected across the motor contacts.
Depending on polarity the appropriate LED will light when the motor starts to drive i.e. lights come on when motor volts are high enough to cause them to light.
The servo plugs into Ch 1 – this is the right stick, left (reverse)/right (forward)

Modification of Diesel Sound Unit

  • Input “S” comes from the Sound PICAXE PWM output (5V max) smoothed by a 470k (R2) and 1uF (C3) mounted on the sound board. – (the 470k was 1M)
  • All the 9 ‘input’ diodes, except 1 to provide polarity protection, were removed
  • R2 changed from 1M to 470k
  • R3 removed because only 5V input for max speed. Gives 1.45ms period at idle and 0.55ms at full speed.
  • Changed C7 from 10uF to 0.033uF – ridiculously large in series with a 1M resistor and caused charging time problems at turn-on.
  • A 680K resistor was used for R11 (instead of 1M) to increase the volume.
  • Added 10nF in parallel with the supplied C2 22nF, giving a total of 33nF, for to slow idle.
  • Removed R7 used to give a turbo whine.
  • Changed R1 from 10 to 150ohm to help smooth the IC supply which is only about 1mA.
  • Added 1000pf across C8 (220pf) to try to reduce whistle from motor/ESC.
An aux input “H” for a horn, is made into the non-inverting pin of the LM380 it is not connected 
“V” is to control the volume - Pin0 turns on a BC548 (TR4) transistor for soft, which connects a 1uF capacitor across C5 on the sound board.
It feeds an 8 ohm 2.5Watt speaker mounted on the cab roof

Sound Card Schematic showing changes
Modified Sound Card Schematic
Block Diagram
Picaxe Delay Program

The program listed below is loaded into the 08M2 Picaxe chip



'Side Rod Diesel Sound card with inertia
'a program to take servo type pulses from a 2.4 GHz  Rx and control a diesel
'sound card AND motor speed using PULSOUT command feeding to Hobbyking ESC.

'THIS HAS INERTIA AS WELL AS DELAY
'no inertia below 50% speed when slowing, just delay.
'has instant stop when throttle set to zero.
'was error in line L112:  also added stoppedcounthigh to stop going loud at notch1 (L101:)
   
'***********************************************************************
'look for servo type pulses from Hobbyking Rx on pin 1
' these will be around 1.0-2.0 ms long
'measured in 10usec counts  ie 100-200 counts
'PULSIN pin,state,wordvariable - can sit 0.6 sec waiting for a signal !!!!!
'then output a PWM (not PWMOUT) signal (p4) to TE card via two RC delays   -
'50 ms for filtering the PWM and 1 sec for sound buildup
'create a 1 sec program delay, then output speed signal using PULSOUT command
'to an ESC (pin2). volume control out on pin 0
'+++++++++++++++++++++++++++++++++++++++++++++
'at turnon, assume throttle is set at min, so store this pulse length as the stoppedCount
'I measured it at 1.1 ms with trim centred = 110 counts
'then ASSUME max speed is  'MaxSpeedCount', 10us pulse counts. 
'measured at 1.85ms or 185 counts
' so Tx output is 0.75 ms from stopped to max.
'------------------------------------------------------------------
'measured Rx pulse widths in msec
   'Trim up Trim centred Trim down
'Zero speed (down)  1.2    1.16   
'Max speed (up)   1.9    1.80   
'-------------------------------------------------------------------
'PIN ALLOCATION
'pin 0 vol control output  LOW =loud  
'pin 1 throttle pulse input
'pin 2 motor OUTPUT pulses 
'pin 3  not used
'pin 4 sound control PWM voltage output
'---------------------------------------------------------------
symbol outsoundvolts=b0  'PWM signal out to TE board  0-255
symbol speedcount=b1  'value 0-6 for min to max speed for lookup table to
    'determine throb rate of TE board
symbol timecounts=w1  'the width of the pulse in 10 us counts. Must be a Word
    'even though <255
symbol stoppedCount=b4  'the No of 10us counts corresponding to stopped speed
    'and is a fn of the transmitter  between 1.0 and 1.2 ms
symbol powerstate=b5  '1= accel, 0=slowing
symbol delaytime =b6  'delay time for motor speed behind revs.Max 255 lines soft: and loud:
symbol stoppedCountHigh=b7 'stoppedspeed plus a couple to stop instant load at notch1.
'symbol MaxSpeedCount=b7    'width of pulses at max speed in 10us counts
symbol oldtimecounts1=b8 'last reading
symbol oldtimecounts2=b9 '2nd last reading
symbol oldtimecounts3=b10 '3rd last reading
symbol plusjitter=b11  
symbol minusjitter=b12
symbol outspeed=b13  'THIS SHOULD BE A WORD, but works OK !!!
symbol ACCstep =1  '  change in output voltage pulse per PULSOUT command for Inertia
symbol BRstep=1   '1 is max inertia
'symbol speedSpan=76  '64 is the measured difference from stopped to max in 10us pulses.
'    'try 72 or 76??
symbol jitter=1
symbol ACCdelay=50  'accel delay per cycle try 150 without inertia, 50 with.
symbol BRdelay=20  'slowing delay. try 50 without inertia and 20 with.
symbol outsoundDuration=15 'duration of PWM signal,in 5ms counts
'--------------------------------------------------------------------------
'debugging
'stoppedcount=110
'maxspeedcount=180
'goto start
'++++++++++++++++++++++++++++++++++++++++++++++
'MUST SEND A PULSOUT EVERY 50ms OR SO.  maybe 100ms OK?
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++
 HIGH 0 'mute the volume.
turnon:      'to Calibrate the Zero speed counts
   
 pause 100    'to allow Rx to lock on.
 pulsin 1,1,timecounts
 stoppedcount=timecounts   'this is stopped number of 10 us counts
 if stoppedCount>120 then turnon  'CRO measured stoppedcount=116
 if stoppedCount<90 then turnon  'wait for a valid signal
'NOTE: stoppedcount is the measured pulse width with throttle in bottom position
 'but speed does not start to increase until about another 5 counts with the
 'throttle up 4 notches.
 'OUTPUT 2    'necessary according to Manual
 'LOW 2     'initialize ESC
 stoppedcounthigh=stoppedcount+6  'to stopp going loud at throtle notch 1.
 outspeed=stoppedcount
PO1: PULSOUT 2,outspeed
 
'----------------------------------------------------------------------------

start:    'CREATES A TIME DELAY FOR MOTOR VOLTS of 3 x 2 x delaytime +75ms
    'the 3 comes from 3 old values stored.
    'the 2 comes from the double send in lines PO3 and PO4
    'the 75 ms is from the length of PWM pulse
    'AND an inertia effect set by the value of ACCstep / BRstep 
 oldtimecounts3=oldtimecounts2
 oldtimecounts2=oldtimecounts1
 oldtimecounts1=timecounts
 GOSUB getpulsewidth  'return with new timecounts value

L20: speedcount= timecounts-stoppedcount+10/12 'now 0-6 for throb lookup table
      
'now need to determine if slowing, to control volume and throb rate

L100: 'see climaxsoundV4.bas for ideas
 if timecounts<stoppedcounthigh then soft 'to stop going loud on start
 if oldtimecounts1<=stoppedcount  and timecounts>stoppedcountHigh then loud
 if timecounts>=oldtimecounts1 and timecounts> oldtimecounts2 then loud
 if timecounts<oldtimecounts1 and oldtimecounts1<=oldtimecounts2 then soft
 'no change in state, so
 goto L120
soft:   'also means slowing.
 'enable this line if no inertia
 'if timecounts>140 then L110 'below about 30% speed, reduce inertia
     'makes loco easier to drive when stopping

 'if speedcount>4 then L112 'leave it loud on 2nd top speed when slowing.
 delaytime=BRdelay  'NOTE  there is another 75ms delay in line 150
L110: HIGH 0
L112: powerstate=0

 goto L120
loud:     'also means accelerating.
 delaytime=ACCdelay
 LOW 0
 powerstate=1
L120: if powerstate=1 then L130 'goto accel
 'this is for slowing
 lookup speedcount,(0,0,50,100,180,230,255),outsoundvolts 'get revs for slowing

 goto PO2

L130: 'this is for accelerating
 'lookup speedcount, (0,80,120,160,200,230,255),outsoundvolts 'get revs for accel.
 lookup speedcount, (0,85,130,175,220,255,255),outsoundvolts 'get revs for accel.
PO2: gosub inert
 'output the sound voltage
L150: PWM 4,outsoundvolts,outsoundduration  'send to TE board for 75ms, via a 50ms TC
      'with C=47uF and the 470k+1uF  TC on TE board.
PO3: gosub inert
 PAUSE delaytime    'This can't be too long !!!!!!
PO4: gosub inert
 PAUSE delaytime
PO5: gosub inert

 goto start
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
getpulsewidth:'timecounts typically 110 to 185 counts

L300: pulsin 1,1,timecounts   'NB Just sits here waiting for pulse to arrive
      'reads 0 for no pulse in
PO6: PULSOUT 2, outspeed
L320: if timecounts<2 then NoInput  'no input pulse in 0.6 sec

 minusjitter=timecounts-jitter  
 if minusjitter<=stoppedCount then stopped 'to stop vol jitter when stopped
 plusjitter=timecounts+jitter  'this stops jittering when input pulses only vary by 'jitter' counts.

 if minusjitter=oldtimecounts1 or plusjitter=oldtimecounts1 then nochange
L400:
 RETURN 'with timecounts
NoInput: 'continues at same speed till gets good signal
 PULSOUT 2, outspeed
nochange:
 timecounts=oldtimecounts1
 return
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
stopped: 
 outspeed=stoppedcount
 PULSOUT 2, outspeed  'instant stop for emergency
 HIGH 0    'set it soft
 timecounts=stoppedcount
 oldtimecounts3=stoppedcount
 oldtimecounts2=stoppedcount
 oldtimecounts1=stoppedcount
 return  

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'inertia routine

Inert:
 PULSOUT 2,outspeed
 if outspeed=oldtimecounts3 then ret
 if outspeed<oldtimecounts3 then incr
 'so need to reduce output speed
 if outspeed<135 then noinertia   'approx 1/3 speed
 outspeed=outspeed-BRstep
 if outspeed>oldtimecounts3 then ret
 outspeed=oldtimecounts3
ret: return
noinertia:
 outspeed=oldtimecounts3
 return

incr: outspeed=outspeed+ACCstep
 if outspeed<oldtimecounts3 then ret
 outspeed=oldtimecounts3
 return
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++