Difference between revisions of "AVR Drivers"

2,031 bytes added ,  06:09, 30 September 2015
m
USBASP details is obsolete - no longer applicable for the V2.0 version commonly available
(→‎Upload new settings: mention NLITE)
m (USBASP details is obsolete - no longer applicable for the V2.0 version commonly available)
 
(8 intermediate revisions by 2 users not shown)
Line 7: Line 7:
===Flashlight Drivers===
===Flashlight Drivers===


Of course you will need a flashlight driver circuit board first. The stock driver in some flashlights already has an Atmel driver on board. There are also 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. As the percentage of off time increases, the light gets dimmer. By setting the on-off cycles to a high frequency, the eye just sees this as a lower mode even when the LED is barely lit. This is called Pulse Width Modulation (PWM). By slowing the flashing more, you get a visible strobe mode or SOS modes. So essentially the Atmel chip is just a computer-controlled on-off switch.
Of course you will need a flashlight driver circuit board first. The stock driver in some flashlights already has an Atmel driver on board. There are also several NANJG drivers available that include an Atmel TINY13A chip that can be programmed. ATtiyny13A can also be locked down (low fuse higher than 0x7F) so they can't be changed easily, 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, as well as Kaidomain driver doesn't use ATtiny13A. 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. As the percentage of off time increases, the light gets dimmer. By setting the on-off cycles to a high frequency, the eye just sees this as a lower mode even when the LED is barely lit. This is called Pulse Width Modulation (PWM). By slowing the flashing more, you get a visible strobe mode or SOS modes. So essentially the Atmel chip is just a computer-controlled on-off switch.


The Atmel ATtiny13A 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.  
The Atmel ATtiny13A 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===
===Hardware===
Line 41: Line 41:
'''[http://www.nongnu.org/avrdude/ AVRDUDE]''' - It is a command line interface (DOS). If you use Tido's programs then you don't need to compile anything: those programs are ready to be loaded. If you install MHV AVR Tools/WinAVR, AVRDUDE will be included. Does not support ATtiny13A, have to use a workaround and pretend it's ATtiny13.
'''[http://www.nongnu.org/avrdude/ AVRDUDE]''' - It is a command line interface (DOS). If you use Tido's programs then you don't need to compile anything: those programs are ready to be loaded. If you install MHV AVR Tools/WinAVR, AVRDUDE will be included. Does not support ATtiny13A, have to use a workaround and pretend it's ATtiny13.


[http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/ '''eXtreme Burner - AVR'''] - Or if you do not like AVRDUDE and want something with GUI, you can try eXtreme Burner - AVR, download latest version at the bottom of the page under release. It can read/write (download/upload) and it also has the required driver for USBasp in the installation. If you only want to write a new firmware (already compiled Tido's, DrJones's, ...) this should be all you need. Does support ATtiny13A.
[http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/ '''eXtreme Burner - AVR'''] - Or if you do not like AVRDUDE and want something with GUI, you can try eXtreme Burner - AVR, download latest version at the bottom of the page under release. It can read/write (download/upload) and it also has the required driver for USBasp in the installation. If you only want to write a new firmware (already compiled Tido's, DrJones's, ...) this should be all you need. Does support ATtiny13A. Does not seem to write correctly nlite driver though. Either does not understand the hex format or ATtiny13A write support is bad. It reads and erases fine.


==== USBasp Driver ====
==== USBasp Driver ====
Line 99: Line 99:
|}
|}


The programmer is 10 pins however which are set up this way:
The programmer is 10 pins however which are set up one of two ways.
 
Old Style:


{|class="wikitable" style="text-align: center; width: 400px;"
{|class="wikitable" style="text-align: center; width: 400px;"
Line 117: Line 119:
|}
|}


[[File:Ribbon.jpg|thumb|The ribbon port at the end is disassembled and wire 8 is moved over to the 9th position]]So Wire 1 (MOSI) of the ribbon cable from the programmer must attach to Pin 5 of the Atmel. Make sure you mark which side 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.
New Style, for the USBASP V2.0:
 
{|class="wikitable" style="text-align: center; width: 400px;"
|+ AVR Programmer ribbon wires
|-
!Pin  !!    Function  !!  Function  !!  Pin   
|-
|1  ||  '''MOSI'''  ||  VCC  || 2   
|-
|3  ||  xxx    ||  TXD  || 4   
|-
|5  ||  '''RST'''  ||  RXD  || 6   
|-
|7  ||  '''SCK'''  ||  GND  || 8       
|-
|9  ||  '''MISO'''  ||  '''GND'''  || 10 
|}
 
 
[[File:Ribbon.jpg|thumb|Old Style: The ribbon port at the end is disassembled and wire 8 is moved over to the 9th position]]Old Style: So Wire 1 (MOSI) of the ribbon cable from the programmer must attach to Pin 5 of the Atmel. Make sure you mark which side 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.


Communication with the Atmel chip is via Serial Peripheral Interface (SPI, see [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia article]) with the ISP programmer a Master and the Atmel on the driver board a Slave. SCK is Serial Clock so they are in sync. The ISP programmer talks on the MOSI line (Master Ouput, Slave Input) while the Atmel talks back on the MISO (Master Input, Slave Output) line. RST is reset.
Communication with the Atmel chip is via Serial Peripheral Interface (SPI, see [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia article]) with the ISP programmer a Master and the Atmel on the driver board a Slave. SCK is Serial Clock so they are in sync. The ISP programmer talks on the MOSI line (Master Ouput, Slave Input) while the Atmel talks back on the MISO (Master Input, Slave Output) line. RST is reset.
Line 125: Line 146:
Now everything is installed and set up. You should be able to plug in your USB programmer with the cable leading to the clip. Attach the clip to the Atmel chip right-side up with at least the 5 critical pins wired correctly.
Now everything is installed and set up. You should be able to plug in your USB programmer with the cable leading to the clip. Attach the clip to the Atmel chip right-side up with at least the 5 critical pins wired correctly.


Be aware that AVRDUDE does not officially support ATtiny13A and you will be using AVRDUDE with ATtiny13 setting "-p t13" instead of unsupported "-p t13a". The difference I found were lockbits when reading with ATtiny13A with it's proper setting compared to ATtiny13 setting. Otherwise it could work if you know what you're doing.
Be aware that AVRDUDE does not officially support ATtiny13A and you will be using AVRDUDE with ATtiny13 setting "-p t13" instead of unsupported "-p t13a". The difference I found were lock bits when reading with ATtiny13A with it's proper setting (0xFC) compared to ATtiny13 setting (0x3C), important are the lowest 2 bits so the final lock bits are for both ATtiny13A and ATtiny13 setting reported correctly despite ATtiny13 setting reporting wrongly the higher bits when used on ATtiny13A chip. Otherwise it could work if you know what you're doing. On a typical Nanjg105C both lock bits are set (zeroed, 0xFC) and programming can only be done after chip erase that is automatically done by avrdude when new flash memory is written with -U parameter. That most likely also prevents reading of the original firmware, which can be read but due to lock bits may be read as garbage/nonsense and cannot be used as backup.


Now open a command window in Windows (or whatever you are in) and typing this command at the C: prompt:
Now open a command window in Windows (or whatever you are in) and typing this command at the C: prompt:
Line 165: Line 186:


==Download settings==
==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.
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. (Actually it is not clear if getting original settings will do any good at all, so if you need a backup, try NLITE, mentioned in the next section).


<PRE style="white-space:normal;">avrdude -p t13 -c usbasp -u -Uflash:r:flash-dump.hex:i -Ueeprom:r:eeprom-dump.hex:i -Ulfuse:r:lfuse-dump.hex:i -Uhfuse:r:hfuse-dump.hex:i</PRE>
<PRE style="white-space:normal;">avrdude -p t13 -c usbasp -u -Uflash:r:flash-dump.hex:i -Ueeprom:r:eeprom-dump.hex:i -Ulfuse:r:lfuse-dump.hex:i -Uhfuse:r:hfuse-dump.hex:i</PRE>
Line 180: Line 201:


The :w: part of the command tells the programmer to <u>w</u>rite settings from the files for flash memory and eeprom and to set the values of the low and high fuses to the hexadecimal values shown. :a is for automatic file type detection, :m indicates "immediate mode" (use the hex values given).
The :w: part of the command tells the programmer to <u>w</u>rite settings from the files for flash memory and eeprom and to set the values of the low and high fuses to the hexadecimal values shown. :a is for automatic file type detection, :m indicates "immediate mode" (use the hex values given).
Always keep low fuse at 0x7F or lower value to ensure that SPI programming is enabled. Values 0x80 or higher will lock the ATtiny13A and it could only be reset in other more complicated ways.
=== nlite ===
<PRE style="white-space:normal;">avrdude -p t13 -c usbasp -u -Uflash:w:nlite.hex:a -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m</PRE>
nlite runs 4.8MHz clock, start up 14CK + 4ms, fast PWM at around 18kHz.
BLF-VLD uses phase correct PWM at 9kHz by default.
eXtreme burner maybe does not understand nlite.hex file and verification fails, or it can't write correctly ATtiny13A at all. Use AVRdude instead.


==Compile your own code==
==Compile your own code==
confirmed
1

edit