The most advanced and sophisticated laser spirograph can be built only with programmable microcontroller.
Design of my spirograph is based on 8-bit microcontroller PIC18F1320 from Microchip.
PIC microcontroller implements software PWM generator with 3 independent outputs. Each output drives 2N7000 MOSFET (can be replaced with any suitable N-channel transistor with gate threshold voltage <5V). Fan is connected as load for MOSFET.
Device supports 5V and 12V fans with working current up to 200mA. Fan's voltage is selected by jumpers on board.
All PWM outputs generate signal of the same frequency but duty cycle (0-100%) can be set individually for each output.
There are two working modes, selected by toggle switch: manual and automatic.
In manual mode operator controls each fan individually by twisting corresponding potentiometer connected to analog input of microcontroller. PIC constantly reads analog inputs and modifies PWM signal so duty value is proportional to voltage on analog input.
In automatic mode microcontroller employs pseudo-random algorithm to calculate duty value for every fan. New PWM value is generated every 10 seconds.
After unit is switched into auto mode first time, PIC reads analog inputs connected to POTs and use this data as initial value for random generator, so by altering POTs settings before turning auto mode on, different initial patterns can be programmed.
There are two phases of auto mode: slow and fast. Each phase lasts for one minute.
During fast phase, microcontroller keeps PWM output unchanged for 10 sec and changes old duty value with new as soon as it's generated i.e. instantly.
During slow phase, after microcontroller has calculated new data it starts slowly increasing/decreasing duty value by 1 every 0.5 sec till current value becomes equal to newly generated then keeps it unchanged till new data is calculated.
Microcontroller stores current duty value in internal EEPROM every 3 min. Stored value is used as initial data for random generator after unit is powered up in auto mode. That feature lets microcontroller generate sequence of non repetitive unique patterns for a long time.
This laser spirograph is designed for home entertainment and intended to work with 5-10mW laser modules like this one. For this purpose controller contains LM317-based voltage regulator with adjustable output to provide power for laser module.
Electronic schematic is simple and controller can be assembled on a prototyping board (as shown below alpha version of controller)
|First quick prototype.|
but it's quite easy to make decent looking PCB as shown in this post.
|Controller assembled on a home-made PCB.|
Board is compact and light, so you don't need any brackets to secure it. Pots hold it perfectly.
|Laser spirograph. Inner setup.|
All technical notes such as
- PCB in PDF format;
- HEX file for PIC18F1320;
- C source code for CCS compiler.
can be downloaded from here.
Preprogrammed PIC18F1320, PCB, whole controller kit or assembled controller board available upon request.
To program chip, I use USB ICD2 programmer (bought it from eBay) and MPLAB IDE (free soft from Microchip.com).
|USB PIC programmer ICD2.|
PCB contains standard Microchip ICSP port (5-pins header) for programming purpose, also chip can be programmed by any socket programmer with proper software which supports PIC18.