// Constant-current power supply for Luxeon 5W LED // with low-voltage warning and shut-off // Software Documentation, as shipped to Mali // in first 45 prototypes, November 2004 // Author: Tim McNerney // Revision: 12/14/2004 17:21 // Functional overview The microprocessor-based driver circuit for a 5W Luxeon LED implements a constant-current power supply, with automatic shut-off if the battery falls below approximately 10.5V, and visible warning below approximately 11V. It also performs limited amounts of data logging, most notably maintaining an "hour meter" that records, in approximately 1/10 hour increments, the cumulative operation time of the projector. This allows an organization supervising a projector deployment project to monitor how much the projectors are being used (though it does not distinguish between use of the projector as a light source or as a projector). [Side note: To encourage re-purposing of the projector as light source when not in classroom use, a blank (i.e. white) frames could be inserted at convenient intervals. This is mostly an issue with white letters on dark background.] The microprocessor is capable of measuring several important analog voltages w.r.t. ground: a) current supplied to the LED (as the voltage drop across a 0.39ohm resistor in series with the LED) b) the voltage drop across the LED (and the current-sensing resistor) c) the battery supply voltage (after the diode bridge) d) the temperature inside the lens barrel at the PCB The microprocessor constantly monitors the actual LED current. It regulates the current using a "buck mode" switching power-supply circuit that efficiently converts a higher-than-needed battery input voltage to the specific voltage across the LED necessary to yield a 750mA supply current. The microprocessor controls the LED voltage (and thus its current) by regulating the PWM duty-cycle of a FET in series with the power-supply circuit's inductor. When the microprocessor is not operating, the FET does not conduct (e.g. at start-up time). // Future functionality In later revisions of the software, it is hoped that temperature monitoring will allow us to drive the 5W Luxeon LED to it's thermally safe maximum, and thus get additional brightness from the LED. Currently the temperature sensor is used only to collect temperature data in the field. // Microprocessor power supply A low-current, linear, 3.3V regulator is used to supply the microprocessor with a stable voltage. This regulator is also used as a voltage reference for the A/D. // PWM architecture The 8MHz internal clock of the PIC16F684 microprocessor is used as a timebase for the hardware PWM module. A frequency of 62.5kHz was dictated by available inductors. This gives 128 distinct duty-cycle values. The brightness of the LED is not linear with current, and current is not linear with PWM duty-cycle. Because of these, the PWM hardware does not have enough resolution to smoothly and imperceptably adjust LED current. To work around this limitation, the PWM duty-cycle is modulated using an length-8 cyclical "dither" pattern. This gives an additional three bits of control resolution over the average LED current (7+3=10 bits). Using this scheme, the instantaneous duty-cycle alternates between two values, but the eye perceives the LED brightness as constant. This effect allows the microprocessor to make smooth variations in average current and LED brightness. // User level, interrupt level The free-running, integral control-loop executes at user level. It sets software registers that are used to control the PWM duty-cycle. The dithering executes at interrupt time, triggered by a dedicated timer. The PWM hardware registers are set in this interrupt routine. // Infrequent, scheduled operations An additional timer is used for processes that need to run once per minute and one every six minutes. In a low-voltage situation, a visual warning, three "winks" of the main LED, is displayed once per minute. The critically low voltage shutoff check is also performed once per minute. The "winking" sequence suspends operation of the current regulation control loop for about one second while it modulates the LED brightness to warn the user that the battery voltage is low. Once low-voltage is detected, between 15 and one hour minutes of operation time remains on the battery. The 15 minute number would only be relevant in cold weather or a compromised battery. // Shutdown Once the critically-low voltage shutoff takes place, the microprocessor continues to run, drawing 2-4mA, but it leaves the main control loop permanently, and "spins" in a loop whose sole purpose is to keep the watchdog timer from resetting the microprocessor and re-starting the control loop (see "Failsafe" below) // Data logging Data logging functions are executed once every six minutes (every 1/10 hour). These record (a) the total operating time of the projector, (b) the highest operating temperature, and (c) the total number of minutes the projector has been run at low-voltage This data logging rate was chosen to avoid shortening the lifetime of the microprocessor's internal EEPROM memory. // Run time test coverage Additional test data is recorded to help confirm that all major paths through the software have been verified. This coverage data is initialized at all-ones. When a path is exercised, the associated bit is cleared. Full test coverage is indicated by all-zeros. // Start-up behavior In order to attain proper behavior at startup time, a "zero minute" event is triggered a few seconds after startup. This is so that the projector can wink immediately upon low-voltage, and then shut off upon critically-low voltage. This "minute" is not counted for data logging purposes. // Control loop strategy The initial PWM duty-cycle is set to a nominal value so that it will not exceed the maximum current "setpoint." The control loop does not implement a proportional term, only an integral term. The duty-cycle state variable is adjusted up or down according to the instantanous error term, the difference between the measured current and the setpoint. // Failsafe mechanism A watchdog timer is used to restart the LED control loop after major malfunctions. If the watchdog timer does not get reset every few milliseconds (e.g. if the software "hangs" and does not call the HEARTBEAT function), the microprocessor is reset/rebooted. // EEPROM The external EEPROM is not currently used. It was originally slated to be used for data-logging purposes, but the C library needed to access it occupied too large a proportion of the PIC16F684's program memory to be practical. Instead the internal, smaller EEPROM is used for limited data logging. // A/D dual voltage range The multiplexed analog-to-digital converter has two ranges: (a) full range (0-3.3V) (b) high-sensitivity (0-1.65V) Both ranges are used in practice, due to an unfortunate choice of voltage-divider resistors that causes "clipped" reading in some cases. The resistor values were not changed after the error was discovered to avoid the need for multiple versions of the software corresponding to multiple revisions of the hardware. // A/D measurements average several readings To reduce measurement noise (especially in the current readings), and to average the dithered control effect, all A/D sensor readings are average over four readings. // Start-up "sanity check", in-circuit programming At software startup, a consistency check is performed, primarily to avoid malfunctioning when the microprocessor is connected to the ICD2 programmer. The In-Circuit Serial Programming (ICSP) clock is shared with the voltage reference pin (RA1/AN1). This causes bad analog mesurements. To protect the Luxeon LED, the projector does not operate when an abnormally high current is measured when the PWM duty-cycle is equal to zero. A small delay (150ms, uncalibrated)) is introduced before this first check is made to avoid measuring the inductive current in-rush when the circuit is powered up. The ICSP capability of the microprocessor allows software to be field upgradable. An unused pin on the programming connector allows the microprocessor to be monitored by attaching it (through an RS-232 level shifter) to a PC serial port or a data-logging terminal. This is useful for debugging and extracting the hour-meter, maximum temperature, etc. from the projector. // Status LED There is a small, yellow status LED on the board, and not visible from the outside of the projector. It is used to indicate error conditions by flashing, but most of the time it glows dimly, indicating normal operation. In fact the status LED is turned on for about 2us every time the HEARTBEAT (watchdog reset) function is called. Because this is called once through the control loop, some operational details can be gleaned by monitoring this either visually, or using an oscilloscope. This LED flickers during normal operation, probably indicating the different path lengths through the control loop. // Pin definitions LED_PIN PIN_C3 // Digital I/O -- status LED PB_PIN PIN_A0 // Digital I/O (unused) -- pushbutton (ICSPDAT) MODESW_PIN PIN_A3 // Digital I/O (NOT MCLR!) -- (was used for testing) VREF_PIN PIN_A1 // Analog Vref (AN1) -- Vreference 1.65V (ICSPCLK) VSENSE_PIN PIN_A2 // Analog Input AN2 -- LED Voltage drop TSENSE_PIN PIN_C0 // Analog Input AN4 -- Temperature sensor BATSENSE_PIN PIN_C1 // Analog Input AN5 -- Battery voltage ISENSE_PIN PIN_C2 // Analog Input AN6 -- LED Current TX_PIN PIN_C4 // Digital Output -- UART transmit (software) PWM_PIN PIN_C5 // PWM (digital output) P1A -- LED current control I2CDAT_PIN PIN_A4 // Digital I/O (unused) -- external EEPROM data I2CCLK_PIN PIN_A5 // Digital Output (unused) -- external EEPROM clock // MCLR not configured for use The MCLR pin is not used as a reset pin. This is used by the "mode switch." // Unused features As mentioned above, the exernal 4kb EEPROM chip is not used by this software. It was originally intended for data logging, but this function is subsumed by the PIC's internal 256 byte EEPROM. Also, the SPDT "mode switch" is not used. It was originally intended to indicate battery chemistry (e.g. Lead acid "wet cell" v. sealed "gel cell"), and may be used in the future, budget allowing. There is also a pushbutton switch. This was intended for debugging and a "soft power" feature. Indeed it would be cheaper to use a pushbutton than to use a toggle switch for "on/off" purposes. In sleep mode, the whole circuit can potentially consume micro-amps, thus effectively "off." As of this writing, the pushbutton is not known to work. It did not pass diagnostic tests, and because it was not needed, this issue was not debugged before shipment. // Future directions The 14-pin PIC16F684 has become less available and more expensive than it was in early 2004. Its 8-pin cousin, the PIC12F683, is mostly software compatible with the '684. It is recommended that a reduced-cost version of the LED driver circuit use the '683. Because of the reduced pin-count, this will not be able to have as many features, notable the external i2c EEPROM, the pushbutton, and the "mode switch." The '683 has 5 I/O pins and one input pin. This -should- suffice for a) Current measurement (analog input) b) Battery voltage measurement (analog input) c) Vref (increases A/D resolution) d) PWM control output (digital output) e) Charge controller FET control (digital output) f) One extra input (analog, or only digital?) Disclaimer: This functionality has not been carefully verified for compatibility with the PIC12F683. This is a design sketch. The big question is whether this could act as a charge-controller too. It is very likely that the basic current regulation for the 5W Luxeon LED -will- be possible using an 8-pin microcontroller.