BCM and Exponential Duty Cycle
PWM and Linear Duty Cycle
Having seen great success with my Larson Scanner I wanted to look around and see if there was room for improvement. I want to make it expandable and I knew I needed to work on the timing to get enough clock cycles out of the interrupts to make using shift registers feasible. Joby Taffey left a comment about his project which uses Binary Coded Modulation instead of PWM as a way to dim the LEDs. This turns out to be a fantastic method as it provides superb fading, just like PWM, but it takes far fewer clock cycles to achieve.
Previously I had read this fantastic tutorial on BCM but never tried it myself. It only took me about 60 minutes to whip up my own version (I had a nasty bug that took me 45 minutes to hunt down) since the hardware was already set up for me.
I’m going to be writing more about the change over to Binary Coded Modulation soon, and about using it with shift registers. But I wanted to check in about one big improvement: getting away from linear duty-cycle. You can see in the image on the right, the PWM levels on my original project are not very evenly distributed. The four or six LEDs on the right appear to be at the same brightness level.
Now look at the image on the left. Yes, it’s using BCM instead of PWM, but that’s not the reason for the improvement in the consistency of the intensity levels. It seems our eyes are not great at distinguishing between small intensity changes of a bright light source. By using a more exponential duty-cycle range (smaller steps when the LED is dim, larger steps when it is bright) we can make the intensity appear more uniformed over the 8 levels shown. Really all I did was start at 0x01 and double the value for each LED until I got to 0x80 for the brightest one in this picture. This is a good lesson to learn and I’ll be using the concept often in the future.
For those interested, here’s my code for the BCM example above. But like I said, I’m working on expanding the Larson Scanner using the concept so look for that post in the near future.
I’ve been hard at working coding my own Larson Scanner. This is the iconic sweeping light seen in the Cylons on Battlestar Gallactica or on the front of KITT, the car from Knight Rider.
As I discussed in my previous post, the thing that makes these look neat is the fading tail that chases the brightest light. Originally that was accomplished with capacitors which caused the light to fade as they discharged. I implemented the same concept, using a microcontroller and pulse-width modulation to manage the fading.
After the break I’ll go through the development process and share the code. I did this using an AVR microcontroller but you can use any chip you want. The gist of my process is this:
- Develop software (interrupt) based pulse-width modulation
- Write a function to monitor PWM values and automatically subtract from those over time to cause automatic fading.
- Use a buffer to track which LED is ‘active’ and do not fade that one. As soon as that buffer is shifted the old ‘active’ diode will start to fade.
Simple, right? Here’s a video overview to convince you:
And of course you’ll want to look at the most recent code.
Okay, it’s time to make a realistic Larson Scanner. You may know it as a Cylon Eye from Battlestar Gallactica or the lights on the front of KITT, the car in Knight Rider. It’s a popular project because it looks cool, but I’ve seen (and built) a ton of lousy imitations. What makes the original so interesting is that the bright tracking light leaves a fading tale behind it. That’s a bit more work to implement, but I’m up for the challenge. Update: check out the complete project.
After the break I embedded a video of the Larson Scanner from Knight Rider. You can pause it to get an idea of what’s going on here. The brightest light is always on the leading edge, the rest fade with time.
So my implementation will happen in a couple of stages:
- Write some code to drive a PWM signal on the pins of an AVR microcontroller
- Write some code to automatically fade an LED once the focus has left it
- Write some code to change where the focus is on a row of LEDs