Main.AvrLightController History
Hide minor edits - Show changes to markup
Deprecated: Function create_function() is deprecated in /home/bluekitc/public_html/ringwald.ch/electronics/pmwiki.php on line 456
Code
The firmware for the AVR Light Controller was developed with the standard AVR-GCC and AVR-LIBC. During development, a bit-banging software UART was used to output debug messages over PB1, which is used for the LED in the final design. I hope the documentation of the source code is reasonable to understand its workings. In doubt, just ask. The summary.txt file in the archive captured my notes and design decisions during development.
Firmware
The firmware for the AVR Light Controller was developed with the standard AVR-GCC and AVR-LIBC. It is released under GPL v2 or later. During development, a bit-banging software UART was used to output debug messages over PB1, which is used for the LED in the final design. I hope the documentation of the source code is reasonable to understand its workings. In doubt, just ask. The summary.txt file in the archive captured my notes and design decisions during development.
- NightBiken.de provides detailed information on Halogen Lights and tips for building huge LiPo battery packs. See the LUXILUS and LUXILUS TTR pages.
- NightBiken.de provides detailed information (in German) on Halogen Lights and tips for building huge LiPo battery packs. See the LUXILUS and LUXILUS TTR pages.
- NightBiken.de detailed information on Halogen Lights and tips for building a big battery packs. See the LUXILUS and LUXILUS TTR pages.
- Martin Muennich built a similar light controler with an ATmega8 microcontroller, which he also sells in case you are interested in just buying one.
- NightBiken.de provides detailed information on Halogen Lights and tips for building huge LiPo battery packs. See the LUXILUS and LUXILUS TTR pages.
- Martin Muennich built a similar light controller with an ATmega8 microcontroller, which he also sells in case you are interested in just buying one.
- http://nightbiken.de]| NightBiken.de detailed information on Halogen Lights and tips for building a big battery packs. See the LUXILUS and LUXILUS TTR pages.
- NightBiken.de detailed information on Halogen Lights and tips for building a big battery packs. See the LUXILUS and LUXILUS TTR pages.
Connectors: Charger, Halogen Light, and Remote Control. Power Switch between Light and Remote
Connectors from left to right: Charge, Halogen Light, and Remote Control. The Power Switch is placed between the Light and Remote Control connectors.
As I wear the light on the head of my bike helmet, the battery and the AVR Light Controller goes into the backpack. In this setup the control button and LED and be put conveniently on the strap of the backpack instead of dangling around near the light as it is common with commercial Lupine lights. Also, as battery and light controller are in the same place, I've put them together into one box.
As I wear the light on top of my bike helmet, the battery and the AVR Light Controller are stored in the backpack. In this setup, the remote control (button and LED) are clipped conveniently on the strap of the backpack, instead of dangling around near the light as it is common with commercial Lupine lights. The battery and light controller are packaged together into one box.
The constants in the code are for a 3 cell LiPo battery (nominal 11.1 V) and a 6V halogen light. The 3 cell configuration provides the voltage level for the BRIGHT mode almost until the battery is depleted (~7.5V).
The constants in the code are for a 3 cell LiPo battery (nominal 11.1 V) and a 6V halogen light. The 3 cell configuration provides the voltage level for the bright mode almost until the battery is depleted (~7.5V).
- The voltage level for dimmed and bright are set by VOLTAGE_BRIGHT and VOLTAGE_DIMMED respectively. Note that the VOLTAGE_BRIGHT is set higher to compensate for the voltage over the MOSFET. Also VOLTAGE_STEP_UP and VOLTAGE_STEP_DOWN determines the transition speed between differnt voltage levels. If you use a 12 volt battery, you should double both values.
- The voltage level for battery warnings are defined by VOLTAGE_FULL, VOLTAGE_WARN, and VOLTAGE_LOW, which in turn depend on NR_LIPO_CELLS. Just set the NR_LIPO_CELLS according to your battery. I've used the following setting for a single LiPo cell: Shut off below 2.5 V, emergency mode below 3.0 V - only the DIMMED mode can be used, battery low warning below 3.375 V.
- The voltage levels for dimmed and bright mode are set by VOLTAGE_BRIGHT and VOLTAGE_DIMMED respectively. Note that the VOLTAGE_BRIGHT is set higher to compensate for the voltage drop on the MOSFET.
- The voltage level for battery warnings are defined by VOLTAGE_FULL, VOLTAGE_WARN, and VOLTAGE_LOW, which are a function of the number of LiPo cells, NR_LIPO_CELLS. Just set the NR_LIPO_CELLS according to your battery. I've used the following setting for a single LiPo cell: battery low warning below 3.375V, emergency mode below 3.0V in which only the dimmed mode can be used, automatic shut-off below 2.5V.
If you want to use a different battery or a different light you need to check the following three settings:
- The voltage divider for battery measurement. The ATtiny can only measure up to 2.56 volts. If you need to adjust the divider you also have to adapt the conversion from measured voltage at the voltage divider to the battery voltage in measure_battery()
If you want to use a different battery or a different light you need to check the following three items:
- The voltage divider for battery measurement, i.e., resistors R1 and R2. The ATtiny can only measure up to 2.56 volts. If you change the divider, you also have to adapt the conversion factor from measured voltage to the battery voltage in measure_battery().
The constants in the code are for a 3 cell LiPo battery (nominal 11.1 V) and a 6 Volt halogen light. The 3 cell configuration provides the voltage level for the BRIGHT mode almost until it's end.
The constants in the code are for a 3 cell LiPo battery (nominal 11.1 V) and a 6V halogen light. The 3 cell configuration provides the voltage level for the BRIGHT mode almost until the battery is depleted (~7.5V).
Measuring the drain voltage was a bit tricky as the ADC conversion time is close to the PWM period. Fortunately, the ADC contains a sample-and-hold unit that samples precisely after 1.5 ADC clock cycles. With this, it is possible to setup the ADC and trigger the ADC such that it measures the voltage exactly in the middle of the ON part of the PWM.
Measuring the drain voltage was a bit tricky as the ADC conversion time is close to the PWM period. Fortunately, the ADC contains a sample-and-hold unit that samples precisely after 1.5 ADC clock cycles. With this, it is possible to setup the ADC and trigger the ADC such that it measures the voltage exactly in the middle of the ON part of the PWM as depicted in the figure below.
http://electronics.ringwald.ch/img/ADC-conversion.png
http://electronics.ringwald.ch/img/ADC-conversion.png \\
Time diagram for correct measuring of VD
Time diagram for correct measuring of VD
Time diagram for correct measuring of VD
Time diagram for correct measuring of VD
http://electronics.ringwald.ch/files/ADC-conversion.png
http://electronics.ringwald.ch/img/ADC-conversion.png
The firmware for the AVR Light Controller was developed with the standard AVR-GCC and AVR-LIBC. During development, a bit-banging software UART was used to output debug messages over PB1, which is used for the LED in the final design. I hope the documentation of the source code is reasonable to understand its workings. In doubt, just ask. The summary.txt file in the archive documents all design decisions and captured my personal notes during development.
The firmware for the AVR Light Controller was developed with the standard AVR-GCC and AVR-LIBC. During development, a bit-banging software UART was used to output debug messages over PB1, which is used for the LED in the final design. I hope the documentation of the source code is reasonable to understand its workings. In doubt, just ask. The summary.txt file in the archive captured my notes and design decisions during development.
Measuring the drain voltage was a bit tricky as the duration for an ADC is close to the PWM period. However, the ADC contains a sample-and-hold unit that samples precisely after 1.5 ADC clock cycles. With this, it is possible to setup the ADC and trigger the ADC such that it measures the voltage exactly in the middle of the ON part of the PWM.
Measuring the drain voltage was a bit tricky as the ADC conversion time is close to the PWM period. Fortunately, the ADC contains a sample-and-hold unit that samples precisely after 1.5 ADC clock cycles. With this, it is possible to setup the ADC and trigger the ADC such that it measures the voltage exactly in the middle of the ON part of the PWM.
http://electronics.ringwald.ch/files/ADC-conversion.png
Time diagram for correct measuring of VD
The firmware for the AVR Light Controller was developed with the standard AVR-GCC and AVR-LIBC. During development, a bit banging software UART was used to output debug messages over PB1, which is used for the LED in the final design. I hope the documentation of the source code is reasonable to understand its workings. In doubt, just ask. The summary.txt file in the archive documents all design decision and captured my personal notes during
The firmware for the AVR Light Controller was developed with the standard AVR-GCC and AVR-LIBC. During development, a bit-banging software UART was used to output debug messages over PB1, which is used for the LED in the final design. I hope the documentation of the source code is reasonable to understand its workings. In doubt, just ask. The summary.txt file in the archive documents all design decisions and captured my personal notes during
In my case, I did already had a Sigma Mirage 6V/20 Watt bike light, but its lead-acid battery is crap, especially in winter when it's cold.
In my case, I did already had a Sigma Mirage 6V/20W bike light, but its lead-acid battery is crap, especially in winter when it's cold.
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Because the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volt a voltage divider consisting of R1 and R2 is used to reduce the battery voltage to 1/8.
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Because the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55V, a voltage divider consisting of R1 and R2 is used to reduce the battery voltage to 1/8.
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as it drops when the the light is turned on, and raises when it is turned off.
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as it drops when the light is turned on, and raises when it is turned off by the PWM.
The 7805 together with C1 and C2 provide the 5 volt VCC for the ATtiny45 and is the reason why the power switch S1 is needed as it has an idle current of up to 5 mA. This is clearly something to change in a later design. I just did not have a better voltage regulator lying around at the time.
The 7805 together with C1 and C2 provide the 5V VCC for the ATtiny45. As its idle current is up to 5 mA, the power switch S1 is needed. This is clearly something to change in a later design.
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET. R8 acts as pull-down to keep the light off if the ATtiny does not work.
The N-channel MOSFET Q1 is used to implement the PWM, i.e., to switch the light on and off. R7 limits the current to the MOSFET. R8 acts as pull-down resistor to keep the light off when the ATtiny does not work.
R6 is used to measure the drain voltage of the MOSFET. If the halogen light is broken or gets disconnected the drain voltage goes to GND. With a working light, it toggles between V'_bat' and the small voltage resulting from the resistance of the MOSFET (for a 6V/20 Watt light, it is about 0.4 V for the IRF540).
R6 is used to measure the drain voltage (VD) of the MOSFET. If the halogen light is broken or gets disconnected, the drain voltage goes to GND. With a working light, VD toggles between Vbat and the small voltage resulting from the resistance of the MOSFET (for a 6V/20W light, it is about 0.4V for the IRF540).
I've got the basic idea of using PWM for controlling the light light voltage by a posting of Willie Hunt in 1993 who later commercialized his designs. Later versions of his initial design already include a Microchip PIC microcontroller. Schematics are available but not the source code for the firmware.
I've got the basic idea of using PWM for controlling the light voltage by a posting of Willie Hunt in 1993 who later commercialized his designs. Later versions of his initial design already include a Microchip PIC microcontroller. Schematics are available but not the source code for the firmware.
- Soft transition between power levels.
- A remote control with a single button and an LED that can be attached for example to the front of a bike pack.
- Smooth transition between power levels.
- A remote control with a single button and an LED that can be attached for example to the strap of a bike pack.
In this project, a microcontroller continuously measures the battery voltage level and calculate the duty cycle to achieve a desired output power.
In this project, a microcontroller continuously measures the battery voltage level and calculates the duty cycle to achieve a desired output power.
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
duty cycle = Veff2 / Vbat2
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
duty cycle = Veff2 / Vbat2
In this project, a microcontroller continuously measures the battery voltage level and calculate the duty cycle to achieve a desired output power.
In this project, a microcontroller continuously measures the battery voltage level and calculate the duty cycle to achieve a desired output power.
I've got the basic idea of using PWM for controlling the light light voltage by a posting of Willie Hunt in 1993 who later commercialized his designs. Later versions of his initial design already include a Microchip PIC microcontroller. Schematics are available but not the source code for the firmware.
I've got the basic idea of using PWM for controlling the light light voltage by a posting of Willie Hunt in 1993 who later commercialized his designs. Later versions of his initial design already include a Microchip PIC microcontroller. Schematics are available but not the source code for the firmware.
duty cycle = Veff2 / Vbat2
duty cycle = Veff2 / Vbat2
duty cycle = Veff2 / Vbat2
duty cycle = Veff2 / Vbat2
In this project, a microcontroller continuously measures the battery voltage level and calculate the duty cycle to achieve a desired output power.
In this project, a microcontroller continuously measures the battery voltage level and calculate the duty cycle to achieve a desired output power.
I've got the basic idea of using PWM for controlling the light light voltage by a posting of Willie Hunt in 1993 who later commercialized his designs. Later versions of his initial design already include a Microchip PIC microcontroller. Schematics are available but not the source code for the firmware.
I've got the basic idea of using PWM for controlling the light light voltage by a posting of Willie Hunt in 1993 who later commercialized his designs. Later versions of his initial design already include a Microchip PIC microcontroller. Schematics are available but not the source code for the firmware.
This project is about building a power controller based on a small microcontroller, here the ATtiny45 was used. The desired output power can be achieved using Pulse-width modulation (PWM) of a power source (LiPo battery in this case). The duty cycle of the PWM determines the amount of power sent to a load (i.e., the halogen light).
This project is about building a power controller based on a small microcontroller, here the ATtiny45 was used. The desired output power can be achieved using Pulse-Width Modulation (PWM) of a power source (LiPo battery in this case). The duty cycle of the PWM determines the amount of power sent to a load (i.e., the halogen light).
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as the it drops the moment the light is turned on, and raises when it is turned off.
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as it drops when the the light is turned on, and raises when it is turned off.
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Because the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volt a voltage divider consisting of R1 and R2 is used to reduce the battery voltage to 1/8.
- The button on the remote allows to turn the light on. It further allows to toggle between BRIGHT and DIMMED power mode. Holding the button for a second turns the light off. * The control LED warns about low battery or when the light is not connected. Also, holding the input button when the light is off triggers the LED to show the battery voltage level.
- The button on the remote allows to turn the light on. It further allows to toggle between BRIGHT and DIMMED power mode. Holding the button for a second turns the light off.
- The control LED warns about low battery or when the light is not connected. Also, holding the input button when the light is off triggers the LED to show the battery voltage level.
I've got the basic idea of a PWM Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
I've got the basic idea of using PWM for controlling the light light voltage by a posting of Willie Hunt in 1993 who later commercialized his designs. Later versions of his initial design already include a Microchip PIC microcontroller. Schematics are available but not the source code for the firmware.
The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
In this project, a microcontroller continuously measures the battery voltage level and calculate the duty cycle to achieve a desired output power.
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used. A desired output power can be achieved using Pulse-width modulation (PWM) of a power source (halogen light in this case). PWM controls the amount of power sent to a load by modulating the halogen light's duty cycle.
This project is about building a power controller based on a small microcontroller, here the ATtiny45 was used. The desired output power can be achieved using Pulse-width modulation (PWM) of a power source (LiPo battery in this case). The duty cycle of the PWM determines the amount of power sent to a load (i.e., the halogen light).
Lithium-Polymer batteries provide enough power, but cannot be used directly with halogen lights. A two-cell LiPo battery (nominal 7.4V) provides about 8.5V when fully charged, and it is not allowed to be discharged below 5V. The halogen lights are usually designed for 6V or 12V. Their light power is controlled by the provided voltage level. While 8.5V voltage level can break the 6V halogen light, the light power at 5V is not good. Therefore, a power controller is required that keeps the voltage supply constant for the halogen light.
Lithium-Polymer batteries provide enough power, but cannot be used directly with halogen lights. A two-cell LiPo battery (nominal 7.4V) provides about 8.5V when fully charged, and it is not allowed to be discharged below 5V. Halogen lights are commonly designed for 6V or 12V and their light power is controlled by the provided voltage level. While an 8.5V voltage level can overheat and destroy a 6V halogen light, the emitted light at 5V is very low. Therefore, a power controller is required that keeps the voltage supply constant for the halogen light.
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used.
A desired output power can be achieved using Pulse-width modulation (PWM) of a power source (halogen light in this case). PWM controls the amount of power sent to a load by modulating the halogen light's duty cycle.
The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used. A desired output power can be achieved using Pulse-width modulation (PWM) of a power source (halogen light in this case). PWM controls the amount of power sent to a load by modulating the halogen light's duty cycle.
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
I've got the basic idea of a PWM Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used. The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used.
A desired output power can be achieved using Pulse-width modulation (PWM) of a power source (halogen light in this case). PWM controls the amount of power sent to a load by modulating the halogen light's duty cycle.
The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
duty cycle = Veff2 / Vbat2
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
duty cycle = Veff2 / Vbat2
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
Lithium-Polymer batteries provide enough power, but cannot be used directly with halogen lights. A two-cell LiPo battery (nominal 7.4V) provides about 8.5V when fully charged, and it is not allowed to be discharged below 5V. The halogen lights are usually designed for 6V or 12V. Their light power is controlled by the provided voltage level. While 8.5V can break the 6V halogen light, the light power at 5 volt is not good. Therefore, a power controller is required that keeps the voltage supply constant for the halogen light.
Lithium-Polymer batteries provide enough power, but cannot be used directly with halogen lights. A two-cell LiPo battery (nominal 7.4V) provides about 8.5V when fully charged, and it is not allowed to be discharged below 5V. The halogen lights are usually designed for 6V or 12V. Their light power is controlled by the provided voltage level. While 8.5V voltage level can break the 6V halogen light, the light power at 5V is not good. Therefore, a power controller is required that keeps the voltage supply constant for the halogen light.
duty cycle = V_eff2 / V_bat2
duty cycle = Veff2 / Vbat2
Lithium-Polymer batteries provide enough power, but should not be used with halogen lights. The light power of halogen lights is controlled by the provided voltage level. A 7.2 LiPo battery provides about 8.5 volts when fully charged and will go down to about 5 volts. While 8.5 volts can break the light, the light output at 5 volt is not good. Therefore, a power controller is required that keeps the voltage supply constant for the halogen light.
Lithium-Polymer batteries provide enough power, but cannot be used directly with halogen lights. A two-cell LiPo battery (nominal 7.4V) provides about 8.5V when fully charged, and it is not allowed to be discharged below 5V. The halogen lights are usually designed for 6V or 12V. Their light power is controlled by the provided voltage level. While 8.5V can break the 6V halogen light, the light power at 5 volt is not good. Therefore, a power controller is required that keeps the voltage supply constant for the halogen light.
11.1 V, 3270 mAh LiPo Battery => 36 Wh
11.1 V, 3270 mAh LiPo Battery => 36 watt-hours
- Lightbulb Voltage Regulator site of Willi Hunt
- Nightbike.de detailed information on Halogen Lights and tips for building the Halo
- ...
- Lightbulb Voltage Regulator site of Willi Hunt.
- http://nightbiken.de]| NightBiken.de detailed information on Halogen Lights and tips for building a big battery packs. See the LUXILUS and LUXILUS TTR pages.
- Martin Muennich built a similar light controler with an ATmega8 microcontroller, which he also sells in case you are interested in just buying one.
Links
- Lightbulb Voltage Regulator site of Willi Hunt
- Nightbike.de detailed information on Halogen Lights and tips for building the Halo
- ...
As I wear the light on the head of my bike helmet, the battery and the AVR Light Controller goes into the backpack. In this setup the control button and LED and be put conveniently on the strap of the backpack instead of dangling around near the light as it is common with commercial Lupine lights. Also, as battery and light controller are in the same place, I've put them together into one box. Let's see the pictures...
As I wear the light on the head of my bike helmet, the battery and the AVR Light Controller goes into the backpack. In this setup the control button and LED and be put conveniently on the strap of the backpack instead of dangling around near the light as it is common with commercial Lupine lights. Also, as battery and light controller are in the same place, I've put them together into one box.
Let's show the pictures...
http://electronics.ringwald.ch/img/avr-light-1.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-2.jpg
Close-up of Remote Control
http://electronics.ringwald.ch/img/avr-light-3.jpg
http://electronics.ringwald.ch/img/avr-light-1.jpg
Connectors: Charger, Halogen Light, and Remote Control. Power Switch between Light and Remote
http://electronics.ringwald.ch/img/avr-light-4.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-2.jpg
AVR Light Controller circuit
http://electronics.ringwald.ch/img/avr-light-5.jpg
Close-up of Remote Control
http://electronics.ringwald.ch/img/avr-light-3.jpg
11.1 V, 3270 mAh LiPo Battery => 36 Wh
http://electronics.ringwald.ch/img/avr-light-6.jpg
Connectors: Charger, Halogen Light, and Remote Control. Power Switch between Light and Remote
http://electronics.ringwald.ch/img/avr-light-4.jpg
AVR Light Controller circuit
http://electronics.ringwald.ch/img/avr-light-5.jpg
11.1 V, 3270 mAh LiPo Battery => 36 Wh
http://electronics.ringwald.ch/img/avr-light-6.jpg \\
As I wear the light on the head of my bike helmet, the battery and the AVR Light Controller goes into the backpack. In this setup the control button and LED and be put conveniently on the strap of the backpack instead of dangling around near the light as it is common with commercial Lupine lights. Also, as battery and light controller are in the same place, I've put them together into one box.
http://electronics.ringwald.ch/img/avr-light-1.jpg
As I wear the light on the head of my bike helmet, the battery and the AVR Light Controller goes into the backpack. In this setup the control button and LED and be put conveniently on the strap of the backpack instead of dangling around near the light as it is common with commercial Lupine lights. Also, as battery and light controller are in the same place, I've put them together into one box. Let's see the pictures...
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-2.jpg
Close-up of Remote Control
http://electronics.ringwald.ch/img/avr-light-3.jpg
Connectors: Charger, Halogen Light, and Remote Control. Power Switch between Light and Remote
http://electronics.ringwald.ch/img/avr-light-4.jpg
http://electronics.ringwald.ch/img/avr-light-1.jpg
AVR Light Controller circuit
http://electronics.ringwald.ch/img/avr-light-5.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-2.jpg
11.1 V, 3270 mAh LiPo Battery => 36 Wh
http://electronics.ringwald.ch/img/avr-light-6.jpg
Close-up of Remote Control
http://electronics.ringwald.ch/img/avr-light-3.jpg
Connectors: Charger, Halogen Light, and Remote Control. Power Switch between Light and Remote
http://electronics.ringwald.ch/img/avr-light-4.jpg
AVR Light Controller circuit
http://electronics.ringwald.ch/img/avr-light-5.jpg
11.1 V, 3270 mAh LiPo Battery => 36 Wh
http://electronics.ringwald.ch/img/avr-light-6.jpg \\
Assembled AVR Light Controller with Sigma Mirage X
Close-up of Remote Control
Assembled AVR Light Controller with Sigma Mirage X
Connectors: Charger, Halogen Light, and Remote Control. Power Switch between Light and Remote
Assembled AVR Light Controller with Sigma Mirage X
AVR Light Controller circuit
Assembled AVR Light Controller with Sigma Mirage X
11.1 V, 3270 mAh LiPo Battery => 36 Wh
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-1.jpg
Assembled AVR Light Controller with Sigma Mirage X
Let there be light!
http://electronics.ringwald.ch/img/avr-light-1.jpg
http://electronics.ringwald.ch/img/avr-light-1.jpg
Schematic for AVR Light Control V1.0
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-2.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-3.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-4.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-5.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-6.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/avr-light-1.jpg
Assembled AVR Light Controller with Sigma Mirage X
http://electronics.ringwald.ch/img/AVR-Light-thumb.png
http://electronics.ringwald.ch/img/avr-light-1.jpg
The constants in the code are for a 3 cell LiPo battery (nominal 11.1 V) and a 6 Volt halogen light. The 3 cell configuration provides the voltage level for the BRIGHT mode almost until it's end. If you want to use a different battery or a different light you need to check the following three settings:
The constants in the code are for a 3 cell LiPo battery (nominal 11.1 V) and a 6 Volt halogen light. The 3 cell configuration provides the voltage level for the BRIGHT mode almost until it's end. If you want to use a different battery or a different light you need to check the following three settings:
Hardware Images
Building Tips
Implementation
As I wear the light on the head of my bike helmet, the battery and the AVR Light Controller goes into the backpack. In this setup the control button and LED and be put conveniently on the strap of the backpack instead of dangling around near the light as it is common with commercial Lupine lights. Also, as battery and light controller are in the same place, I've put them together into one box.
http://electronics.ringwald.ch/img/AVR-Light-thumb.png
Schematic for AVR Light Control V1.0
Approach
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used. The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
Approach
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used. The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
\\
Schematic
The schematic for the AVR Light Controller is depicted below.
http://electronics.ringwald.ch/img/AVR-Light-thumb.png
Schematic
The schematic for the AVR Light Controller is depicted below.
Schematic for AVR Light Control V1.0
http://electronics.ringwald.ch/img/AVR-Light-thumb.png
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
Schematic for AVR Light Control V1.0
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as the it drops the moment the light is turned on, and raises when it is turned off.
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
The 7805 together with C1 and C2 provide the 5 volt VCC for the ATtiny45 and is the reason why the power switch S1 is needed as it has an idle current of up to 5 mA. This is clearly something to change in a later design. I just did not have a better voltage regulator lying around at the time.
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as the it drops the moment the light is turned on, and raises when it is turned off.
R5, S2, and the LED make up the 'remote control'.
The 7805 together with C1 and C2 provide the 5 volt VCC for the ATtiny45 and is the reason why the power switch S1 is needed as it has an idle current of up to 5 mA. This is clearly something to change in a later design. I just did not have a better voltage regulator lying around at the time.
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET. R8 acts as pull-down to keep the light off if the ATtiny does not work.
R5, S2, and the LED make up the 'remote control'.
R6 is used to measure the drain voltage of the MOSFET. If the halogen light is broken or gets disconnected the drain voltage goes to GND. With a working light, it toggles between V'_bat' and the small voltage resulting from the resistance of the MOSFET (for a 6V/20 Watt light, it is about 0.4 V for the IRF540).
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET. R8 acts as pull-down to keep the light off if the ATtiny does not work.
R6 is used to measure the drain voltage of the MOSFET. If the halogen light is broken or gets disconnected the drain voltage goes to GND. With a working light, it toggles between V'_bat' and the small voltage resulting from the resistance of the MOSFET (for a 6V/20 Watt light, it is about 0.4 V for the IRF540).
\\
Motivation
Motivation
\\
Problem
Problem
\\
Motivation
Motivation
\\
Problem
Problem
\\
AVR Light Controller for LiPo/LiIo-Powered Halogen Bike Lights
AVR Light Controller for LiPo/LiIon-Powered Halogen Bike Lights
\\
\\
\\
The constants in the code are for a 2 cell LiPo battery (nominal 7.4 V) and a 6 Volt halogen light. If you want to use a different battery or a different light you need to check the following three settings:
The constants in the code are for a 3 cell LiPo battery (nominal 11.1 V) and a 6 Volt halogen light. The 3 cell configuration provides the voltage level for the BRIGHT mode almost until it's end. If you want to use a different battery or a different light you need to check the following three settings:
- The voltage level for battery warnings are defined by VOLTAGE_FULL, VOLTAGE_WARN, and VOLTAGE_LOW. If you use a battery with higher voltage adapt it accordingly. I've used the following setting for a single LiPo cell: Shut off below 2.5 V, emergency mode below 3.0 V - only the DIMMED mode can be used, battery low warning below 3.375 V.
- The voltage level for battery warnings are defined by VOLTAGE_FULL, VOLTAGE_WARN, and VOLTAGE_LOW, which in turn depend on NR_LIPO_CELLS. Just set the NR_LIPO_CELLS according to your battery. I've used the following setting for a single LiPo cell: Shut off below 2.5 V, emergency mode below 3.0 V - only the DIMMED mode can be used, battery low warning below 3.375 V.
- Soft transition between power levels
- Soft transition between power levels.
General Configuration
Configuration
Link to code. Explain code functions.
The firmware for the AVR Light Controller was developed with the standard AVR-GCC and AVR-LIBC. During development, a bit banging software UART was used to output debug messages over PB1, which is used for the LED in the final design. I hope the documentation of the source code is reasonable to understand its workings. In doubt, just ask. The summary.txt file in the archive documents all design decision and captured my personal notes during
development.
Measuring the drain voltage was a bit tricky as the duration for an ADC is close to the PWM period. However, the ADC contains a sample-and-hold unit that samples precisely after 1.5 ADC clock cycles. With this, it is possible to setup the ADC and trigger the ADC such that it measures the voltage exactly in the middle of the ON part of the PWM.
Explain user changes to the code
Configuration for 12 Volt Halogen Lights
3 changes:
- voltage divider for battery measurement
- voltage level for dimmed and bright
- voltage level for battery warnings
The constants in the code are for a 2 cell LiPo battery (nominal 7.4 V) and a 6 Volt halogen light. If you want to use a different battery or a different light you need to check the following three settings:
- The voltage divider for battery measurement. The ATtiny can only measure up to 2.56 volts. If you need to adjust the divider you also have to adapt the conversion from measured voltage at the voltage divider to the battery voltage in measure_battery()
- The voltage level for dimmed and bright are set by VOLTAGE_BRIGHT and VOLTAGE_DIMMED respectively. Note that the VOLTAGE_BRIGHT is set higher to compensate for the voltage over the MOSFET. Also VOLTAGE_STEP_UP and VOLTAGE_STEP_DOWN determines the transition speed between differnt voltage levels. If you use a 12 volt battery, you should double both values.
- The voltage level for battery warnings are defined by VOLTAGE_FULL, VOLTAGE_WARN, and VOLTAGE_LOW. If you use a battery with higher voltage adapt it accordingly. I've used the following setting for a single LiPo cell: Shut off below 2.5 V, emergency mode below 3.0 V - only the DIMMED mode can be used, battery low warning below 3.375 V.
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET.
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET. R8 acts as pull-down to keep the light off if the ATtiny does not work.
hardware images
building tips
... coming soon.
Hardware Images
Building Tips
http://electronics.ringwald.ch/img/AVR-Light-thumb.png
http://electronics.ringwald.ch/img/AVR-Light-thumb.png
Schematic for AVR Light Control V1.0
Schematic for AVR Light Control V1.0
Schematic for AVR Light Control V1.0
Schematic for AVR Light Control V1.0
\\
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as the it drops the moment the light is turned on, and raises when it is turned off.
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
The 7805 together with C1 and C2 provide the 5 volt VCC for the ATtiny45 and is the reason why the power switch S1 is needed as it has an idle current of up to 5 mA. This is clearly something to change in a later design. I just did not have a better voltage regulator lying around at the time.
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as the it drops the moment the light is turned on, and raises when it is turned off.
R5, S2, and the LED make up the 'remote control'.
The 7805 together with C1 and C2 provide the 5 volt VCC for the ATtiny45 and is the reason why the power switch S1 is needed as it has an idle current of up to 5 mA. This is clearly something to change in a later design. I just did not have a better voltage regulator lying around at the time.
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET.
R5, S2, and the LED make up the 'remote control'.
R6 is used to measure the drain voltage of the MOSFET. If the halogen light is broken or gets disconnected the drain voltage goes to GND. With a working light, it toggles between V'_bat' and the small voltage resulting from the resistance of the MOSFET (for a 6V/20 Watt light, it is about 0.4 V for the IRF540).
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET.
R6 is used to measure the drain voltage of the MOSFET. If the halogen light is broken or gets disconnected the drain voltage goes to GND. With a working light, it toggles between V'_bat' and the small voltage resulting from the resistance of the MOSFET (for a 6V/20 Watt light, it is about 0.4 V for the IRF540).
\\
The schematic for the AVR Light Controller is depicted below. On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
The schematic for the AVR Light Controller is depicted below.
http://electronics.ringwald.ch/img/AVR-Light-thumb.png Schematic for AVR Light Control V1.0
On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
By turning the light on/off
When the light is running at
http://electronics.ringwald.ch/img/AVR-Light-thumb.png Schematic for AVR Light Control V1.0
Explain schematic here in detail
R5, S2, and the LED make up the 'remote control'.
The N-channel MOSFET Q1 is used to switch the light on and off. R7 limits the current to the MOSFET.
R6 is used to measure the drain voltage of the MOSFET. If the halogen light is broken or gets disconnected the drain voltage goes to GND. With a working light, it toggles between V'_bat' and the small voltage resulting from the resistance of the MOSFET (for a 6V/20 Watt light, it is about 0.4 V for the IRF540).
The ATiny45 only requires power supply as it runs from its internal 8 MHz oscillator.
\\
Features
Beside controlling the output power, the use of a microcontroller allows for other goodies:
- Soft transition between power levels
- A remote control with a single button and an LED that can be attached for example to the front of a bike pack.
- The button on the remote allows to turn the light on. It further allows to toggle between BRIGHT and DIMMED power mode. Holding the button for a second turns the light off. * The control LED warns about low battery or when the light is not connected. Also, holding the input button when the light is off triggers the LED to show the battery voltage level.
The schematic for the AVR Light Controller is depicted below. On the left side is the LiPo battery with a fuse and a switch to power off the circuit. Then R1/R2 are used as a voltage divider as the Analog-to-Digital-Convertor (ADC) of the ATtiny45 can only measure voltage levels up to 2.55 volts. At R3, about 1/8 of the battery voltage is available.
R3 and C3 create a low-pass filter. Without this filter, the battery voltage is quite noisy as the it drops the moment the light is turned on, and raises when it is turned off.
The 7805 together with C1 and C2 provide the 5 volt VCC for the ATtiny45 and is the reason why the power switch S1 is needed as it has an idle current of up to 5 mA. This is clearly something to change in a later design. I just did not have a better voltage regulator lying around at the time.
By turning the light on/off
When the light is running at
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a [http://www.cs.indiana.edu/~willie/lvr/doc |posting of Willie Hunt in 1993]] who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a posting of Willie Hunt in 1993 who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
\\
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a [http://www.cs.indiana.edu/~willie/lvr/doc |posting of Willie Hunt in 1993] who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are [[http://www.cs.indiana.edu/~willie/lvr.html |available] but not the source code for the firmware.
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a [http://www.cs.indiana.edu/~willie/lvr/doc |posting of Willie Hunt in 1993]] who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are available but not the source code for the firmware.
\\
Approach/Concept
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used.
Explain general PWM approach together with effective Power (RMS)
Approach
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used. The basic approach is to use the microcontroller to continuously measure the battery voltage level and calculate the duty cycle to achieve a desired output power.
I've got the basic idea of a Pulse Width Modulated Voltage Regulator by a [http://www.cs.indiana.edu/~willie/lvr/doc |posting of Willie Hunt in 1993] who later commercialized his design. A later version already includes a PIC microchip controller. Schematics are [[http://www.cs.indiana.edu/~willie/lvr.html |available] but not the source code for the firmware.
The resulting effective power of the halogen light is calculated by integrating the applied power over time. With on/off modulation, this results in:
duty cycle = V_eff2 / V_bat2
Although super-bright LEDs will Let's start with the current schematic.
Although super-bright LEDs are superior to halogen lights, as they are more energy-efficient and require smaller batteries, halogen lights are cheaper and easier to build. In my case, I did already had a Sigma Mirage 6V/20 Watt bike light, but its lead-acid battery is crap, especially in winter when it's cold.
Lithium-Polymer batteries provide enough power, but should not be used with halogen lights. The light power of halogen lights is controlled by the provided voltage level. A 7.2 LiPo battery provides about 8.5 volts when fully charged and will go down to about 5 volts. While 8.5 volts can break the light, the light output at 5 volt is not good. Therefore, a power controller is required that keeps the voltage supply constant for the halogen light.
This project is about building such a controller based on a small microcontroller, here the ATtiny45 was used.
AVR Light Controller for Halogen Bike Lights
AVR Light Controller for LiPo/LiIo-Powered Halogen Bike Lights
Let's start with the current schematic.
Although super-bright LEDs will Let's start with the current schematic.
AVR Light Controller for Halogen Bike Lights
Motivation
AVR Light Controller for Halogen Bike Lights
Motivation
Problem
Approach/Concept
Problem
Approach/Concept
Schematic
Schematic
Code
Code
General Configuration
General Configuration
Configuration for 12 Volt Halogen Lights
Configuration for 12 Volt Halogen Lights
hardware images
building tips
hardware images
building tips
http://electronics.ringwald.ch/img/AVR-Light-640x480.png
http://electronics.ringwald.ch/img/AVR-Light-thumb.png
http://electronics.ringwald.ch/img/AVR-Light-640x480.png Schematic for AVR Light Control V1.0
Schematic as PDF
http://electronics.ringwald.ch/img/AVR-Light-640x480.png Schematic for AVR Light Control V1.0
http://electronics.ringwald.ch/img/AVR-Light-640x480.png Schematic for AVR Light Control V1.0]]
http://electronics.ringwald.ch/img/AVR-Light-640x480.png Schematic for AVR Light Control V1.0
http://electronics.ringwald.ch/img/AVR-Light-640x480.png Schematic for AVR Light Control V1.0
http://electronics.ringwald.ch/img/AVR-Light-640x480.png Schematic for AVR Light Control V1.0]]
Schematic as PDF
http://electronics.ringwald.ch/img/AVR-Light-640x480.png "Schematic for AVR Light Control V1.0" | Schematic for AVR Light Control V1.0
http://electronics.ringwald.ch/img/AVR-Light-640x480.png Schematic for AVR Light Control V1.0
Motivation
Let's start with the current schematic.
Problem
Approach/Concept
Explain general PWM approach together with effective Power (RMS)
Schematic
http://electronics.ringwald.ch/img/AVR-Light-640x480.png "Schematic for AVR Light Control V1.0" | Schematic for AVR Light Control V1.0
Explain schematic here in detail
Code
Link to code. Explain code functions.
General Configuration
Explain user changes to the code
Configuration for 12 Volt Halogen Lights
3 changes:
- voltage divider for battery measurement
- voltage level for dimmed and bright
- voltage level for battery warnings
hardware images
building tips
AVR Light Controller for Halogen Bike Lights
... coming soon.