STAR Firmware by JonnyC - Source Code and Explanation

Anyone?

I'm not sure which would be the better replacement between the 0.22uF and 2.2uF. Either one of those is going to require some tuning and tweaking (not worth the hassle, in my opinion). My opinion: don't cheap out. Pay the extra $1, get the proper parts, and save yourself the headache.

Same goes for the Y5V. They aren't as temperature stable and may give you switching issues over time and with heat exposure. With off-time memory capacitor stability affects the timing, so you don't want it to drift too much.

If you’re only going to have one type of press and can do simple coding, don’t even bother with an off time cap. Using brown out detection method works very good.

For those that don’t know how to do it, here are the details:

For this to work you have to change a fuse settings in the AVRDUDE command. “Brownout detection” must be enabled. Snipped from Alex site:
“Example of working fuse bit configuration avrdude arguments: -U lfuse:w:0x79:m -U hfuse:w:0xed:m”

The code:
First you need a byte in the “no initialise” area. Define it like this:

http://pastebin.com/embed_iframe.php?i=W6F8DCRr

When the light is on normally (after all start up code) you set it to 0 with “OffCheck = 0”.

On startup when detecting a short press, just check if it is still 0 with “if (!OffCheck)”.

With the brownout fuse set the OffTime integer value survives short off presses because of the input capacitor. It decays away after about half a second. Decayed non initialised bytes are 0xFF (all bits 1), the exact opposite to 0 (all bits 0 ). Meaning if the OffCheck value is still 0 it was a short press. If it’s not 0, it has decayed to 0xFF meaning the light was off for longer.

Brownout detection works pretty well for distinguishing between short (< 0.5s) and long (> 0.5s) presses.

I haven’t made a STAR clone with it yet, but I have a non-STAR firmware published and working if you want a reference. It’s ToyKeeper/s7/s7.c in my repo linked below. It may be a bit on the fancy side though, with 15 different modes… but at least you don’t have to cycle through them to use just the basic “normal” modes.

ToyKeeper, I'm having no luck with the Offtime-Cap firmware. I'm not seeing any blinking when turning on-off-on etc. Maybe I don't understand how to use it, can you offer any advice?

? Blinking ?

The Offtime-Cap.c (.hex) firmware blinks out the ADC value of the voltage on the Offtime cap. This helps tweak the short press and medium press values for mode switching in other firmwares.

I think...!?!

Crux, does it turn on at all?

Maybe the first level is too low to light up the emitter.

And if it won’t change modes, the OTC values are probably way off.

I’m just guessing though.

Oh, wait. You mean offtime-cap.c? You might want to set BLINK_PWM to a higher number, perhaps. If it’s set high enough, it should at least blink once briefly after it turns on, since a zero will still register. But it’s half as bright as the regular blinks, and much shorter, so it might not light up at all if the #define is too low.

For a value of 203, for example, it should blink out “_ , ., _ _”. Or for a value of 0, it should blink out a single “.”.

But, of course, if it gives you a zero, the OTC is either not working or has been off for a long time.

Change the shift register code to this:

    buffer = (buffer << 1) | ((~PINB & (1 << SWITCH_PIN)) == 0);

This inverts the logical value of the input pin.

I must have a compile issue. The .hex from your repository runs, but the blinks are too short for my driver. When I change BLINK_PWM and rebuild (Studio 6.2) the PWM pin just goes to 1 volt (?!) with no pwm. The .hex file I made is 132 bytes yours is 688 bytes.

Let me redo this from scratch, I have something wrong here.

EDIT: Working fine now (deleted all and recreated project) - operator error. Thanks ToyKeeper!

Ah, now I see what you're talking about. (I obviously don't have any idea what I'm talking about!)

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.