I remember writing as a kid in the mid ’70s to an electronics magazine well-known in Italy, Nuova Elettronica, asking them to publish the project of a device to display music on a TV like on an oscilloscope. They did not reply but eventually they published the project. I’m not sure I’m the one who actually sprung them into designing the circuit but I was nonetheless compelled to build the circuit which of course worked great as expected. In my idea the line would have been horizontal but vertical appeared to be the most natural after reading the article.
The circuit was a clever mixture of triangular wave generators, comparators, monostables and flip-flops plus an RF generator to feed the TV’s antenna input.
Now that circuit is lost and the magazine gone into recycled paper but it remains one of my preferred.
It is now possible to replicate the circuit using a few components. Also, it is now well clear that a regular microcontroller like a PIC or an AVR provide the necessary speed and peripherals to do the job.
The circuit is very simple as this was my main target. I decided I would use one of the smallest AVRs I had, an ATtiny84. Physically small but large in memory : 8k FLASH is way larger than needed as my circuit fits 1/32th of that much. Anyways, just one 20MHz crystal, 5 capacitors, 4 resistors and one VGA connector are sufficient to generate a vertical line on a VGA monitor which swings left to right depending on the voltage at a micro’s input pin. Applying music at the pin the line dances at the music. A little bit kitschy ’70s prop.
This is a picture of the output without any input : a well steady line is displayed, not bad for software timing.
I chose to go on a VGA instead of a regular TV because it is a single standard all over the world (no 60Hz vs 50Hz issue) and it is not interlaced (like TVs) which would have added another layer of difficulty.
This is the circuit. It is not mounted on a PCB : read further.
The code is entirely in assembler and interrupt driven.
Assembler source code and HEX files are here
Horizontal synchronism is generated by the internal PWM generator at Timer 1. Horizontal Synch is also used as the timebase for Vertical Synchronization. Also, the input voltage coming from the audio input is read by channel 0 of the internal ADC at the beginning of every line, then a new conversion is started over to give the ADC the time of a full Horizontal line to make a new conversion.
Resolution required is low and as few as 7 bits are sufficient to span the monitor horizontally. The overall effect is just fine anyways.
The only tricky part is the interrupt routine called at the start of every horizontal line :
In case it is the last (628th line at 800×600, 60Hz) line, a Vertical sync pulse is started with the aid of a counter. The pulse is stopped after a 4 lines’ duration has passed. This is the Vertical sync pulse wich causes the vertical retrace and during this period no out should be put on the RGB (colour) outputs (the reti instruction).
In case it is not the vertcal sync occurrence, the ADC input value is converted into a delay after that output at the RGB (Red only, actually) is set to VCC for one single instruction cycle. This time is the smallest possible yet a well visible red spot is displayed on the screen.
The schematic is herebelow. Download it in higher resolution clicking on the image to go to Flickr, then select ‘all sizes’.
The input at the ADC must be 0-5Vcc so it is offset at 2.5V with a resistive network. A capacitor cancels the DC component at the input so that audio is converted to an AC offset which adds/subtracts from the 2.5Vcc DC offset.
In case input level is not sufficient I added a simple op-amp preamp suitable for 5V operation. The requirements called for a rail-to-rail op amp that could be powered from as low as 5v and provide an output of 0/5V. Also it had to be powered from one single supply rail. National Semiconductors LMC6462 was my choice. Other components are fine as long as they meet the three requirements above.
The preamp is designed to be driven by an electret microphone of the kind used in cell phones. In case a regular external source like a magnetic microphone or CD player can be connected at the positive lead of C1 and ground. R2 should be removed also.
A filter can be added placing a .1uF to 1uF capacitor in parallel to R5.
I mounted the two circuits on regular perfboard but wanted to add some finesse, so I glued some black and red cardboard on the perfboard (component side, of course!) to hide the holes and just opened the ones I needed with a needle. Next time I’ll print these paper mask adding components references, some logo and legend at the connectors and variable resistor.
This is the circuit completed with the pre amp. Power supply comes from a 5Vcc wall adapter.
Finally a video of the thing in action.
As usual I take the videos with my Olympus camera, probably not the best mean.
The sources I used to understand are endless, probably too many and not always in agreement to each another: probably they all are right as there’s room for tolerance in timing.
I want to mention the most important: Alberto Ricci Bitti whose articles helped to shed some light on VGA with his award winning video projects (www.riccibitti.com), Daniel Ciocea for the same reason (check his VGA monitor tester at http://www.eosystems.ro/deogen/deogen_en.html) and the infinite list of PIC pongs .
Also the reference pages on VGA at http://www.epanorama.net/ was chosen as the standard since same resolutions happen to be given different different parameters on different internet sources.
Update (21/03/09) : now this thing runs on Arduino also, read at bottom.
This is a simple project of a sundial wherein the pinion is replaced by a line LASER I took from a LASER level. The LASER is mounted on a RC servo which in turn is driven by a micro controller. The micro controller keeps the time and turns the RC servo accordingly.
Very basic in design it does exactly what I wanted and has as few parts as I could.
The micro controller is an Atmel Attiny24 with crystal for better accuracy. The internal RC oscillator could be calibrated but in the end the precision can be achieved from a crystal quartz only.
The schematic is very simple, just the micro with crystal and capacitors, the LASER and the transistor necessary to drive it, the servo. The power supply comes from a 5Volt wall adapter.
The micro controller runs a real time clock. Time is converted into minutes from 1:00 hours and converted in PWM pulse which is suitable to drive an RC servo. The source code is well commented, I’d say, and can be easily followed to understand how it works. In case, just comment and ask.
J4 is necessary to program the micro with the In Circuit Serial Programming faciliy like the one provided by the AVR Dragon debugger. If you have the micro already programmed (by a friend, say) you don’t need to mount that. Just be careful not to leave unconnected the R2, J2 and Pin 7 node also…
Upon power on the servo swings from about mid position of the sundial to 1:00 hours. Short pins 5-6 of J1 to make the sundial advance 1 hour at a time. Let it go a few times from 1:00 to 12:00 to see the rotation span. Then remove the short when the LASER points to the right hour.
To set the minutes it might be easier to set the time at the exact hours as the minutes are set to 0 whenever hours are set. Otherwise just short pins 3-4 of J1 counting 2 every second and remove the short when at the correct minute.
Shorting pins 1-2 adds some life to the sundial and makes it count just the seconds. Hypnotic initially, then pointless.
Shorting pins 7-8 makes the LASER on continuously, otherwise it blinks every second, like in the video below.
The circuit and software can be modified to display different things like a voltage at an analog input of the micro making a LASER analog meter. Or to make something like a LASER chronulator.
More of these circuits can be superimposed to display different values on the dial.
This is a picture of the thing.
The servo I used is a Hitec HS-300BB, a pretty good one I happened to have in a drawer. Any other servo would do, the rotation span being probably a little bit different. It can be adjusted with the SERVO_MIN and SERVO_MAX defines but recompiling would be necessary.
I did not use a PCB, I actually built an UV bed to make PCBs but I never get to the point of actually making one…in case : http://www.instructables.com/id/The-return-of-the-dead-flatbed-scanner/
The pictures show how I attached the LASER to the RC servo : an L-shaped piece of Aluminum, a few tiny screws and a teflon fastener did the job easily. The tricky part is to make the lower end of the LASER line aligned with the center of the rotation of the servo. Anyways, misalignment might give some interesting visual effects when the LASER line does not rotate along one of its end but around a point somewhere in between like the hand of a speedometer. Just experiment.
The software.
It is written in C and compiled and debugged in AVR Studio. I debugged the code with the AVR Dragon which uses the In-circuit debugging capabilities of the ATTiny24.
The code is commented and should be readable and modifiable as desired in any case a few comments follow.
#define F_CPU 2457600UL // crystal frequency
#define PWM_TOP F_CPU/60 // == 40960 is TOP count for timer 0 (goes into OCR0A)
These pre-compiler instructions define the frequency of the crystal and the value to the placed in the OCR1A register which is going to be the maximum count for timer1 before resetting to zero. We want the PWM frequency to be 60Hz. We are using these 60Hz pulses as the time base for the real time clock also.
The following lines set up Timer1 with fast PWM, no prescaler (that is, the crystal frequency goes straight into Timer1), and PWM compare output is on OC1B pin (read on)
TCCR1A = _BV(WGM11) | _BV(WGM10) | _BV(COM1B1);
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);
OCR1A = PWM_TOP; // PWM freq = 60Hz
Timer1 now runs from 0 to PWM_TOP which happens 60 times every second (2457600/40960)
The instructions above also make the output pin OC1B high when the counter is below OCR1A and zero otherwise (PWM compare). This is PWM : changing the value in OCR1B from 0 to PWM_TOP makes the duty cycle output from 0% to 100% at the PWM frequency which do not change : 60 pulses every second, the pulses are simply thinner or larger.
The exact meaning will more clear when checked with the datasheet of the ATTiny24.
The following instruction places the servo at OCR1B output halfway between the maximum and minimum position of the servo.
OCR1B = (SERVO_MAX + SERVO_MIN) / 2;
This is not 50% PWM duty cycle, as the servo does rotate from min to max with pulses smaller than 50%, that’s why I defined SERVO_MAX and SERVO_MIN based on the the length of the pulses that place the servo at maximum or minimum:
#define SERVO_MAX PWM_TOP*1.65/(1000/60) // max rotation is at 2.35ms pulse
#define SERVO_MIN PWM_TOP*0.75/(1000/60) // min rotation is at 0.70ms pulse
Now I want the timer overflow to be used also as the timebase for the real time clock :
TIMSK1 = _BV(TOIE1); // enable timer overflow (for real time clock)
sei(); // enable global interrupts
Now every 1/60th of a second the following routine is called :
ISR(TIM1_OVF_vect) { … }
This routine does a number of things :
It counts the real time, 60 times1/60th of a second makes one full second elapsed, so the counter of seconds is incremented together with minutes and hours if required.
It also blinks the LASER for 1/10th of a second every second unless the relevant pin short strips shorted,in which case the LASER is always on.
This routine evaluates also the position to be given to the servo to make it rotate as needed. To do so the time is converted into total minutes elapsed from time 1:00 and the result scaled into the range SERVO_MIN to SERVO_MAX.
servo_pos = servo_min + ((hour-1)*60+min)*((servo_max-servo_min)/(11*60+59));
Shorting JUMP_0 makes the servo display the seconds only (9 to 59) thus the calculation as of above is made on current seconds only and minutes/hours disregarded :
servo_pos = servo_min + sec*((servo_max-servo_min)/59);
The following places the servo in the mirror position to make the LASER rotate clockwise :
OCR1B = servo_min+servo_max-servo_pos; // clockwise
// OCR1B = servo_pos; // counter clockwise (commented out)
If needed the first line can be commented out and the double ‘//’ removed from the second line : this would make (after compiling and downloading to the micro) the servo run counter clockwise.
Finally the routine also checks pin short strips for time set and sets hours and minutes if required. Minutes advance 1 every half a second while hours once per second. Removing the shorts resume regular clock display.
If you are going to modify the and recompile with AVR Studio with AVRGCC, the C compiler, don’t forget to set the fuses to External Crystal mode 0.9 to 3MHz, no watchdog, x8 clock divider disabled. All other fuses should be default.
You can see a video of the sundial below. Please trust me when I say that the light pulses much better than in the video : the bad flicker or disappearing light is just caused by low frame rate, poor camera ( and poor operator ? ). I should have shot the video with the LASER always on. Now I removed the roman lettering from my living room as my sweet half was showing some impatience.
Finally, this is a picture of a real sundial built around 1930 at Tripoli, Libya, I saw recently. Far better than the ones I used to improvise on summertime when I was a kid and didn’t mind melting under the Summer sun.
For questions or comments or anything else, just write, If you build your own, send pictures.
The hex file ready to be burnt into the microcontroller is here, the C source code is here.
The schematic for Arduino is herebelow, click for a larger view (on Flickr) :
The sketch needs the MsTimer2 library you can download from Arduino playground.
…and this one is the sketch to be loaded on Arduino.
Ciao
Alessandro












