18m2 Trying to make a Axle counter help?

Thunns

New Member
Hello All. I'm abit of a Picaxe Newbie, iv only made one circuit so far so please bare with me :eek:

I'm Currently trying to code a 18M2 to work as a Axle counter to control a signal at a local miniature railway. If any one could help it would be very much appreciated.

What I'm after is the Picaxe 18M2 to count a number of input pulses from 0 which will then set a output to high when count number is higher than 0. (Pulses to be triggered by passing train axles e.g. 1 small Train 2 pulses or one large train 6 pulses)

And then id like a different input to be able to count the number of pulses from the earlier input back down to 0 then once the count number is back to 0 it sets the output back to off.

then starts the process again. Also could there be the option of adding a reset button if any miss counting happens.

I'm thinking of using Inductive proximity sensors switches to create the pulses from the detecting of passing trains.

If someone feels they know a program/circuit that could achieve what I'm trying to create please let me know.
 
Last edited:

stan74

Senior Member
What I'm after is the Picaxe 18M2 to count a number of input pulses from 0 which will then set a output to high when count number is higher than 0.
ie 1 count
And then id like a different input to be able to count the number of pulses from the earlier input back down to 0 then once the count number is back to 0 it sets the output back to off.
ie 1 count
then starts the process again. Also could there be the option of adding a reset button if any miss counting happens.
why reset,only 1 count?
 

Thunns

New Member
Thanks for reply Stan, I edited the original post as it wasn't clear on the count being how many Axles of the train passing said sensor, I hope make a little more sense, thanks
 

stan74

Senior Member
Hmm. well a generic count from any input not 0 or off is just wait for it to go on or 1.. that's your init or start then check it's gone off...else train crashed,gone on strike what ever,
then now wait till sensor gives input,inc count,wait till no input then loop until no more changes to input in x cycles.
You got to break it down to a simple flow chart yourself 1st before coding sorry.
 

Dartmoor

Member
This might work (seems to simulate OK)?
Attached is screenshot of flowchart.
Below is automated messy translation to basic.
Start loop reads input C.0 and increments varA (upper limit of 6)
Start1 loop reads input C.1 and decreases varA (lower limit of 0)
Start3 loop sets output B.7 if varA=0, else output B.7 low.

Axle Counter1.png

Code:
'BASIC converted from flowchart:
'D:\Users\Dave\Documents\Picaxe\Axle Counter1.plf
'Converted  2017-08-09 at 00:51:27

{ ;Symbols
symbol varA = b0
symbol varB = b1
symbol varC = b2
symbol varD = b3
symbol varE = b4
symbol varF = b5
symbol varG = b6
symbol varH = b7
symbol varI = b8
symbol varJ = b9
symbol varK = b10
symbol varL = b11
symbol varM = b12
symbol varN = b13
symbol varO = b14
symbol varP = b15
symbol varQ = b16
symbol varR = b17
symbol varS = b18
symbol varT = b19
symbol varU = b20
symbol varV = b21
symbol varTEMPBYTE1 = b22
symbol varTEMPBYTE2 = b23
symbol varTEMPBYTE3 = b24
symbol varTEMPBYTE4 = b25
symbol varTEMPBYTE5 = b26
symbol varTEMPBYTE6 = b27
symbol varTEMPWORD1 = w11
symbol varTEMPWORD2 = w12
symbol varTEMPWORD3 = w13
}


main:
	let dirsB = 255
	let dirsC = 8

Cell_7_4:
	if pinC.0=1 then

		goto Cell_7_6
	end if
	goto Cell_7_4

Cell_7_6:
	if varA < 6 then
		goto Cell_7_8
	end if
	goto Cell_7_4

Cell_7_8:
	inc varA
Cell_7_10:
	if pinC.0=0 then

		goto Cell_7_4
	end if
	goto Cell_7_10

start2:

Cell_13_6:
	if varA = 0 then
		goto Cell_16_6
	end if
	low B.7

	goto Cell_13_6

Cell_16_6:
	high B.7

	goto Cell_13_6

start1:

Cell_10_4:
	if pinC.0=0 AND pinC.1=1 then

		goto Cell_10_6
	end if
	goto Cell_10_4

Cell_10_6:
	if varA > 0 then
		goto Cell_10_8
	end if
	goto Cell_10_4

Cell_10_8:
	dec varA
Cell_10_10:
	if pinC.1=0 then

		goto Cell_10_4
	end if
	goto Cell_10_10


#no_data	'reduce download time
 

Peter M

Senior Member
sounds like you are trying to do a level crossing.. count the cars in and then count them out again..(to verify all have crossed)
if that be the case you could maybe just sense when train is over top of the in coming sensor perhaps IR, and then when it clears a second sensor on the outgoing side. may be simpler to set up than an inductive sensor as couplings may give false triggering etc.
 

Thunns

New Member
sounds like you are trying to do a level crossing.. count the cars in and then count them out again..(to verify all have crossed)
if that be the case you could maybe just sense when train is over top of the in coming sensor perhaps IR, and then when it clears a second sensor on the outgoing side. may be simpler to set up than an inductive sensor as couplings may give false triggering etc.

Yeah I guess you could use it for a crossing also, but this is more for a signalling block section, so it counts how many cars go in, turns signal to red, then counts how many come back out if it's all of them the signal goes back green &#128077;

I was going to use the sensors points at the flange of the wheel,
 

Thunns

New Member
This might work (seems to simulate OK)?
Attached is screenshot of flowchart.
Below is automated messy translation to basic.
Start loop reads input C.0 and increments varA (upper limit of 6)
Start1 loop reads input C.1 and decreases varA (lower limit of 0)
Start3 loop sets output B.7 if varA=0, else output B.7 low.

View attachment 21433

Code:
'BASIC converted from flowchart:
'D:\Users\Dave\Documents\Picaxe\Axle Counter1.plf
'Converted  2017-08-09 at 00:51:27

{ ;Symbols
symbol varA = b0
symbol varB = b1
symbol varC = b2
symbol varD = b3
symbol varE = b4
symbol varF = b5
symbol varG = b6
symbol varH = b7
symbol varI = b8
symbol varJ = b9
symbol varK = b10
symbol varL = b11
symbol varM = b12
symbol varN = b13
symbol varO = b14
symbol varP = b15
symbol varQ = b16
symbol varR = b17
symbol varS = b18
symbol varT = b19
symbol varU = b20
symbol varV = b21
symbol varTEMPBYTE1 = b22
symbol varTEMPBYTE2 = b23
symbol varTEMPBYTE3 = b24
symbol varTEMPBYTE4 = b25
symbol varTEMPBYTE5 = b26
symbol varTEMPBYTE6 = b27
symbol varTEMPWORD1 = w11
symbol varTEMPWORD2 = w12
symbol varTEMPWORD3 = w13
}


main:
	let dirsB = 255
	let dirsC = 8

Cell_7_4:
	if pinC.0=1 then

		goto Cell_7_6
	end if
	goto Cell_7_4

Cell_7_6:
	if varA < 6 then
		goto Cell_7_8
	end if
	goto Cell_7_4

Cell_7_8:
	inc varA
Cell_7_10:
	if pinC.0=0 then

		goto Cell_7_4
	end if
	goto Cell_7_10

start2:

Cell_13_6:
	if varA = 0 then
		goto Cell_16_6
	end if
	low B.7

	goto Cell_13_6

Cell_16_6:
	high B.7

	goto Cell_13_6

start1:

Cell_10_4:
	if pinC.0=0 AND pinC.1=1 then

		goto Cell_10_6
	end if
	goto Cell_10_4

Cell_10_6:
	if varA > 0 then
		goto Cell_10_8
	end if
	goto Cell_10_4

Cell_10_8:
	dec varA
Cell_10_10:
	if pinC.1=0 then

		goto Cell_10_4
	end if
	goto Cell_10_10


#no_data	'reduce download time

Looks good! Il make a curcuit up and test it out!! Thanks mate!
 

Dartmoor

Member
I think the "Inductive proximity sensor switches" may be the biggest challenge here?
They work better with a magnet. Steel / cast iron wheels will work but need to get within about 2mm.
On a typical 5 or 7.25 inch gauge railway the flange depth can vary by more than that?
Have fun!

Ultrasonic sensors, magnet & reed switch or a short isolated piece of rail all work.
Peter M suggested IR in post#7 which could work. I have also seen a design (probably this forum?) using 2 LDR's, one between the rails & one away from the track. The picaxe looks for the difference between the two (only works in during the day!).
Microswitches are unreliable outdoors.

Probably gone too deep now.
 

Thunns

New Member
I think the "Inductive proximity sensor switches" may be the biggest challenge here?
They work better with a magnet. Steel / cast iron wheels will work but need to get within about 2mm.
On a typical 5 or 7.25 inch gauge railway the flange depth can vary by more than that?
Have fun!

Ultrasonic sensors, magnet & reed switch or a short isolated piece of rail all work.
Peter M suggested IR in post#7 which could work. I have also seen a design (probably this forum?) using 2 LDR's, one between the rails & one away from the track. The picaxe looks for the difference between the two (only works in during the day!).
Microswitches are unreliable outdoors.

Probably gone too deep now.
Not too deep at all mate!! This is for a 7 1/4 gauge railway. The sensor I picked up said it had a range of 8mm but time will tell with that! We used a waterproof micro switch to latch a relay which was fine, but I thought that might give me switch Bouce so I wanted to avoid them!

Thanks again for your help buddy
 
Top