Close
0%
0%

Christophanous Radiance Modulator, Model 114B

Precision manual PWM creates visually appealing light patterns in Christmas tree star made from retrofitted Ikea fiber optic light fixture.

Similar projects worth following
248 views
CRM 114B

Perusing the aisles of Ikea, probably 4-5 years ago, I ran across a STRALA fiber optic light fixture (since discontinued) for $5. I couldn't resist. The STRALA made its way into my bottomless box of unfinished/incomplete/never-started ideas ... until Christmas 2016. The hackaday 1kB Challenge seemed like the perfect justification to finally put the STRALA to good use.

This project demonstrates how precision manual PWM can compensate for the non-linearity of a human's perception of light intensity, creating multiple visually appealing light patterns, all within 1kB of program space. The application was a retrofit of an Ikea light fixture for use as a Christmas tree star, and the user controls were fitted into a professional-looking package made with common tools and a shoestring budget.


Non-Linearity of Human Perception

A human's perception of light intensity is non-linear. As an example, the perceived difference between 1% and 2% duty cycle lights is much greater than between 99% and 100%. The result when increasing standard PWM values for lighting is the light will ramp up to almost full intensity very quickly and subsequently only gradually increase in intensity.

To compensate for this, an algorithm is required that increments the intensity value with small steps on the low end and larger steps on the high end--an exponential algorithm. One obvious solution would be iteratively using the following:

Seeing as the target device (ATtiny2313A--I had on hand and am familiar with) doesn't have a multiply instruction and that a goal was to keep the program space usage to 1kB, this obvious solution would not meet the project requirements. Instead, a less program space intensive algorithm was devised and used. Counting through consecutive values while multiplying by two (a left bit-shift) every 16 counts results in an approximation of an exponential function with values like this:

...
0b0000001000000000
0b0000001000100000
0b0000001001000000
0b0000001001100000
...
0b0000001111100000
0b0000010000000000 <-- Bit shift; restart count with leading '1'.
0b0000010001000000
0b0000010010000000
0b0000010011000000
...
0b0000011111000000
0b0000100000000000 <-- Bit shift; restart count with leading '1'.
0b0000100010000000
0b0000100100000000
0b0000100110000000
...

Manual PWM

For a larger dynamic range of light intensity and smoother brightening and dimming, 16-bit PWM was chosen. As the ATtiny2313A has only a single 16-bit timer with only two PWM channels, a manual PWM scheme had to be employed to modulate the three color channels simultaneously.

The 16-bit overflow interrupt is used to mark the beginning of major frames--a major frame lasts 2^16 MCU cycles. The major frames are split into four equally-timed minor frames. Tasks are split between these minor frames so as to prevent calculations and color switching from interfering with each other and causing glitches.

Minor frame actions:

  • 1st minor frame: Most calculations performed, appropriate colors turned on, and setup for on/off switching of 2nd minor frame.
  • 2nd minor frame: Appropriate colors switched, red turned off at precise time, and setup for on/off switching of 3rd minor frame.
  • 3rd minor frame: Appropriate colors switched, green turned off at precise time, and setup for on/off switching of 4th minor frame.
  • 4th minor frame: Appropriate colors switched and blue turned off at precise time.

The calculations for on and off switching are performed in the overflow interrupt routine for the 1st minor frame. Timer compare A interrupt routine is used to mark the beginning of the 2nd-4th minor frames where channels are turned on. Timer compare B interrupt routine is used to turn off the colors at the precisely calculated times during the 2nd-4th minor frames. The timers to turn channels on and off in each minor frame are set during the previous minor frame. The masks used to turn on and turn off the colors are loaded into a non-indexed variable at the end of the execution of the previous minor frame and used immediately when beginning the routine. In this way, the accuracy of the color intensity is maximized.


Light Patterns

The CRM-114B has 8 light pattern modes that are controlled by the switch integrated into the rotary encoder. Pushing the knob cycles through the pattern modes.

  • Random color approach mode: A pseudo-random color is chosen and each executed...
Read more »

  • 1 × ATtiny2313A microcontroller, PDIP Tayda: 0.99 USD each
  • 1 × 0.1uF capacitor, ceramic Tayda: 0.01 USD each
  • 6 × 1.0 Ohm resistor Tayda: 0.01 USD each
  • 3 × 4.7 kOhm resistor Tayda: 0.01 USD each
  • 3 × 2N3904 transistor Tayda: 0.02 USD each

View all 21 components

  • Design and Physical Construction

    nater01/06/2017 at 02:58 0 comments

    The original LED was a single battery-powered white LED with a large diffuser.

    The original LED's circuit board was used to mount the RGB LED as the board fit into the fixture's holder.

    The driver circuits for each of the LED's channel had the following requirements:

    • Must be constant current.
    • Must work with 5.0V--didn't want to need more than one voltage for this project.

    A tried-and-true constant BJT/MOSFET LED driver was used. For non-buck/boost drivers, this driver provides probably the lowest drop-out for of any constant-current driver, and it's a relatively low parts count.

    With the 2N3904, the voltage between the base and emitter is about 0.5 V. This and the 300mA maximum current per LED channel value gives the minimum value for R1.

    As can be seen, the complete circuit is quite simple.

    The original plan would've placed the circuit in a much smaller enclosure so the layout is more compact than required.

    The perfboard itself ended up being an almost perfect fit for the enclosure chosen. A snip of diagonal pliers on each corner finished that fit.

    The soldering was a mess. It was made even worse by a couple of mistakes that fortunately didn't fry anything before diagnosis and repair.

    A barrel power connector was installed in the side of the enclosure, and a hold was drilled for the light's wire. Additionally, a connector for the wire, rotary encoder module, and programming header was installed.

    All the inside was done and ready to close up.

    U.S. quarter for size comparison.

    The control panel underlay process is straight-forward, and is documented here: https://github.com/oelgern/box_underlays/wiki Be sure to check it out.

    The finished controller uses a wall-wart (not pictured) for power.

    A white wire hanger was used to hold the light onto the tree.

    The project repo--contains schematic, board layout, control panel, and source files--can be found at: https://github.com/oelgern/crm114b

    The control panel template repo can be found at: https://github.com/oelgern/box_underlays

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates