I know that each of the output pins on my parallel port may be on (+5v)or off (0v)
but how can i then use these to create a variable voltage (0v-12v) sutiable for a train set?
Probably the "simplest" thing to do is to use the output byte as the terminal count for a PWM circuit. Run an 8-bit counter continuously, compare the output count to the byte coming from the parallel port, then feed that comparator
output to a power transistor controlling the 12V power (you're NOT getting 12V power from your parallel port.). Just multiply your refresh frequency by 256 to find your counter input rate.
In other words, you have a counter which runs from 0-255 continuously and back to zero. When the count is less than the parallel port value, you'll get a 0 or +V output, which will change to/from 0 when then count exceeds the value, until the count reaches 255, then it will switch back. The proportion of the "on" time is the proportion of the current you'll get. A value of 127 will give you approximately half the power, etc.
You may want to run your comparator output through an opto-isolator, to keep the power supplies separate. You can probably run your counter and comparator from your computer supply without problem, but the 12V to run the train should be on a separate circuit.
Surely there is a model train special interest group who could supply you schematics and parts lists for such a controller!?!?!?
Disclosure: I work for this company.
If you can use the USB port instead of the parallel port, then the Teleo sytem by MakingThings will accomplish this with a couple of off-the-shelf modules: A USB Translator gets from your computer to the Teleo Network, then a Motor Controller module gives you a full H-bridge controller at either 2 Amps or 10 Amps of up to 30 volts DC.
If you prefer the parallel port, we could design a custom interface for you.
If you have any questions feel free to contact me, probably offline as this is perhaps off-topic for this group.
You will need additional hardware in any case.
--most simple: switch a pin on and off with variable duty cycle. Filter the squarewave to get a DC average. Requires exact software timing.
--also simple: Use multiple pins. Output a bit pattern representing a number. Connect an R/2R network to them. Needs all port output pins for just one value.
-- Connect real DACs. Use some address logic and latches to realize multiple outputs.
Finally, all these solutions would need an amplifier stage and additional power supply to achieve 12V output.