STAR Firmware by JonnyC - Source Code and Explanation

Okay, was BLINK_PWM the only thing you needed to change?

To help make it work on more drivers, I set it to 20 and re-published a new build. That way, even the “zero” blink will be at a level of 10, which should show up on almost anything.

Yes, all I changed was BLINK_PWM (to 40, because of my PWM-to-analog driver). 10 is probably fine for the bulk of the drivers. Of course after that success I also changed the Vref to Vcc just to see where the OffTime cap voltage range is. My driver runs on either two or three cells, so Vcc is stable at 5V. With 1.1V vref I was reading 255 on short clicks. With Vcc vref the counts were at 60 to 45 range. I'll need to do some more testing to find good values for medium and short presses.

So now I've been working with Battcheck.c to figure out where that count is. I plan on adding a second low battery step-down mode, one at 9V and one at 6V. Somehow I need to differentiate between three dead cells (9V), and two full cells (8.4V). Sounds like disaster waitin' to strike. :)

I not asking for help (yet) but I'm open to any advice.

THANK YOU for posting and hosting these programs as well as the others in the repository.

hey, im looking for a “step by step” tutorial for programing the Attiny13A useing an arduino,
just like drdanke did here in post #29, but if possible with more details and maybe even a video,

i like the idea of not need to buy the programer and the clips, and i do have the arduino alrady.

thanks.

Just so happens I have another USBasp on the way. I found the latest firmware and will update one of the units when it gets here. BTW: I’m not used to handling things like this with open chip leads w/o being grounded with a wrist strap. Has anyone had an ESD failure? I think when I’m done flashing the new firmware, I’ll slip it into some 3/4” clear heatshrink tubing and shrink the two ends.

I took the next step and loaded Atmel Studio 6.2 (along with some serious bloatware from Microsoft). So far, all the c files I’ve looked at compiled fine. Finding the optimization settings was a hoot. Looking at the code, quite a bit of it makes sense.

This is all coming together just in time, because the 22mm 16 X 7135 boards arrived from OSH today, and the F13 light is in transit. I’ve got two or three other projects underway as well plus a test bench.

Thanks to all of you for your help and support.

No ESD problems yet, and I've programmed a few.

If I want to change the switch pin to Star 3 and the temperature sensor to Star 4 of MTN_momentary_temp, should I simply modify these lines:

#define SWITCH_PIN PB3 to #define SWITCH_PIN PB4

#ifdef VOLTAGE_MON
volatile uint8_t adc_channel = 1;
#else
volatile uint8_t adc_channel = 2;
#endif

to

#ifdef VOLTAGE_MON
volatile uint8_t adc_channel = 1;
#else
volatile uint8_t adc_channel = 3;
#endif

also modify the adc_channel to 0x03 (PB3)

// Switch ADC to temp monitoring
adc_channel = 0x03;
ADMUX = ((ADMUX & 0b11111100) | adc_channel);
} else if (adc_channel == 0x03) {

Thanks for your comments.

Okay, I made a version of STAR which uses brownout detection instead of an offtime capacitor. It’s just STAR_off_time 1.3 with that one thing changed; otherwise it’s identical.

http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/files/head:/ToyKeeper/STAR_noinit/

Not guaranteed to work on every attiny13-based driver, but it works on all the ones I tried. I hear the brownout timing can vary depending on some of the other driver components.

Everytime I read “Brownout” my mind immediately thinks “dust storm.”

I may just have to try that sometime, but I have a lifetime supply of OTC’s, so we’ll see if I ever get around to it.

There isn’t really any advantage to it if you already have an OTC installed. It might save a few bytes, I guess, but mostly it’s just to get an offtime-based UI on lights which don’t have (or can’t fit) the capacitor. I use this trick on a couple qlite/nanjg drivers.

I use a USBasp 2.0 programmer and grew tired of the annoying “cannot set sck period” error message every time I used it, so I fixed it (updated the firmware) for $3—and ended up with a backup programmer in the process. I gleaned the following info from a few sites including the programmer’s site. This only works if you’re currently using a USBasp 2.0 programmer.

1. Buy a USBasp 2.0 with 10-wire ribbon from Ebay, Fasttech or wherever.
2. Choose which programmer you’re going to update (the target) and mark it with a permanent marker or something,
3. Document your clip ribbon connections to your existing programmer and remove them.
4. Optional: Make sure your new programmer works. Connect to a clip, clip to an attiny13a, and test the connection. I use “avrdude –p t13 –c usbasp –n” (without the quotes).
5. Jump JP2 on the target USBasp to put it in programming mode.
6. Connect the two USBasps with the 10-wire ribbon. It can only connect one way.
7. Get the new firmware either from the developer (needs to be compiled) or get the hex file here . Lazy arse that I am, I got the hex file.
8. Put the hex file in the correct directory.
9. Plug the non-target USBasp into the USB port
10. The new firmware requires different fuse settings on the target programmer’s processor. I used the command line “avrdude –c usbasp –p atmega8 –u –U hfuse:w:0xc9:m –U lfuse:w:0xef:m” (without the quotes).
11. Flash the hex file to the target USBASP to update the firmware. I used the command line “avrdude –c usbasp –p atmega8 –U flash:w:usbasp.atmega8.2011-05-28.hex” (without the quotes). If you made your own hex file, use it in the command line.
12. Disconnect the 10-wire ribbon and remove the jumper from the target.
13. Connect the clip ribbon to the target and repeat #4 above. The “cannot set sck period” error message is now a thing of the past.

You should now be able to flash error free. Oh, I had both programmers set to 5 volts.

I have only flashed one chip with the new firmware, and it works, but I am leaving the non-target with the old firmware just in case there is some issue down the road.

Hope this helps someone and good luck!

I think you're the only person who has ever cared to update their firmware. It's never caused any problems for me or anyone else that I'm aware of, so my opinion has always been "if it isn't broken, don't waste time trying to fix it".

That said, I applaud you for figuring out a fix for something that isn't really broken just because it bugs you. It sounds like you'll fit in really well here (we've all been known to do things like this).

TK - I tried this firmware on a single sided Nanjg 101-AK-A1 (from IOS) with 2 added 7135's (2.1A total). This driver really has no space for the OTC cap I could find for it. Mostly it worked great:

  • quick click detection had excellent timing and works reliably
  • LVP kicks in at just about exactly 3.0v, but with an issue:

--> It blinks 3 times ok, but immediately goes into moon mode after that, instead of ramping down. I'm using your recommended fuse settings (not sure what those settings mean: -Ulfuse:w:0x79:m -Uhfuse:w:0xed:m). Everything else is untouched, your original code, but set my own mode PWM values, including 5 for moon mode assuming that's the minimum for 7135's.

I carefully reviewed the LVP code and didn't see any differences, and the logic appears correct, using the ALT_PWM port value. Looks like it should cut output in half each time, then decrement modes when the PWM value falls below the next, etc...

Any ideas why this is happening? Does LVP work ok for you in this firmware? Almost seems like reading ALT_PWM is not working well, or something...

Edit: This is a pretty good fuse setup web app for the ATTiny13A: engbedded.com fuse app

Interesting. It could be a fuse value, perhaps, since I didn’t change anything except the memory method and fuse settings. Or it could be a bug inherited from STAR_off_time. The fuse values were copied from alexvh’s posts, but I’m not sure why some bit changed. I suspect that 0x75 and 0xfd should work, but I’ve only actually tried 0x79 and 0xed. Perhaps I can test LVP with various fuses soon…

Ok - I fixed it now. First, I re-produced it on another Nanjg 101-AK-A1 (short story: 1st light sold as soon as I showed it to someone...). This was a 2.45A build, but same exact firmware of STAR_NoInit. It has the same exact problem, but this time I notice after the 3 blinks, it actually turns off for a couple secs, then turns on at a moon mode level -- weird.

So again, I studied the code and only possible issue I could see is the manipulations of ALT_PWM_LVL, which is really the I/O register OCR0A. So, I added a variable called: 'setPwmOut' that mirror images the PWM output, and referenced it instead of ALT_PWM_LVL in the LVP code. Then viola!! Re-built and works perfectly. You can see it now go thru 3 blinks, then drop, repeatedly, which is how it should work. Also I fixed a potential bug in the Main LVP code where mode_idx is decremented where it could potentially be 0 before the decrement.

The decrement is below this comment (code inserting sux in a thread post), add an if " if (mode_idx > 0)" before "mode_idx++":

// See if we should change the current mode level if we've gone under the current mode.

Ohhh - I use AtmelStudio 6.2 with the optimized for size setting - all same compile/build settings as my eswitch and STAROffTime projects which work well, including LVP.

Awesome. Could you send me a patch, or the source you’re now using? I’d like to fix it in my repo too.

Sure.. My version has some additional formatting changes, always backs off the mode index by 1 when a turbo timeout occurs (so 1 click restores turbo), and disables the moon mode STAR setting (commented out). @work now with no access to it, but I'll try this eve. You probably should grab all my latest to update your repository with. I'll try to throw together some readme text files for each to list the changes/enhancements.

Really love the quick click mode change of this noinit version. The OTC cap versions always seem to have issues of variation of timing, and so far, this one has been a rock. From what I can see, the 2 main changes to the fuses is the 64 msec delay option vs. the 4 msec delays option, and the brown-out detection enabling. Thinking the 64 msecs give it more time for the memory to change, so the timing of the mode change detection is better/shorter. The brown-out detection enabling is the key to it working at all, I would think.

When you say "mirrored" do you mean reversed? or do you mean copied?

Smile - in CS/IT, never heard of mirror imaging doing anything reverse - interesting analogy.. I mean copy, a local copy of the I/O register.

It's an old trick (I'm old too) to have a local copy of registers, specially when they are write-only. These registers (OCR0A and OCR0B) are doc'd as R/W, so either there's something quirky with them, or the C compiler has some bug/issue with doing manipulations on registers, dunno, or could be some flaky bug in our software that somehow corrupts something, and my change simply moved things around so the effect is minimized. I've seen it all from chip bugs to SW tool bugs, and got burned a few times on C compiler problems. We've had a few C compiler bugs on our current project at work using a TI DSP and the development tools that support them. Back in the mid-late 80's and 90's, I believe the compilers were better - they were developed in the US either directly by the chip manufacturer or direct contractor. Now everything goes overseas and the rigorous quality and testing standards have diminished. It's all bout saving money now...

Sorry - That's my engineer curse throwing doubt in my interpretations. Anyone else would know exactly what you meant.

I figured you meant 'copy', and now upon further refection, I can't imagine why you would 'reverse' it, but I asked first and thought second.

I did it because I can :stuck_out_tongue: . And now I have a spare programmer in case one goes Tango Uniform.

…And what did it cost me? $3 and maybe 2 hours of net surfing/zapping.