Skip to content

Latest commit

 

History

History
78 lines (58 loc) · 3.15 KB

README.md

File metadata and controls

78 lines (58 loc) · 3.15 KB

Led headlamp based on PIC 16F616

Basic principle

PIC works as core of DC-DC step down converter. It has two internal independent comparators which compare voltage on led sense resistor with a reference voltage generated by PWM. The switching frequency is set by an external RC circuit to about 100kHz.

The PIC generates two channel PWM signal (one for each led) which creates a reference voltage after reducing the level by rezistor divider and smoothing by RC circuit.

Implementation

The PWM is generated by software during interrupt routine (tmr0 overflows every 512us). To keep it short and simple, the routine generates a shorter part of the pulse. This way up to 50% of the system time is used for generator

If the PWM duty is over 50%, generate low part, if less than 50% generate high.

The rest of the programming is divided into two tasks: Key task and ADC task

Key task

Called every 10ms, it check the current key states and sets the flags. It's able to detect two key press lengths. Short press and long press. The long press generates two separate handler calls, first is generated when the key is pressed for over the minimal time and the second event occurs when the key is released.

Key handlers points to actions.asm file which contains definitions of led modes etc.

ADC task

ADC task is running at 8Hz, it checks the battery voltage and shuts the headlamp off if it's too low. It could be also used to correct PWM period to keep the brightness stable during whole discharge cycle of the battery.

The way the voltage is measured is a little tricky, to keep the consumed power during sleep as low as possible, the pic uses a status LED as a reference which brings kind of reversed logic into the program.

When device goes to sleep, status led is turned off and consumes no power.

The voltage across led is kept at almost the same level which is not dependent on battery voltage.

Because PIC takes the supply voltage as a reference for AD module, the measured AD data on LED are getting bigger as the voltage drops. The equations to calculate the voltage from AD data are discussed in more details in ad.asm

Anyway this solutions has also some disadvantages. Due to low pin count and quite crowded PCB, it's connected between pwm output and one of the pins. As the pwm output changes quite often, the interrupt must be disabled during measurement, therefore ADC task cannot be called very often as it would make pwm output quite unstable.

The second problem is that the voltage across LED is not 100% stable, it changes a bit as the input voltage drops. To set the threshold correctly, the actual voltage at 3V needs to be measured and used in calculations

Operations

After connecting device to power, it goes to sleep. Press bt1 for about 2 sec to turn it on. Press it again for more than 2 sec to turn it off

Press bt2 for about 2 sec to activate/deactivate second led.

Short press of bt1 increases light output, bt2 decreases Led1 is turned on all times except the power off state, led2 is controled by long press of bt2 (on/off), long press bt2 also switches currently controled led's intensity