PIC program description
General descriptionSchematic description
This small project is intended to add the flashing lights to an "analog" powered train. This circuit is battery powered and does not need electric contact to the tracks. Other important feature is the magnetic switch (reed bulb) for circuit on/off: thanks to this component the user does not fit in the model the on/off switch and has only to modify the model for flashing leds positioning. The very compact dimensions allows the user to fit the circuit in a Z, N or HO scale model.
This circuit is a perfect replacement for old LM3909 based led flashers with the improved capability to asynchronously flash the two leds.
The schematic is very simple and completely based on the PIC 12F629 microcontroller. This microcontroller has an internal 4MHz oscillator and is packaged in SOIC 8 pin for very compact realizations. The microcontroller is held in low power mode (sleep) until a interrupt from an external pin occurs. The closure of the reed bulb switch force the interrupt and is useful also for circuit switch off when the usage is ended. The two leds are connected via 470 ohm resistor for very low consumption; if the user needs more current for the leds, the resistor value can be consequently decreased.
With the shown components the sleep current is near to 0 (down 1uA) and the mean working current is about 100uA, for about 200 hours of usage.
The PIC program is very simple and is based on a main loop that flashes the two leds using a random generated seed.
When the PIC wakes up (for a switch of the reed bulb when the user move near to the bulb a magnet) the microcontroller counts the time for what the user activate the switch. This time is used for random number generation and in order to change the two led relative phase. During this period one of two leds is switched on (at 50% brightness) and remains in this state until the user activate the reed bulb.
After this initialization the two leds flashes asynchronously with a 1s period. The end of flashing can occur for two reasons: a) Timeout if the circuit flashes for 1 hour or if the user re-activate the reed bulb for at least 1 second.
The shut down procedure switch on (at 50% brightness) one led and go in sleep mode when the user deactivate the reed bulb (moving the magnet away) shutting off the two leds and the CPU.
All the parameters are specified in constant section for user tuning and easy modifying.
The first components that should be solded are the 0603 resistor for their heights and dimensions. Then the user should sold the medium battery holder, then the lateral holder for the second battery. The final component is the PIC and the reed bulb (in lateral or vertical position). The last components are the wires for leds connection. After the complete mounting the user can put the batteries in the holders.
Polarized component orientation : The battery holders must be oriented with the opening to the PCB edge (!), the PIC 1 pin is near to the first led anode connector. The two leds have the anode in the upper and mid pad of the J4 connector and the two cathods are shorted together in the bottom pad (see the assembly).
Model Trains >