Speed/Voltage comparator:
The completed project will need to be able to control a locomotive at varying speeds over a test track to build a voltage/speed control table. To do this, track voltage would need be monitored while the locomotive is timed passing between two points. Using the formula Speed = Distance / Time we can then calculate the actual speed the train is moving. From there it is a simple step to further calculate scale speed. Armed with this information, it will be possible to limit the voltage to the rails in order to limit a locomotive to a maximum speed.
My initial thoughts were to make a long straight section of track with graduated markers along the side. I decided that a simpler approach would be to make an oval with a smaller sample area. Obviously the larger the sample area, the more accurate the data. For initial tests though, a small sample should suffice.
At first I'd envisaged using an infrared LED and receiver to detect when the train first passed. A timer would start and continue to run until a second iR beam was broken, a set distance away. This would require a 38Khz PWM signal to drive the iR LED, some filtering circuitry to increase the accuracy of the readings and lessen the chance of the receiver being triggered accidentally by natural of fluorescent lighting, and a lot more code than I was prepared to write. I decided to try a simpler approach using an Orange LED and an LDR. I just needed a way of mounting them accurately at a fixed distance with no chance of them moving ...
... never ever, ever, ever throw away your old Lego :D
I started by building a simple structure that would eventually house my LED's and LDR's. I test fitted it and made sure the loco could pass through without fouling on any part of the structure. As more was added it became apparent I could actually house a small PCB on the construction and keep some of the wiring off the breadboard. At this point I also decided to add two more LED's that would visually show me when the beams were being broken. That came in handy for fault finding later on. The PCB was designed with standoffs for all the major connections. The entire structure can be disassembled and the components all re-used as a result.
Initially I'd made a small shroud with heat-shrink tubing to channel the light from the LED to the LDR. The LDR's had been similarly fitted and it was very hard to get an adequate amount of light falling onto the sensor. You can see the LDR hood protruding from the bricks on the left, and the LED hood between the walls on the right. After a few static tests it was determined that the hood should come off the LED's for further testing. That worked well.
Another dry run was made with the structure re-assembled to check for clearances. It was then hooked up to a 16F84A and the code from the first Pot tests was used as a base since the method for reading the LDR was exactly the same. In fact, the circuit on the proto PCB was taken directly from the Pot project. When the light beam is broken, the value being read by the RCtime command will fall to zero. When a value less than one is read, the corresponding LED atop the structure is lit to show that the beam has been broken.
Once a single side of the unit was bench tested, the code was simply reused to test the other side. The entrance side will now be referred to as "Start" while the exit side will be known as "Stop." With the code recompiled and the chip flashed again, the bench tests proved satisfactory and it was time to trial it on the test track. At this point there is no timing code in place, just the two beams detecting whether or not there is an obstruction at either of them.
The next step will be to accurately measure the distance between the points where each beam is broken, then write a timing routine to count the difference between "Start" and "Stop" being initially broken. That will then be calculated into scale speed and displayed on the LCD.
After that, voltage monitoring/control will need to be implemented in order to build the speed table.
Edit: Okay, so I was thinking about this after I climbed into bed and I had to get up because I don't want to lose this thought. There seemed to be a delay from when I expected the beam was being tripped and when the appropriate indicator LED came on. It may just be an illusion but there's a simple way to see. If I hook up a small signal transistor to the output on each LDR and use that to drive an additional LED for both "Start" and "Stop", I'll have a good visual guide if there's any real delay. Keeping that in mind, it might be an idea to use the voltage drop on the LDR as a hardware interrupt to begin and end the timing sequence rather than actually using code to monitor and test the LDR condition. The timing is critical and this may make all the difference. Food for thought.
Tags: railway project
Current Mood: creative