3 Step-up converter with current feedback measurement
4 Battery voltage monitor
11 Driven by PWM output OC1B (PB4 pin) with MOSFET.
12 Current feedback measured at ADC3 (PB3 pin).
13 Output on the PB4 header (pin 1 is negative, pin 2 is positive side).
14 Battery voltage monitor:
15 Uses ADC1 (PB2 pin), voltage is divided using 1M5 and 100K resistors,
16 low-pass filter added on input (R30 capacitor, R32 resistor)
18 Uses PB1 pin, R22 resistor, positive side is PB1 header pin 2,
19 negative side is PB1 header pin 1
21 Connected to PB0 header pin 2 using R12 0-Ohm link R12,
22 negative side is PB1 pin 1 (alternatively PB0 pin 1 could be
23 used instead - 0-Ohm link R15 needs to be added). Internal
24 pull-up resistor of ATtiny itself provides the voltage.
25 Pins 2 and 3 of PB2 header are shorted, and 100K resistor R3x
26 is added between pins 1 and 2.
33 D50 SS24 Schottky diode (SMB package, 40V, 2A)
34 L50 470uH, 390mA, 200 mil pin distance (probably too big for 20mA LEDs :-)
35 PB4 two-pin header soldered to pins 1 and 2 of PB4
36 Q50 IRLML6344TRPBF N-channel MOSFET, 30V, 5A, SOT-23 package
37 R30,R40 220nF capacitor (not resistor!)
43 R12,R51,R53 0R00 (zero-ohm link)
44 R55 3R0 (can safely measure currents from ~1 mA up, for higher currents use lower value)
55 1: status LED -, button -
62 The firmware is a dumbed-down version of firmware for my other
63 project: http://www.fi.muni.cz/~kas/bike-lights/, modified
69 After power-up, the firmware sets up the CPU and powers it down,
70 waiting for a long button press. In this condition the system
71 takes about 8uA from the 9V battery. So a typical 500 mAh 9V battery
72 would last about 2604 days in this mode.
74 When the button is pressed for a sufficiently long time, the CPU
75 wakes up, switches the status LED on (providing visual feedback),
78 The firmware main loop is timed by ADC interrupt. It continuously measures
79 the voltage on R55 feedback resistor, and adjusts the PWM value on OC1B
80 to match the expected current through the LED string. Occasionally
81 the ADC is switched to the battery voltage sensing, and the battery
82 voltage is read. If the battery is critically low, the system
83 is switched to the power-saving light pattern (see below).
85 The step-up converter has four target values of current (2 mA,
86 6 mA, 12 mA, and 20 mA as of this writing, see pwmled.c). The blinking pattern
87 is adjusted separately from the target value in the firmware.
89 The firmware recognizes short and long button presses. The short one
90 cycles through all blinking modes, the long one switches the system off and on.
92 The status LED has two blinking modes:
93 - in the normal one, it is off by default, and uses a series of
94 short switch-on blinks to display the battery voltage
95 (the number of blinks is voltage above 7V in 0.5V steps).
96 - when an error occurs, the status LED stays on by default, and displays
97 the error condition as a series of short switch-off blinks:
98 - one blink is a "power low" condition
99 - three blinks is "step-up error" (a LED string disconnected,
101 - when the long (-enough) button press is detected, i.e. when powering on
102 or off, the LED is switched on to provide a visual feedback
103 of long-enough button press.
105 The blinking modes and patterns are currently set up as follows:
106 1. power-saving minimal mode
107 - a single short blink at minimum current
109 - 2 and 3 blinks at the second-lowest current
111 - 2 and 3 blinks at the third-lowest current
113 - 2 and 3 blinks at the highest current
114 5. steady light at the minimum current
115 6. steady light at the second-lowest current
116 7. steady light at the third-lowest current
117 8. steady light at the highest current
119 The system starts up set to mode 3, and switches to mode 1 when
120 the power is critically low. Other modes can be chosen via short