Flashlight Firmware Repository

After using cypreus2 on a real light for a day, I decided the hidden modes were in the wrong order. I updated it to make things a little nicer by default. Here’s the new interface:

I still have 70 bytes left to do something with, but I’m not sure what. I know I don’t have to fill all the space, but maybe there’s something worth adding? I might be able to fit soft-regulation for moon, to make it more stable at different voltages…

BTW, the reason it has two turbos is because it’s running on a light which goes well beyond the sane limit for power in its size — 10 to 15 amps in a little 18650 tube light (2200 to 3300 lumens, depending on the hardware). That’s the same as a Skyray King or Supfire M6, only in a much smaller host. This is configurable in the firmware, of course, but I don’t want to melt my nice new hotrod.

In this case you may want to consider renaming 'Max Turbo' to 'Nitrous'!

I think that if you go to SLEEP_MODE_PWR_DOWN output should be turned off, hopefully. Found this pic:

http://2.bp.blogspot.com/\_9WOJMofzxU0/S9PyagiuISI/AAAAAAAAHY8/tGlOUPRmano/s1600/Picture+1.png

So turn off WTD and go to SLEEP_MODE_PWR_DOWN should be enough to turn off as much as possible. But will test when I get my flasher.

Also remember to turn off the ADC...

Looking at the picture i posted earlier that should not be needed. Hopefully the power down mode takes care of that already.

Correct me if I'm wrong but I believe that chart shows the wake-up sources from the various sleep modes, and doesn't imply that all other systems are disabled.

This is an excerpt from the ATtiny13A datasheet (doc8126):

"7.4.1 Analog to Digital Converter
If enabled, the ADC will be enabled in all sleep modes. To save power, the ADC should be disabled
before entering any sleep mode. When the ADC is turned off and on again, the next
conversion will be an extended conversion. Refer to “Analog to Digital Converter” on page 82 for
details on ADC operation."

As I understand it ADC is turned off in power down mode. It is still enabled but it doesn’t run. If you leave power down mode the ADC will start working again.

Edit: I posted the wrong pic earlier, this is the right one for attiny13: http://we.easyelectronics.ru/uploads/images/00/04/62/2011/05/02/646e36.png

In my testing, I was able to see quite a difference in current draw during sleep with and without the ADC disabled.

It's worthy of a quick test.

Hmm ok. Just checked, it only takes two bytes to disable adc explicitly before enter power down mode. But it would be nice if not needed. And also not needed to fiddle with the pwm output too.

Edit: It seems that you are right my fellow yank. :slight_smile: Technoblogy - ATtiny Low Power
“I confirmed that the ADC uses about 320uA in sleep.”
ADC does take some power even in power down mode, so it should be disabled first.

Measurements trump theory, and Crux was nice enough to measure a lot of code for power use. :slight_smile:

I still need to fit as much of that as possible into various firmwares. Like, the blf-a6 code only has two bytes left so I should probably use that to shut off the single biggest remaining power drain after LVP.

So my flasher arrived today. I ordered these items:
http://www.dx.com/p/343981
http://www.dx.com/p/268210
http://www.dx.com/p/80207

And it works but … if you look at the clip it got tighter pins than normal female cable pins. Arrgh, but I managed to cut the plastic on the clip around 10mm and bend the pins and then it bloody worked to fit the ribbon cable. :slight_smile: Otherwise the clip seems to be of decent quality. So I managed to get my code in order too, used the one byte reads as suggested by ToyKeeper and got it to work. Got a compiler warning when using a line from blf-a6 but managed to fix it with this:
eep = eeprom_read_byte((const uint8_t *)(uint16_t)eepos);

Don’t ask me exactly why it should be like that, I found the fix on the net somewhere. :slight_smile: Finally there is a simple firmware too, code here:

Bugfixes most welcome. :slight_smile:

The compiler doesn’t fully understand the memory model on the attiny, or that the eeprom address space only has 64 slots, so it expects a 16-bit memory pointer and you’re passing it an 8-bit integer. This is totally fine, but the compiler is confused. You can turn off the warning by putting this somewhere in the code:

#pragma GCC diagnostic ignored “-Wint-to-pointer-cast”

My fix works without increasing size so if compiler is happy I’m happy already. Oh yeah forgot to say, as it turns out eeprom_read_block is just a wrapper for eeprom_read_byte so it’s basically the same thing.

Edit: Damn fast pwm is nice! No more friggin buzzing pwm modes. A big thanks to all who started this driver flasher thing. :slight_smile:

Ok, I have investigated this now. If you enter sleep mode power down all pwm output is shut off. However, full output (255) is not shut off. I found a solution to that and if you make all your pins input (0 bits) all output is shut off. So to properly shut off as much power drain as possible you should first shut off WDT and ADC and then you set pins to input. After that you can enter power down mode. Too bad there is not a power off mode that takes care of everything already.

Sounds like it could also be a race condition… if the PWM wave is high, it stays on; if the PWM wave is low, it stays off? So if PWM is set to 128 it might have a 50% chance of shutting off?

Just a guess.

Frankly i don’t care. With that said, gaaah, I hate it when you’re right. But I guess that’s why you’re the sheriff in town. 8) Yes it seems to be a race. I only tested before with 10% and then it shut off a few times. But if you test 50% sometimes it shuts off and sometimes it goes to full output. It doesn’t matter though as you just set all pins to input and be done with it.

I’m pretty happy with my first driver so I wrote another one. I’m a c noob so I basically just make things up along the way. :slight_smile: And I managed to get just about everything to work except one thing, I couldn’t for my life get the right mode count of an array I pass as a parameter to a function. In the end I found out that it’s not possible and you have to pass the size as its own parameter. grrr. Anyway, it got run time group settings so it’s pretty cool. A seasoned c coder probably can save a few bytes here and there and squeeze a bit more modes into it so happy hacking.

Thank you so much for this!!

I appreciate all your time and effort in enhancing our community as you have.

Toy Keeper, I’ve got your cypreus2 in my EagleEye XA-6 triple build, so far I’m liking it, the blinky modes are fun in the rain. Is there an easy way to make the first hidden mode High instead of Max Turbo? Hitting max turbo on this light is painful in daylight.

Joat, to change the hidden modes, just change the definition of HIDDENMODES so it says “100” or so instead of “TURBO”. You might also want to change the last “PHASE” to “FAST” on the next line. And if you want a short tap to go to max turbo instead of moon (off to moon, med top to high, short tap to either moon or max turbo), you should also change the ‘0’ on the HIDDENMODES_ALT line to the number of the mode you want next (probably SOLID_MODES-1).

So, it’s a little weird… but that’s because I wasn’t planning on putting any regular operation modes in the hidden loop.

Also, one reason max turbo is so easy to get to from off is because it serves as “impress mode”, for when muggles ask about a light. They don’t usually care that it has a nice moon mode, but they’re sure impressed by max turbo.