~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to Tido/BLF-VLD/docs/README

  • Committer: Selene Scriven
  • Date: 2015-09-14 19:24:28 UTC
  • mto: (153.1.18 tiny25)
  • mto: This revision was merged to the branch mainline in revision 156.
  • Revision ID: ubuntu@toykeeper.net-20150914192428-v83iibqzvjlxko9h
updated to BLF-VLD 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
requests, patches, fan mail, hate mail, legal threats etc. to tido@4gh.eu
7
7
or join the discussion on the Budget Light Forum: http://budgetlightforum.cz.cc
8
8
 
9
 
 
10
 
This is the second alpha release of the BLF-VLD. It can be built in three 
 
9
This is the third alpha release of the BLF-VLD. It can be built in three 
11
10
configurations, namely simple, fixed and programmable modes. In simple mode,
12
11
the user can only use the standard modes configured at compile time. In fixed 
13
12
and  programmable mode, the user can switch from the main mode group to the
60
59
 
61
60
To enter programming mode, first choose the mode slot you wish to reassign and
62
61
stay in that mode for more than two seconds. Now change mode NUM_EXT_CLICKS
63
 
times in a row. The light will give two short blinks and enter the extended
 
62
times in a row. The light will give a short blink and enter the extended
64
63
mode group. Choose the mode you wish to assign and stay in it for more than 
65
64
two seconds, then switch the light off. When switched on again, the light
66
 
will give two short blinks and you will have to lock in the new mode.
 
65
will give a short blink and you will have to lock in the new mode.
67
66
 
68
67
To acknowledge the programming, you will have to follow a timed sequence of
69
68
"taps". "Tapping" means turning the light on for only a short period of time. 
72
71
driver has been compiled with the proghelper enabled, the light will signal 
73
72
the appropriate moment to switch off by briefly rising or lowering the light
74
73
level, depending on the current light mode.
 
74
 
 
75
Setting up battery monitoring
 
76
=============================
 
77
 
 
78
Battery voltage monitoring is configured via the following #defines:
 
79
 
 
80
MONITOR_BAT:
 
81
If defined, battery monitoring will be compiled into the driver.
 
82
 
 
83
LOWBAT_TRIG:
 
84
Battery voltage is monitored via the analog-to-digital converter, which 
 
85
returns a value in the range of 0 to 255. Low battery voltage handling 
 
86
will be activated if the measured value is smaller than the one given here.
 
87
The actual threshold to use here depends on how the monitoring circuitry
 
88
is set up. See below for an explanation on how to calculate this value.
 
89
For most variants of the NANJG-101-AK, a threshold value of 130 will
 
90
trigger at around 3V.
 
91
 
 
92
LOWBAT_LVL:
 
93
PWM level to fall back to if a low battery situation is detected.
 
94
 
 
95
ADC_MUX:
 
96
ADC channel to use, depending on which pin of the ATtiny13 is connected.
 
97
    ADC0 (PB5) => 0x00
 
98
    ADC1 (PB2) => 0x01
 
99
    ADC2 (PB4) => 0x02
 
100
    ADC3 (PB3) => 0x03
 
101
 
 
102
ADC_DIDR:
 
103
To make sure the ADC works correctly, the digital input for pin used for
 
104
measuring is explicitly disabled. 
 
105
    ADC0 (PB5) => ADC0D
 
106
    ADC1 (PB2) => ADC1D
 
107
    ADC2 (PB4) => ADC2D
 
108
    ADC3 (PB3) => ADC3D
 
109
 
 
110
ADC_PRSCL:
 
111
The ADC has to be clocked between 50kHz and 200kHz. The clock is generated
 
112
from the system clock and needs to be scaled down. For systems running at 
 
113
4.8MHz or 9.6MHz a prescaler value of 64 is adequate, systems running at 
 
114
1.2MHz will need a prescale factor of 32.
 
115
    64 => 0x06
 
116
    32 => 0x05
 
117
 
 
118
How to compute the low voltage threshold:
 
119
==========================================
 
120
 
 
121
Most driver PCBs sold by DX and KD contain the necessary circuitry to monitor
 
122
the battery's voltage (V_bat). This is done by using the ATtiny13's 
 
123
analog-to-digital converter (ADC) and the internal 1.1V reference (V_ref). 
 
124
To measure the battery's voltage, which is usually in the 3V-4V range, V_cc is 
 
125
connected to the measuring pin via a voltage divider. This is necessary 
 
126
because the ADC can only measure voltages smaller or equal to the reference.
 
127
 
 
128
As there usually is a diode in front of the µC to provide reverse polarity 
 
129
protection, V_cc is 200mV to 600mV lower than V_bat. We will call this voltage
 
130
drop V_diode.
 
131
 
 
132
The voltage divider consists of two resistors in series, connecting V_cc to
 
133
ground. The voltage between the resistors is measured by the ADC and can be
 
134
expressed by the following formula:
 
135
 
 
136
    V_adc = V_cc * (R2 / (R1 + R2))
 
137
 
 
138
The ADC is set to measure with 8 bit resolution in the range from 0V to V_ref.
 
139
The value returned by the ADC can be expressed by this formula:
 
140
 
 
141
    val = 255 * (V_adc / V_ref);
 
142
 
 
143
By subsequently substituting V_adc and V_cc, we get the following formula:
 
144
    
 
145
    val = ((V_bat - V_diode) * R2 * 255) / ((R1 + R2) * V_ref)
 
146
 
 
147
Now we can substitute the component values and the desired target voltage
 
148
to get the ADC value at which the battery alert should be triggered.
 
149
 
 
150
Example 1 (older NANJG-101-AK):
 
151
    V_diode = 0.6V
 
152
    V_ref = 1.1V
 
153
    V_bat = 3V <= target voltage
 
154
    R1 = 10kOhm
 
155
    R2 = 3kOhm
 
156
    
 
157
    val = ((3.0V - 0.6V) * 3kOhm * 255) / ((10kOhm + 3kOhm) * 1.1V) = 128
 
158
 
 
159
Example 2 (newer version):
 
160
    V_diode = 0.2V
 
161
    V_ref = 1.1V
 
162
    V_bat = 3V
 
163
    R1 = 18kOhm
 
164
    R2 = 4.7kOhm
 
165
    
 
166
    val = ((3.0V - 0.2V) * 4.7kOhm * 255) / ((18kOhm + 4.7kOhm) * 1.1V) = 134
 
167