AVR Drivers

From Flashlight Wiki
Jump to navigation Jump to search

Some drivers have an ATMEL microprocessor on board to control different modes. ATMEL processors are programmable therefore the same driver can be loaded with different settings to give different numbers of modes, different output levels, as well as flashing modes like strobe or SOS, along with features like mode memory. This page will summarize some of the things you will need if you want to program your own drivers. This is based on a BLF discussion thread where you can go for help or to get answers to your questions.

All of this is based on AVR tools developed for Atmel chips, which is mostly open source (free). Wikipedia article.

Things You Will Need

Drivers

Of course you will need a driver first. There are several NANJG drivers available that include an ATMEL TINY13A chip that can be programmed. These chips can also be locked down so they can't be changed, but so far none seem to be. However, some variants of NANJG drivers use a PIC chip that can not be programmed with AVR tools. See Popular drivers to see some of the drivers people have been using. Most of these use current regulators to limit the current delivered to the LED while the Atmel chip itself turns the power on and off very quickly, leaving it on for full power, or flashing on and off quickly to simulate a lower mode. By slowing the flashing more, you get strobe modes or SOS modes.

The Atmel ATTiny13 has an 8-bit processor with 1 kb of flash memory, 64 bits of RAM, and 64 bits of EEPROM that can be written several thousand times. There are also settings called "fuses" which can be set or cleared.

Hardware

You will need two pieces of hardware: a programmer and a clip to attach to the Atmel chip which is already soldered in place. There are a number of programmers available, including one called USBTinyISP that you can build yourself from a kit. Ironically, it uses an Atmel chip as well which must be programmed before it can be used as a programmer. There are also a number of cheap drivers available on eBay if you search for USBASP. These all look similar with an exposed blue circuit board and cost about $12, usually including a ribbon cable, which you probably won't need.

You will also need a SOIC 8 clip to attach to the pins of the Atmel chip on the flashlight driver. There are cheap ones on eBay that have been problematic, but will generally work. They cost about $12 as well. It is best to get one with a ribbon cable that attaches to pins coming out of the clip. The individual wires of the ribbon cable can be disconnected from pins and then reattached so that the correct pins from the USB programmer are connecting to the correct pins on the Atmel chip via the clip.

Software

You need some kind of software to interface with the USB programmer and read or load programs into the Atmel chip.

You will at least need AVRDUDE to upload and download files to the Atmel chip. It is a command line interface (DOS). AVR Studio is available from Atmel to allow you to write and compile programs and load them. WinAVR is another package that includes the tools you will need if you want to write and compile your own programs. Eclipse is another package that can be used to develop programming and is what Tido uses.

BLF-VLD

Budget Light Forum user Tido created the original files that can be used, called the BLF Versatile LED Driver. If you go to the first entry of the thread How To Build a Flashlight With Perfect Modes, you will find a link to the latest zip archive of the files you need. This zip archive includes a helpful readme file.

Without doing any programming, you can choose from three setups that Tido has written:

Simple is a 3-mode setup with Low, Medium, and High. It includes mode memory (if light is on for 2 second or more, the mode is memorized when the light is turned off) and a low battery warning.

Extended has hidden modes that can be accessed by running through all of the modes quickly. By default you run 3 modes, but can reach other modes if you want.

Programmable allows you to assign any of the extended modes to your 3 simple modes.

Getting Ready

Installing software

Installing software on your PC and setting it up to get the USB programmer working. Put files in the correct locations so you can access them.

Follow instructions here for installing WinAVR and Eclipse. Then configure Eclipse for AVR. There is also a Wiki about Eclipse AVR.

Set up your clip

Match the pins of the Atmel chip with the pins of the USB programmer. Only pins 1, 5, 6, and 7 of the Atmel are used by the ISP programmer.

The pins of the ATMEL chip are

Pin numbers of Atmel ATTiny13. Pin 1 has an indented circle and is marked with a triangle.


ATMEL ATTiny13A pins
8 VCC 7 SCK 6 MISO 5 MOSI
1 RST 2 INP 3 INP 4 GND

The programmer is 10 pins however which are set up this way:

AVR Programmer ribbon wires
Pin Function Function Pin
1 MOSI VCC 2
3 NC GND 4
5 RST GND 6
7 SCK GND 8
9 MISO GND 10

So Wire 1 (MOSI) of the ribbon cable from the programmer must attach to Pin 5 of the Atmel. Make sure you mark which end of the clip attaches to the top of the Atmel or everything will be misaligned next time you use it. Line up RST and SCK with their appropriate wires. But notice that MISO on the programmer is Wire number 9 and the ribbon only has 8 wires. You will need to disassemble the end of the ribbon cable at the controller end and move wire 8 over to the 9 position so that MISO lines up correctly.

Download settings

Use the software and hardware to download the existing program from the Atmel chip on the flashlight driver. You will need this if your programming doesn't work and you want to reset the driver to how it was originally. Get fuse settings too.

Upload new settings

Open a command window in one of the BLF-VLD subdirectories: "Fixed Modes", "Programmable", or "Simple". With everything hooked up, enter this command:

avrdude -pt13 -c usbasp -P com2 -u -Uflash:w:BLF-VLD.hex:a -Ueeprom:w:BLF-VLD.eep:a -Ulfuse:w:0x79:m -Uhfuse:w:0xef:m