howto: Use Atmel AVR Studio 5 to make a .hex file

66 posts / 0 new
Last post

Pages

comfychair
comfychair's picture
Offline
Last seen: 8 months 2 weeks ago
Joined: 01/12/2013 - 05:39
Posts: 6187
howto: Use Atmel AVR Studio 5 to make a .hex file

The version of Atmel AVR Studio 5 that works is 'as5installer-stable-5.1.208-full.exe' - the version you'll find if you get it through Atmel's site IS BROKEN AND WILL NOT INSTALL! Search for the exact filename above to get the one that works.

This applies to firmwares where the authors have released the source code - so for instance, minimo (momentary switches), minidrv (clicky switches), and the older version of luxdrv. NLITE is supplied only as a pre-built ready to use hex file so the steps shown here aren't needed, it's ready to be flashed as-is. I'm not sure if these same steps work with the BLF-VLD code, I haven't tried editing the included files (only flashed the ready-to-go hex/eep files) but unless there's something particular about Tido's code that needs tweaking to be used in AS5, it should work. Tido uses a completely different set of tools and I don't know if the code works the same across platforms. If you have any specific troubles with building (turning raw code into a hex file that can be flashed to the driver) of these firmwares it's probably best to ask for help in that FW's own thread, as I don't know squat about the code or even how/why this works, only that if I poke at the right buttons in the right order something usable comes out at the end (most of the time!).

 

 

Open your sample file (could be a plain txt file, .c file, or anything that looks like what's shown below when you open it), make any changes needed (mode levels/order, uncomment lines to enable/disable features, etc.). 'Select all', copy, then open AVR Studio 5.

http://75.65.123.78/as5/01.png

 

Click 'New Project':

http://75.65.123.78/as5/02.png

 

'AVRGCC C Executable Project', then 'OK':

http://75.65.123.78/as5/03.png

 

Select 'tinyAVR, 8-bit' from the dropdown box...

http://75.65.123.78/as5/04.png

 

...which will reduce the number of options, ATtiny13A is conveniently right there at the top. Then click 'OK':

http://75.65.123.78/as5/05.png

 

It'll open the project with a generic template:

http://75.65.123.78/as5/06.png

 

'Select all'...

http://75.65.123.78/as5/07.png

 

...then paste in what you copied from the txt file:

http://75.65.123.78/as5/08.png

 

Build > Build AVRGCCxx

http://75.65.123.78/as5/09.png

 

If you get 'Build succeeded' and no errors in the status window at the bottom, it worked:

http://75.65.123.78/as5/10.png

 

Go up to the R/H corner, expand the Output Files item, then double-click 'AVRGCCxx.hex'...

http://75.65.123.78/as5/11.png

 

...the .hex will appear in the main window:

http://75.65.123.78/as5/12.png

 

File > Save AVRGCCxx.hex As...

http://75.65.123.78/as5/13.png

 

Name it something relevant and put it somewhere convenient:

http://75.65.123.78/as5/14.png

 

Now you have a .hex file, ready to be put into avrdude and sent to the driver!

 

 

 

Edited by: comfychair on 02/25/2014 - 13:42
MRsDNF
MRsDNF's picture
Offline
Last seen: 1 week 6 days ago
Joined: 12/22/2011 - 21:18
Posts: 10044
Location: A light beam away from the missus in the land of Aus.

Thanks a lot CC. I was reading through the other thread on perfect modes the other day until my head was spinning. Would it be possible to add a couple of links for the tools used in the actual programming to keep it all in the one spot? I may never be able to do this but one must try these things. Cheers and thanks again.

My current and or voltage measurements are only relevent to anything that I measure. Budget light hobby proudly sponsored by my Mastercard and unkowingly paid for by a hard working wife. Free plug for my daughter. http://missymupsnails.com.au

old4570 "I'm not an expert , so don't suffer from any such technical restrictions."

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

Tom E
Tom E's picture
Offline
Last seen: 7 hours 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 8692
Location: LI NY

I use 6.0 - never had a problem...

comfychair
comfychair's picture
Offline
Last seen: 8 months 2 weeks ago
Joined: 01/12/2013 - 05:39
Posts: 6187

Tom E wrote:

I use 6.0 - never had a problem...

Great! I guess if you know this kind of stuff, you can choose to use all kinds of different tools to do different things without any problems. But if you dive in without a clue, it helps to have the stuff on your screen exactly match the pictures in the guide. It doesn't help to be buried under a giant pile of 300 different options and opinions about which one is best for one thing, but another thing you have to use that one instead, and so on.

I mean, still today I really don't know the difference in 'Build' and 'Compile'... I just know that if I click things in the right order, something usable comes out the other end. I couldn't find a step-by-step guide anywhere that was relevant to only the things needed to put a custom firmware onto a driver. Lots of generalized stuff with a million distractions, and not knowing what any of it meant made it impossible to weed out the stuff that only applied to different hardware or different types of projects.

Tom E
Tom E's picture
Offline
Last seen: 7 hours 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 8692
Location: LI NY

Yes, nice work comfy! I totally understand - everyone is at a different level. I've been doing C programming since about 1980, so, got a little unfair background. I was going to attempt a step-by-step install, but seems like the 5.x was more commonly adopted, and I would have had to start from scratch all over again, then I would assume too much knowledge for sure...

comfychair
comfychair's picture
Offline
Last seen: 8 months 2 weeks ago
Joined: 01/12/2013 - 05:39
Posts: 6187

I think sometimes it's easier to give a clear explanation of something when you've only just figured it out - you still remember all the things you didn't know before you started. But something you know really well, inside out and backwards, you end up taking a lot of things for granted. I'm as bad about that as anybody.

What's that saying - 'experts are people who know more and more about less and less, until they know nothing at all'? Not really, it just sounds that way when they talk about what they know... watch some NASA press conferences on youtube for examples. I swear they have forgotten how to construct an actual sentence in English. I wonder what happens when they pull up at the McDonalds drive-thru? It must be hilarious. Big Smile

leaftye
Offline
Last seen: 8 hours 49 min ago
Joined: 07/25/2012 - 17:43
Posts: 3795
Location: San Diego, CA

Thanks for the clear presentation.  This should take a lot of the fear and learning curve out of the process.

The low mode should be lower.

Reviews: Efan IMR18350 700mAh 10.5A

moderator007
moderator007's picture
Offline
Last seen: 2 years 10 months ago
Joined: 12/23/2012 - 04:47
Posts: 1411
Location: North Carolina

I wish someone had written a detailed guide like this when I started, quite a bit of a learning curve for me. I don’t claim to be all that smart anyway. So I would just like to say thanks for the time spent on this detailed guide, I’am sure it will help others who have had problems or some of those who might say “I got to try this, comfychair makes it look easy”.
I don’t do it the same way as you do, but the results are the same. Nice to see how a expert does it. :bigsmile:

Tom E
Tom E's picture
Offline
Last seen: 7 hours 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 8692
Location: LI NY

The Tiny13A gets all the attention, deservedly so, but I'm liking the Tivo532 Z8 setup so far. It's really nice to be able to reprogram on-the-fly by just plugging in the connector to the exposed back of the driver. I'm using it in a P60 (L2T) and it's really nice to try different PWM levels, and turn around your source code changes to actually testing in a light in seconds. First couple of times you try it, think anyone will be amazed when coming from the Tiny13A environment. The Z8 has 8K bytes of program space - 8X more than the Tiny13A, so plenty of space to put in all the bells and whistles, not to mention 7135 regulation combined with direct drive mode.

Sorry to go little off topic here, but I'm thinking this Z8 setup may be getting hot soon so don't get too used to AVR Studio and Tiny13A's Wink. I got 4.7A in a P60 on a Pana PF (over 1,300 lumens), in turbo mode, then Hi mode at a regulated 1.5A, and a nice low, then moonlight level -- nice...

Le_Zouave
Le_Zouave's picture
Offline
Last seen: 3 weeks 2 days ago
Joined: 12/11/2013 - 07:12
Posts: 229

I use Atmel Studio 6.1 without problem. Well, in fact there was one problem with luxdrv 0.30b source code, where there is “PROGMEM byte modes[]={ MODES };” I had to change it to “const PROGMEM byte modes[]={ MODES };”.
I found this on the big tread for AVR.

I stick to luxdrv code because I really like the short term memory and I’m not skilled enough to implement that short term memory in minidrv.

Yesterday I received a Convoy S6 from banggood, I flashed it right away.
My method is to use extreme burner AVR to check connection, erase chip (mainly to release lockbit fuse) and set low and high fuse. Then I use avrdude to flash hex as extreme burner AVR can’t do it properly (why?)

And in the end of the tutorial, once buildt, it should appear in “my documents”, you don’t need to save hex again.

comfychair
comfychair's picture
Offline
Last seen: 8 months 2 weeks ago
Joined: 01/12/2013 - 05:39
Posts: 6187

AS5 takes whatever I paste into it and spits out a hex file ready to use, I don't really care other than that.

I know the project folder created as soon as you hit 'build' contains the .hex, but it also has a bunch of other files that aren't needed. I find it easier to save the hex directly on its own, give it a name that identifies it, instead of going through all the crap of naming the AVRGCC projects. Paste, build, save, then I'm done with it and don't want to see it anymore. I do all the editing of the input files in notepad beforehand, unless I miss something and it fails to build correctly. Even then, after I make changes and get it to go through so I know it works, I copy the source from the AS5 window and paste it back into the txt file I keep in the folders with each version of FW (along with a .bat file with the avrdude commands in it, so I can just connect to a driver and double-click, no futzing with opening command windows for me please, unless I just have to).

I have WinAVR installed, just because it automatically sets up avrdude - I'm sure there's a way to do it without the unneeded WinAVR stuff, but this works for now, it should work for anybody else who just wants to stick firmware onto a driver and isn't really interested in launching a new career as a (apologies in advance for the following link) software developer. I only care about this stuff to the extent it lets me make better flashlights. Silly

Driver for the USBASP programmer is libusb-win32, again, no real reason other than because it works and that's really all I care about.

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: 01/04/2014 - 06:47
Posts: 4913
Location: H-Town

Brilliant!!!

I have AVR Studio 6 so I will be building the .hex file soon...just waiting on my daggum programmer!

dave_
Offline
Last seen: 1 year 5 months ago
Joined: 04/19/2013 - 08:45
Posts: 455
Location: Schleswig-Holstein, Germany

There is this combobox that says ‘debug’. I’d switch it to ‘release’ if you are not planning on actually using a debugger. That debug stuff just uses up space in the controller for nothing then.
Very nice how-to! It’s no fun to find out all that stuff alone if you are not to familiar with that kind of software!

Tom E wrote:
8X more than the Tiny13A, so plenty of space to put in all the bells and whistles, not to mention 7135 regulation combined with direct drive mode.

Sorry to go little off topic here, but I’m thinking this Z8 setup may be getting hot soon so don’t get too used to AVR Studio and Tiny13A’s Wink. I got 4.7A in a P60 on a Pana PF (over 1,300 lumens), in turbo mode, then Hi mode at a regulated 1.5A, and a nice low, then moonlight level — nice…

I don’t have anything against that Z8, but keep in mind that that 13A is not exactly the pinnacle of the Tiny family, more like an ancient dinosaur or something. Wink Some of them have really nice features (like 16bit timers for more pwm steps than you will ever want for dimming), and they are just a few lines of code away if you already have invested time and money in the AVR platform.

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: 01/04/2014 - 06:47
Posts: 4913
Location: H-Town

It's also very good to use Notepad++ (portable) to read the *******.c file to edit Wink

ChibiM
ChibiM's picture
Offline
Last seen: 13 hours 56 min ago
Joined: 05/09/2011 - 10:25
Posts: 5099
Location: Holland

Thanks Comfychair,

That was very clear, much better than just words written in the flashlight wiki, or the long thread...

For a good overview, could you post a few links in your OP with other useful information about the setup, different firmware etc to keep it all easy to find...

Really appreciate your work!

mattthemuppet
Offline
Last seen: 2 days 9 hours ago
Joined: 01/04/2012 - 16:20
Posts: 1248
Location: WA

thanks Comfy, that’s a great help. I knew that if I procrastinated long enough the good peeps on here would help me get started with the minimum of fuss. I’ll bookmark this and come back to it in a few days to kick myself into gear. This electronics/ code stuff doesn’t come easily to me!

comfychair
comfychair's picture
Offline
Last seen: 8 months 2 weeks ago
Joined: 01/12/2013 - 05:39
Posts: 6187

Added a paragraph at the top with links to the free-to-use firmwares.

ChibiM
ChibiM's picture
Offline
Last seen: 13 hours 56 min ago
Joined: 05/09/2011 - 10:25
Posts: 5099
Location: Holland

Great help, thanks

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: 01/04/2014 - 06:47
Posts: 4913
Location: H-Town

Tido's code is missing

#define F_CPU 4800000 in the BLF_VFD zip file

It fails to compile the driver.c code in the main dir, the sub directories (Fixed Modes, Programmable, Simple) have pre-compiled .hex files in them based upon the default driver.c code, has 3 mode levels...I compiled one with the mode setting to 5 with nothing else changed (but it's untested)

This is under Atmel Studio 6.1

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: 01/04/2014 - 06:47
Posts: 4913
Location: H-Town

Don't use 6.1, it just doesn't compile these, the 5.1 as mentioned above works like a champ...go figure

Pardon me while I smack myself in the forehead and have a V8

DB Custom
DB Custom's picture
Offline
Last seen: 7 hours 4 min ago
Joined: 01/13/2013 - 22:28
Posts: 13798
Location: Heart of Texas

Why do y’all sometimes speak English and sometimes Swahili? Or Greek? Russian? I don’t know what it is but there’s big chunks of it I just plain can’t make head or tails out of!

Thanks Comfy for pointing me/us in the write direction. I have bitten off my first chunk and ordered the programmer and clip. Now I see it’s all in Chinenglish and barely decipherable. Oh well, off to get me a box of Capn Crunch for the mystic decoder ring…

Dale

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: 01/04/2014 - 06:47
Posts: 4913
Location: H-Town

DBCstm wrote:
Why do y'all sometimes speak English and sometimes Swahili? Or Greek? Russian? I don't know what it is but there's big chunks of it I just plain can't make head or tails out of! Thanks Comfy for pointing me/us in the write direction. I have bitten off my first chunk and ordered the programmer and clip. Now I see it's all in Chinenglish and barely decipherable. Oh well, off to get me a box of Capn Crunch for the mystic decoder ring...

Swahili? Or Greek? Russian?

It's actually code...programming nerd language Big Smile

All that text gobbledy gook, plug into a compiler [the copy/paste thing], the computer then takes the text (from the links above) and builds a .hex file which is the program in "computer language" the chip can then run

The ATtiny13A is actually a 20mhz computer with a 1Kb "solid state harddrive" inside it EEPROM...a very limited computer but it allows with the above coding to turn on and off different pins at different frequencies and stuff for the different levels

DB Custom
DB Custom's picture
Offline
Last seen: 7 hours 4 min ago
Joined: 01/13/2013 - 22:28
Posts: 13798
Location: Heart of Texas

Makes sense. Haven’t looked at any of that since keypunch class. But I’m game. May not be the best to start this late at night, so tomorrow I’ll come back in here and start opening stuff up and digging around. Maybe I’ll learn something!

I’m really not as bad as all that, even though it’s not anything I’ve done before the layout has some sense to it…once I figure out what buttons to press and in what order the problem will be remembering it. Wink

Dale

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: 01/04/2014 - 06:47
Posts: 4913
Location: H-Town

Not trying to insult your intelligence...I just find if I simplify an explanation down to where "I" can understand it...usually anyone else can too

and Google is your friend..I taught myself linux by using Google (I know it enough, more or less a "power user" the guys that write that stuff are the geniuses!)

DB Custom
DB Custom's picture
Offline
Last seen: 7 hours 4 min ago
Joined: 01/13/2013 - 22:28
Posts: 13798
Location: Heart of Texas

I can always get Comfy to knock it down to size and email me the hex file. Smile Then I could hook up my big jumper cables to it and wait for lightning….“It’s ALIVE!”

Dale

comfychair
comfychair's picture
Offline
Last seen: 8 months 2 weeks ago
Joined: 01/12/2013 - 05:39
Posts: 6187

For a simple one like minimo all you have to change is the PWM levels. '0' is off, '255' is 100%.

So take the line in the original that says:

uint8_t modes[]={0,  8,90,255};          //PWM values, 5..255 - LEAVE THE "0" THERE

and change it to:

uint8_t modes[]={0,3,9,28,85,255};          //PWM values, 5..255 - LEAVE THE "0" THERE

(or, if you'd like to try it with the levels descending instead of ascending, do:

uint8_t modes[]={0,255,85,28,9,3};          //PWM values, 5..255 - LEAVE THE "0" THERE

and each short press will decrease one level instead of increase.)

(PWM values under 5 only work with the FETs, 7135s will sometimes work at 4 but not always reliably; stick to 5 as the lower bound for a 7135 driver)

luxdrv 0.30b works just the same, though the code is much more complex. You can edit the number of levels and their PWM values just the same. It gets more complicated if you want to do stuff like delete the ramping or strobe modes, you just have to comment out (add a '//' at the beginning of the line) the obvious stuff, then see if it builds without errors. It will tell you if anything is left behind that was tied to the part you commented out.

 

 

The software you'll need, at least to see the same things I see on my screen (that helps when following a step-by-step), is:

WinAVR: http://sourceforge.net/projects/winavr/ (install guide)

libusb-win32 for the driver for the USBASP programmer: http://sourceforge.net/projects/libusb-win32/

and AVR Studio 5.1.208. (try this: https://docs.google.com/file/d/0Bz85IxvlZQErdlpFYUhpbjYtZGM/edit - if you can get it to download, it should be the non-broken version of the installer, it's the right filesize)

max
max's picture
Offline
Last seen: 1 year 1 month ago
Joined: 02/17/2014 - 18:55
Posts: 234
Location: Ruidoso, NM

This is a huge help. Parts are on order. Hope to begin in about 2 weeks from now.

DB Custom
DB Custom's picture
Offline
Last seen: 7 hours 4 min ago
Joined: 01/13/2013 - 22:28
Posts: 13798
Location: Heart of Texas

Comfy, the step by step screenshots are a fantastic idea! Handholding, as it were. Thanks, this just might get me through it…

I plan to install AS5 today and wade in, look around, see if I can figure it out. With some luck, I’ll also attack the clip today and get the wires in the correct places for the ATiny13.

USB Programmer hasn’t shown up yet, but I’ve ordered components for the new FET board and eagerly await the direction to order the boards themselves.

Thanks again for leading me off into parts unknown…

Dale

locusto03
Offline
Last seen: 3 months 1 week ago
Joined: 03/03/2014 - 01:35
Posts: 293

The pics don’t seem to be working. Would anybody mind uploading the screenshots to an image hosting service?

DB Custom
DB Custom's picture
Offline
Last seen: 7 hours 4 min ago
Joined: 01/13/2013 - 22:28
Posts: 13798
Location: Heart of Texas

When I followed the screenshots everything in mine went right along with the tutorial, up until the time to expand the Output file. There’s not a hex file there, only the .c file. So what am I doing wrong?

Dale

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: 01/04/2014 - 06:47
Posts: 4913
Location: H-Town

You need to copy the ***.hex file into the same directory you run the ***.bat file

and you need to make sure the ***.bat file has the exact name of the ***.hex file it is going to load to the ATtiny in it or it will fail

Pages