Melaleuca station building banner

Site Navigation

Description

S&TR Home

Gallery Index

Links

Last updated Apr 10, 2006

TRACK and BATTERY LOCO RADIO CONTROL USING PICAXE CONTROLLERS AND UHF 'CAR DOOR' REMOTES.
Radio Control      Steam and Diesel Sound using PICAXE     


This description may be of use to those who are electronically minded. They will not allow a novice to build them.

The following is a general description which may allow you to design your own. [The program listings are at the end of this page.]

PICAXE based UHF Radio Controllers

Oatley Electronics has a 433 MHz transmitter and receiver pair with decoding for $12 each. It is called the Series V UHF and numbered Rx7 and Tx7. The transmitter needs 3 screws to assemble and has four buttons A, B, C and D. It looks like a 'car door remote'.It uses standard small cylindrical 12V battery. See pic at left
The receiver has 4 outputs as above and a VT (valid transmission) O/P. Outputs are normally low and go high when receiving. Rx works at 5V. It can be seen mounted vertically on the left of the circuit board shown at left and is not easily seen in the pic.

In conjunction with this radio link I am using a PICAXE-08 microcontroller to control the motor speed and direction. I am using these to control either track voltage or battery powered locos.
Loco speed/voltage is controlled by pulse width modulation, using a power MOSFET. Reversing is done using a relay.(the big black rectangle in pic.)

The Picaxe is programmed in a simple version of BASIC, using a small circuit connected to your PC, so that:-
Pressing and holding A (Accelerate) will slowly increase the track/motor voltage. If held for about 8 seconds the voltage will reach the maximum (provided by the supply/battery). If A is released at any time before max volts are reached, the voltage will remain at that level indefinitely.
Pressing and holding B (Brake) for about 6 seconds will reduce voltage to zero. If B is released at anytime, the voltage will remain at that level indefinitely.
. Pressing button C for about ½ a second will select one direction of travel (Clockwise?). Pressing D for ½ sec will select the other direction. These will work only if the speed is less than about 1/8 of max.
If C or D are pressed when the volts are greater than 1/8 max, this will result in an

Here is a typical schematic of the track power version. To use for loco battery power, just delete the rectifierand capacitor on input and use battery - email me if you want more info.
track power controller circuit


PICAXE Steam & Diesel Sound generator circuit

The Picaxe includes a white noise generator (SOUND command) which can be used to simulate both diesel engine and steam chuff sounds. While no-one will ever be able to say “ ah that’s an Alco”, they can provide a ‘different' sound from a small and cheap package. Click here to listen to the diesel, and here for the steam The basic circuit for both sounds is as follows. Only the program is changed to get the diesel or steam sound.
L1 refers to leg 1 of the Picaxe – ie pin1 in the usual parlance. R1 and the setting of the 10k pot are chosen so that the input voltage into leg 6 of the Picaxe, is 3.3V with the track voltage corresponding to max loco speed. A typical value for R1 would be 15k. Adjust the 10k pot setting to give max ‘chuff rate’ or diesel sound rate with the max track voltage you will use. The 10uF capacitor on leg 6 filters pulse controllers.
The sound appears at L5 (‘pin2’) and is fed into a small amplifier – LM386 in this case, but any could be used. I found that the diesel sound needs a higher gain for the same perceived volume, probably because it is a lower frequency. So you could use an LM380 or two LM386 in a bridge configuration for the diesel.
You can experiment with a resistor from pin 2 of the LM386 to 0V to change the ‘timbre’ of the steam sound. Note that the speaker output is really just a digital signal, so that a good amplifier is not needed. I have even used a 555 connected as a flip flop as a driver for a small speaker.

Simple STEAM Loco sound

[See program steamSound.bas at end of this section]
This is a very simple program of only 38 bytes. The steam chuff is just the white noise output from the SOUND command turned on and off at a rate determined by the voltage on leg 6, so it is a very ‘harsh’ sound with no attack or decay time. The sound can be varied by selecting different values in the SOUND command. When the loco is stopped there is a constant ‘hiss’.
SOUND 2, (255, time) is very harsh and SOUND 2, (249, time) is less so. The odd numbers give better sounds than the even numbers. Change the line labelled “Chuff: ” to experiment.
The 3 lines labelled times2: set the length of the chuff and the silent time between chuffs. If the max chuff rate is wrong for your situation you can adjust these. They are just simple equations that seem to work OK. Alternatively, you can use a LOOKUP command as shown in the following Diesel sound program.
Many more features can be added such as:
1. Having 3 chuffs of one sound and the 4th of a different, to simulate a loco with a valve timing problem. To try this, change the chuff: lines to
chuff: 
sound 2,(255,Ontime)		
Pause Offtime
sound 2,(255,Ontime)		
Pause Offtime
sound 2,(255,Ontime)		
Pause Offtime 
sound 2,(252,Ontime)		‘change sound of 4th chuff
Pause Offtime
	goto Nextread
Or you can have a different sound for every cylinder! Try values of 255,253,252,251 in the four Sound commands. If you have a 3 cylinder Shay, use 6 of the Sound commands.
2. Adding a ‘panting’ sound when stopped to simulate a compressor. Try this in line
stopped: 	
sound 2,(250,50)
Pause 20		
	 goto nextread

More Complicated Steam Sound

[see program for BIGsteamSound.bas at end of this section] This extends the above simple program to change the chuff sound when the loco is slowing This is done by storing the previous speed and changing the chuffsound number in the Sound command. To avoid instability when the speed is just on the borderline between two analogue values, the speed has to increase by 2 steps before the loader chuff is turned on again. It also adds a large hiss when it stops to simulate brakes exhaust.

DIESEL Loco sound

This is a more complicated program and provides:
1. An idling rumble sound, which then increases in rate as the speed (voltage) increases.
2. A horn that sounds twice as the loco starts to move.
3. If the speed is reduced, the sound reverts to the idle sound until the speed increases again. This is to represent the driver ‘shutting off’ and coasting. However, this feature is disabled for speeds less than about 40% of max so you can shunt around and the sound rate will change.
4. The horn sounds at random intervals while running – the time between is dependent on the random number generator and the speed of the loco. Sometimes there will be 2 or 3 horn blasts together – it just depends on the random number generator.
5. When the loco stops there is a loud hiss for a few seconds to represent the brake and then the idle sound commences. Generation of the diesel sound works on a similar principle to previously published circuits - a shift register is clocked at a speed dependant on the loco speed and the last two bits of the register are Ex-ORed and fed back to the input. I found that a 5-bit shift register sounds OK. This is easy to implement in code as a left shift of a register is just multiply a number by two (called ‘seed’ in program). The initial value for ‘seed’ greatly affects the sound – experiment and enjoy!
The ‘clocking speed’ is read from a lookup table and depends on the input speed/voltage. Because of memory limitations, there is not enough space to have 16 different clocking rates for the 16 input speeds. So I only use 6 steps, but this doesn’t seem to be noticeable.
The horn is simply a single note generated by the SOUND command – vary to your liking in lines labelled Horn1: and Horn2:
If the horn sounds too often, increase the value of 65500 in line labelled horn0:

As an aside, the 8bit random command in the PICAXE is not very random and virtually useless. It seems to repeat after only 12 steps. This why I have used a 16 bit word.


STEAMSOUND.bas
'Steam Loco sound generator with analogue speed input driver.
'G Hunter  Feb 05
'PICAXE-08

'simple on/off hissing sound (a bit harsh) with no amp modulation.

'the SOUND command only operates on periods of sound of 10 ms (or 12 ?)
  
'analogue input voltage on pin1,- arrange resistor divider to give 3.3 volts at max speed
'this gives 0-160 analogue values but in only 16 steps.

' at starting, need something like sound 2,(255,25) then Pause 200   = 2 Hz
'at max speed need  sound 2,(255,8) then Pause 20  = 10 Hz


'adc input is held in b1
'Pin1 is speed volts input
'pin2 is amplifier/speaker.


	symbol speed=b1		'input voltage 1-160 count
	symbol Ontime=b2		'length of hiss sound in 12ms periods
	symbol OFFtime=b3		'quiet time between hiss in ms
		
'-----------------------------------------------------------------------

	
NextRead: 
	   readADC 1,speed			'get the speed voltage
	   if speed <11 then stopped
  

	  'now do the chuffing !!!!!

times2: OFFtime=254-speed		'quiet time between chuffs		
	  Ontime=175-speed		'duration of chuff
	  ontime=ontime/25+5			
	  
	
chuff:  sound 2,(255,Ontime)		'or try 253 instead of 255
	  Pause Offtime
  	  goto Nextread


stopped: 	
	  sound 2,(250,50)		'stopped = quiet hissing sound  or try 240, 245 OR 249
	  goto nextread

	

BIGSTEAMSOUND.bas
More complicated Steam sound generator with analogue speed input driver.
'G Hunter Mar 05


'the SOUND command only operates on periods of sound of 10 ms (or 12 ?)
  
'analogue input voltage on pin1,- arrange resistor divider to give 3.3 volts at max speed
'this gives 0-160 analogue values but in only 16 steps.

' at starting, need something like sound 2,(255,25) then Pause 200   = 2 Hz
'at max speed need  sound 2,(255,8) then Pause 20  = 10 Hz

'assume adc input is held in b1
'Pin1 is speed volts input
'pin2 is speaker.

	symbol speed=b1		'input voltage 1-160 count
	symbol Ontime=b2		'length of hiss sound in 12ms periods
	symbol OFFtime=b3		'quiet time between hiss in ms
	symbol chuffsound=b4	'the number represent the hiss in SOUND command
					'usually 255 for loudest hiss.  245 is quiet hiss
	symbol OLDspeed=b5	'previous speed
	symbol speed2=b7		'oldspeed+10. used to stop instability when speed is
					'just overlapping two input steps.	
'-----------------------------------------------------------------------

	  OLDspeed=0


read2:  readADC 1,speed
	  speed=speed+5				'see notes at end
	  if speed <11 then stopped
	  if oldspeed=0 and speed>0 then accel	
L30:	  speed2=oldspeed+10
L35:	  if speed>speed2 then accel
L40:	  if speed<oldspeed then slowing
	  goto times2

slowing:oldspeed=speed+10		'+10 necessary
	  chuffsound=249			'mute the volume
	  goto times2	  
	  
accel:  oldspeed=speed-10		
	  chuffsound=255			'loud chuff sound


	'now do the chuffing !!!!!
times2: OFFtime=254-speed			
	  Ontime=175-speed		
	  ontime=ontime/25+5			
	  if speed<10 then stopped
	
chuff:  sound 2,(chuffsound,Ontime)
	  Pause Offtime
  	  goto read2


stopped: if oldspeed>10 then justStopped
	
	sound 2,(249,20)
	goto read2

justStopped:
	PAUSE 500
	sound 2,(255,200)	'exhaust brakes sound
	oldspeed=0
	goto read2





'NOTES: speed is increased by 5 to stop the hunting effect due to the sound ADC having 16.
'Sometimes the speed is on the borderline for the ADC and would change the hiss
'sound when not required.

'This program has been changed in lines L30-40 and accel: and slowing: so that 
'speed must increase/decrease by TWO steps to cause a change in the hiss sound.


DIESELSOUND.bas
' Simple Diesel engine sound 
' G Hunter Feb 05
' only 6 different STEPS of rate of sound between stopped and max speed.

 'constant "fast idle" when decelerating until speed falls below '60' or 40% of max
' double Horn blast on starting.
' Random single horn when running - every 2 mins at max speed, longer times at slower speeds.
' brake exhaust sound on stopping

'requires an analogue voltage on pin1 - 0 to 3.3V =max speed.='160'
' 5 stage shift register. bits 4 & 5 EXORed and fed back to input bit

	
	'pin2 is output to speaker
	'use b0 as the shift register
	
	'use b2 as ADC speed
	'use b3 as timer to determine rate of sound (pause).
	'use b4 as intermediate value for speed/10 

'++++++++++++++++++++++++++++++++++++++++++++
symbol oldspeed=b5		'speed last time looked at input. used to determine if
					'accelerating, slowing etc.
	
symbol DECEL=b7			'=1 if speed is falling. 0 means accelerating or const speed.
'word 4 is random number = bytes b8 & b9 used to sound horn 'randomly'

symbol speed=b2
symbol seed=b0
	 seed=56 			'initialize - can be any number except 0 and 255
					'53 is slow, 36 is fast, 56 is pulsy fast
					'4,9 are fast		5 is pulsy
			
	
start:seed=seed*2		'shift left 1 bit. RH bit0 is set to zero automatically

	if bit4<>bit5 then XORed	'do an EXOR on bits 4 & 5 of seed (b0)
	LOW 2					'spkr output
	bit0=1				'feedback to RH bit
	goto motSpeed


XORed:
	HIGH 2				'spkr output

	
MotSpeed:
	random w4				'for horn

	readadc 1,speed			'read speed into b2 - 15 steps of 'speed'
	if oldspeed=0 and speed>0 then Horn2

Horn0:if w4>65500 and speed>11 then Horn1	'65500 works every 2mins or so at max speed
						'sometimes get 2 or 3 blasts together -
						'just depends on random number generator.
	if oldspeed>speed then slowing
	if oldspeed=speed and decel=1 then slowing

   'so must be accelerating or at steady speed but was last accelerating
	
  
accel:	DECEL=0

loop:	oldspeed=speed
	
	b4=speed+30/31			'integer result converts 16 steps of speed to 6
	
table: 					'determine the 'clocking rate'
	lookup b4,(18,10,7,4,2,1,0),b3   	'idle + 6 steps of speed
					'only enough memory for 6 steps in lookup table

paus:	
	pause b3				
	goto start

Horn2:sound 2,(57,50)			'starting double horn blast
	pause 200
Horn1:sound 2,(57,150)
	oldspeed=speed
	goto loop


slowing:  
	DECEL=1
	if speed=0 and oldspeed>10 then justStopped
	if speed<60 THEN loop
	b3=8		     		'decelerating at higher speeds gives 
					'constant fast idle'
	oldspeed=speed
	goto paus

justStopped:
	PAUSE 500
	sound 2,(253,200)		'exhaust brakes sound.  try 249 for a quieter hiss
	goto loop


Top of Page | S&TR Home Page