Wednesday, April 23, 2014

MELD LED board

Just a quick update on my MELD LED boards, they came in and the results are great. The white beam is nice and centered now, plus there's room for UV.



One issue I found is that I tried to make it smaller than it needed to be, so the wire pads end up being right under the reflector on the two lights I've installed it in (Olight S10, Sunwayman C10R). The fix was just to push the pads out so that there's a bigger gap where the traces can run under the reflector. I made that change, as well as made a version with an XP size part:


Sunday, April 6, 2014

MELD v2


Here's the 2nd version of MELD (Multicolor EDC Light Driver), first posted here. This version addresses the issues and shortcomings I had on the first one:
  • converter dropouts and flickering
  • low current on main (white) output
  • no current regulation on white
  • requires rechargeable cell to use UV



To solve all of these I made major electrical and layout changes:
  • CV regulator changed to TPS63000
    • increased current
    • better pin spacing
    • adjustable output voltage
  • separate SEPIC converter for white channel using LM3410
    • output current up to 1.5A
    • true constant current regulation


To make everything fit on a 5/8” diameter board, I had to put the SEPIC converter up on a daughter board that stacks above the main board. This allows the main board to be used for RGBW applications without the SEPIC board if lower currents on the white channel are acceptable. It's also feasible to use the SEPIC board on its own in some applications.





The new converter for RGBUV is a higher power part which fixed all the dropout issues (along with forcing it into PWM mode). It also is an adjustable output version, so I use a pair of 0402 resistors to set the feedback voltage. This allowed me to better handle high-Vf green parts by increasing the voltage rail to 3.5V, and it gives me the ability to let software control the output voltage. To do this, I put an additional resistor that connects the feedback pin to one of my microcontroller's I/O pins. Normally the pin is kept at high impedance, but on UV mode (which requires higher Vf for the emitter) I turn the pin to an output and pull it low, which effectively changes the ratio of the feedback divider and makes the converter generate 5.0V instead of 3.5V. Since this is running from the automatic buck/boost converter, the high-Vf UV part can be run from any battery type at any charge level.





This is my first time using a SEPIC converter (or the LM3410) but it works well. Using the SEPIC architecture allows me to run actual current regulation on the white channel, with input voltage above or below LED Vf. The tradeoff is that you need an extra inductor, but at 4x4x2mm that's not much to worry about. The LM3410 takes a PWM dimming signal on its enable pin, which makes things really simple since I only need one line to control it during dimming and standby. I did have to slow down PWM on the white channel to 488Hz to get it to work well, and I lost some resolution on the low end that software has to compensate for by artificially inflating PWM duty cycle (minimum is now 3/256 instead of 1/256).



Here's a video demonstrating use of MELD v2 in a Novatac 120P:



I'm very happy with the way these came out, I think I finally have a driver that I'm satisfied with for the ultimate light. Here's the board and daughter on OSHPark. If you want the source file or Eagle files, leave a comment. I also put together an LED board to cram RGBUV around a bigger white emitter for better beam patterns, still waiting on that one in the mail:



Thursday, April 3, 2014

MELD v1 boards and Olight S10



For quite some time now I’ve had my RGBWUV multicolor lights and my ultimate flashlight code white lights working well, but always had to have the two separate lights in order to get all the features. I decided it was finally time to combine them into the do-everything light, and so I designed the MELD board:


MELD is for Multicolor Edc Light Driver. Here were my requirements for the design:
  • 4 output channels with PWM dimming for RGBW
  • 1 output channel with on/off control for UV
  • Operate from a single lithium cell of primary or secondary type (input voltage 2.0-4.2V)
  • Consistent output at any battery level
  • Controlled with momentary switch
  • 5/8” diameter or less to fit in small lights
  • 1A output on white channel, ~350mA on colors
  • Colors able to be mixed (channels with varying Vf can be operated simultaneously)
  • Firmware can be upgraded while board is installed in a light
Operating from primary or secondary cells meant the output voltage could be higher or lower than the input voltage depending on LED color and charge level, so I needed buck and boost functionality in the switching converter. The other deciding factor about the converter was the mixing capability. A constant-current source is ideal for LEDs and provides true regulation (immune to temperature-based Vf changes), but if LEDs of dissimilar Vf are both connected to a CC source, only the lower Vf LED will light.

The best solution would be to have individual regulators for each channel, but the size requirements didn’t allow for that. My solution was to find a part that would regulate to a constant voltage, and then run the LEDs from that source with individual current-limiting resistors. This creates waste in the resistors, but if the bulk voltage is closely matched to Vf the waste can be minimized. I found a part that fit, the LM3668. This part will switch automatically between buck and boost modes to maintain a 3.3V output. It is also extremely small and runs at 1.6MHz which means a small inductor can be used.

To run the board I went with PIC16F1824. This part has 4 PWM peripherals to run the output channels and enough I/O for the rest of the functions. In addition to the 5 outputs, it has the switch input and an enable output to the regulator that shuts it down when in standby. From an early prototype of this, I learned one other trick that you can see in the schematic: the microcontroller gets its supply voltage through a dual Schottky diode, which supplies it either from battery voltage or from the converter output, whichever is higher. Without this, with the µC running straight from battery, if the battery is drained (2-2.5V) the microcontroller’s outputs to the FET gates aren’t above the gate threshold and it can’t turn the LEDs on. With the diode, the µC runs from battery while in standby, but when in operation the converter is switched on and it supplies 3.3V to operate the microcontroller (unless the battery is a rechargeable at a high charge level, in which case this doesn’t matter).


The PCB design was challenging because it is so small, but I managed to fit everything. The converter and microcontroller are on top, and the 5 FETs and resistors are on the bottom, along with the positive battery contact:

While I waited for the PCBs to come in, I started coding. This project was essentially a rewrite of my Skyray King software (which was based on D10 software), but writing it in C this time. Writing in C forced me to give it a much cleaner structure and it leaves the firmware open to easier upgrades in the future. I was very happy with the way the code came out. The main control logic is a big state machine that runs all the time, taking inputs from the switch debouncer that runs in the background. Everything else is triggered from a 1ms interrupt that runs timers and fires the switch debounce routine. I’m still looking for an alternate site to upload code to since Google Code stopped taking uploads, so if you want a copy leave a comment. Here’s a list of the features included in the latest version:
  • All modes:
    • Turn on and off by short click
    • Mode memory in all cases (restore last mode after turning off and on)
    • Ramping by holding switch while on
    • Ramping reverses direction when initiated if it has been less than 3 seconds since the last ramp
    • Smart momentary from off (short click latches on, long press is momentary)
    • Shortcut to primary level from on by double click
    • Shortcut to max by click-press
      • If level is currently max, shortcut to min instead
      • If primary level is set to max, shortcut to min instead
      • If held down for an extended time after click press, only do momentary maximum (restore previous brightness (or strobe/color mode) once switch is released)
      • Available from off as well (double click from off to latch on in max, click press from off to go to max in momentary mode)
    • If inactivity timer is enabled, jump to a low white level after 15 minutes of inactivity
      • Any press while in the timeout state restores the previous state
    • State of light is stored in EEPROM and restored upon power up, enabling use in lights that have both a momentary switch and a power switch
  • White mode:
    • Ramping adjusts brightness on logarithmic profile
    • If dim to red is enabled, minimum level is replaced by dim red
    • Ramping pauses on min and max before reversing
  • Strobe mode:
    • Accessed by triple click
    • Ramping adjusts strobe speeds from 8 options ranging from 0.25-40Hz
    • Triple click while in strobe is a shortcut to stunner mode
  • Color mode:
    • Accessed by click-click-press
    • Continuous color mix:
      • Ramping gradually fades between colors so that any color on the spectrum can be chosen
      • Pauses on solid red, green, and blue to help select them
    • Stunner: randomized strobe that uses all colors
    • Auto fade: continuously fades through all possible color mixes
    • Low red: low brightness solid red output. Only available if dim to red is disabled
    • UV: solid UV output, only available if UV is enabled
    • Flasher: triple-blink safety flasher using red
    • Police: alternating blue and white to mimic police lights
    • Fire: simulates flickering firelight by calculating randomized output levels for a mix of red, green, and white
    • All low: turns on all four colors at minimum brightness so the LED can be observed directly
  • Flourish mode:
    • A special color mode not included in the normal set
    • Activated by entering the color command (click-click-press) while already in a color mode
    • Performs a fun-looking sweep through colors that lasts about 2 seconds and returns to standby
    • Light is stuck in this mode once activated, exited by double click or click-press (shortcuts to white modes)
  • Configuration menu:
    • Set up options for light behavior. Click to cycle to next option, hold switch until green LED flashes to activate item
    • If all items are cycled through, the menu exits and returns to normal without taking any action
    • Item 1: tactical
      • Indicated by single long blink
      • When activated, puts light into a momentary-only mode using whatever output (including strobes and color) was active before entering the config menu
      • Can only be disabled by power cycling the light
    • Item 2: beacon
      • Indicated by single short red blink
      • Enables or disables the locator beacon (flashes red every 4 seconds while in standby to help find the light in the dark)
    • Item 3: dim to red
      • Indicated by white med > white low > red low pattern
      • Enables or disables the dim to red feature
      • If dim to red is enabled, the low red color mode will be removed from the list
    • Item 4: auto dim
      • Indicated by white med > white low if currently disabled
      • Indicated by white low > white med if currently enabled (the light is showing what will happen if the menu item is activated—getting dimmer if you are about to turn on the feature, getting brighter if you are about to turn it off)
      • If enabled, the light will drop to a low white level after 15 minutes of inactivity
    • Item 5: set primary
      • Indicated by quick double blink on white (looks like the double click associated with the primary level)
      • When activated, the primary level is changed to the brightness level that was active before entering the config menu
      • Primary level is stored in EEPROM permanently until changed in config menu again
    • Item 6: set momentary max
      • Indicated by short blink then long blink on white (looks like the click-press associated with maximum)
      • When activated, any use of momentary (holding switch from off) will output maximum brightness instead of the last-used brightness or mode. Previous brightness or mode is still remembered
    • Item 7: enable UV
      • Indicated by blue med > blue low if currently enabled
      • Indicated by blue low > blue med if currently disabled (the light is showing what will happen if the menu item is activated—getting dimmer if you are about to turn off the feature, getting brighter if you are about to turn it on)
      • Simply enables the UV mode. Included in the menu so that MELD can be used easily in lights without UV hardware by disabling the feature
    • Item 8: enable colors
      • Indicated by red > green > blue pattern
      • Enables or disables all color modes
      • If color modes are disabled, locator beacon and battery check mode will use only the white output
  • Battery check:
    • Accessed by click-click-click-press
    • Stays active and continuously updates measurement as long as switch is held
    • Measures battery voltage and reports it in blinks – blue blink for values and a long green blink for the decimal place
    • Examples:
      • Battery is 3.2V
        • Blue flashes three times
        • Green long flashes once
        • Blue flashes two times
        • 2 second wait before repeating
      • Battery is 4.0V
        • Blue flashes four times
        • Green long flashes once
        • 2 second wait before repeating

The boards worked pretty well when I assembled them. Many of the software features were developed after I had a board installed in my Olight S10, as I use the light constantly and go write an update any time its behavior isn’t exactly what I want. I quickly ran out of space on the 16F1824 and upgraded to the 16F1825 which is almost identical but double the memory.

Unfortunately there were a number of issues with converter dropouts. On some modes, the output would flicker, and in some cases this would cause the converter to shut down and I’d have to power cycle to restore it. I traced this to a number of factors and made big improvements to it, which eliminated shutdown. Number one was reducing the output current; I currently have 500mA on white and 300mA on colors. I also added a number of small filter caps to the converter’s input and output in parallel with the big 10µF caps. I discovered that the issue wasn’t with pulling too much current (the part is rated for 1A draw), but with PWM—switching the load on and off confused the converter and it was going into its low-power mode on the off cycle. This led me to the biggest improvement which was pulling the SYNC/MODE pin high to force it to PWM mode at all times. Unfortunately this required some difficult trace cutting under a microscope before the chip is populated.



The boards work well enough for low-power lights at this point, but I designed an improved one to address some of these issues. I’ll put up a separate post about MELD v2, but here’s an overview:
  • Daughter board holding separate SEPIC converter for white channel
    • Gives true current regulation on white
    • Outputs up to 1.5A on white
  • Updated buck-boost converter
    • Handles higher current
    • Better pin spacing for less soldering difficulty
    • Allows output voltage adjustment with resistors (increased color efficiency since I can set the output closer to Vf)
  • Software control over buck-boost output
    • Allows use of a high-Vf UV emitter from any battery type without sacrificing RGB efficiency
  • Additional pin exposed for use with other input types (such as twist ring)
I plan on putting up a video of the UI but I may wait until my v2 boards arrive