I have a routine for counting N-Scale model railroad axles and speed among other things.
The East or West routine starts when a wheel set is detected from either direction of travel.
It measures elapsed time until the same wheel set is detected at the end of a 24 inch timing gate
and uses the elapsed time to index into a speed table.
The axle count is set to 1 when the timing gate is entered and then axles are counted when
the second and following wheel sets are detected at the end of the timing gate. The distance between
two wheel sets on the same truck is 0.45 inches which give 55 milliseconds time between wheel sets at a scale speed of 73mph.
I sometimes get one extra count with any number of axles. I think the first wheel set is triggering
the interrupt routine. I think I need some delay between line 14 and line 15 but how much delay.
I think the cycle time for the instructions in line 8 through line 15 is about 10 milliseconds but I don't
know how to measure that. I would feel safe including a delay of about 90% of the 55 milliseconds
between wheel sets.
Thanks for any suggestions for improvements and maybe some way to measure those instruction cycles.
Al
The East or West routine starts when a wheel set is detected from either direction of travel.
It measures elapsed time until the same wheel set is detected at the end of a 24 inch timing gate
and uses the elapsed time to index into a speed table.
The axle count is set to 1 when the timing gate is entered and then axles are counted when
the second and following wheel sets are detected at the end of the timing gate. The distance between
two wheel sets on the same truck is 0.45 inches which give 55 milliseconds time between wheel sets at a scale speed of 73mph.
I sometimes get one extra count with any number of axles. I think the first wheel set is triggering
the interrupt routine. I think I need some delay between line 14 and line 15 but how much delay.
I think the cycle time for the instructions in line 8 through line 15 is about 10 milliseconds but I don't
know how to measure that. I would feel safe including a delay of about 90% of the 55 milliseconds
between wheel sets.
Thanks for any suggestions for improvements and maybe some way to measure those instruction cycles.
Al
Code:
1 Start:
2 setfreq m32
3 low b.5 'disble display
4 setint %00000000,%00000000
5 cnt = 1 ;number of axles
6 cont:
7 if pinc.2 = 1 then east ; if pinc.2 high train detected from east direction
8 if pinc.1 = 0 then cont
9 west: ;if pin c.1 high train detected from west direction
10 time = 0
11 dir = 1
12 contw:
13 if pinc.2 <> 1 then contw
14 et = time ;et is used to index into a speed table
15 setint %00000100,%00000100 ;set int on east
16 for b5 = 0 to 30 ;routine
17 pause 100 ;to continue
18 next b5 ;checking axles until time expires ie, no more axles to count
19 goto calc
east: same as west routine except for setting int
.
.
.
Calc:
;calculations and display of the results routines
goto start
end
interrupt:
if pinc.1 = 1 or pinc.2 = 1 then interrupt
inc cnt
if dir = 0 then
setint %00000010,%00000010 ;set interrupt on west
else
setint %00000100,%00000100 ;set interrupt on east
endif
b5 = 0
return
Last edited: