This is an additional segment of my LED Clock project post.
The LED board cycle involves turning a row off, uploading data, and turning the row on. This means that each row would be on for less than 1/16th of the time at max brightness. The minimum time between row changes is limited by the calculations of what to display on the next row. This means that the brightness and the screen refresh rate are both limited by processor speed.
Test code was written with an Arduino, which runs at 16 MHz. Once the code was working I tried different clock speeds. 20 MHz showed no visible improvement on the LED brightness, but 8 MHz created a visible problem with the refresh rate.
Choosing a micro-controller
I originally wanted to use a 14 DIP ATtiny84, which has 12 I/O (11 if you keep RESET). Unfortunately its internal clock runs at 8 MHz, and incorporating an external clock gives me a requirement of 13 I/O. The ATtiny85 has an internal PLL that can create 16 MHz, which is really cool, but with 6 I/O it is not useful for this project.
I read some articles on potential alternatives with a low pin count. I eventually realized that I had no constraint on size, and an ATmega’s price is comparable. As a result I decided to go with the 28 pin ATmega328 and focus my energy on more important tasks.
Input knob type
My initial plan was to use a rotary encoder as my analog control. I ended up buying a poor quality encoder with lots of noise. I was able to make it effective by using two interrupt pins and some code. Unfortunately the ATmega328 only has two interrupt pins and I needed one for my 60 Hz clock in.
I was able to find a continuous potentiometer, and run my control using a simple analog in. The actual knob isn’t as nice, but it integrated into the system more readily.
Sensing a 120V AC line
According to the datasheet, the max pin voltage for an ATmega is 6V (5.5V operating with a pin allowances of ±0.5V). My solution to this problem was to use a photocoupler that I salvaged from a printer power supply. The way photocouplers work, is you have an LED that gets powered from one side. You then have a phototransistor on the other side, which is basically a light sensing switch.
My design was simple, create a voltage divider to power the photocoupler, and use that to drive my digital input. This worked great until I wanted to look at the waveform it was creating to debug with an oscilloscope.
A Lesson about Oscilliscopes
I had recently received an old CRT oscilloscope from work because they were going to toss it. One of the knobs was missing and the grounding pin of the power cord was broken off. I replaced the cord with a fresh one, and was scoping anything I found with a signal. I was like a kid with a new toy.
I hooked the leads up into my circuit, and as soon as I turned the power on – BANG. my photocoupler flew 2 feet up in the air while on fire, and bits of it slowly spiraled to the ground as I smelled the melting plastic of my $60 Arduino Mega.
It took a bit of investigating, but I finally discovered the problem from this video. With old oscilloscopes, the negative lead is actually tied directly to earth ground in order to reduce signal noise. I was accustomed to USB scopes which are floating, and clearly my associates at work valued floating leads as well. My oscilloscope now has its original power cord.