How To Build a Flashlight With Perfect Modes (picture heavy)

Hello guys, does anyone have a working hex/eep with 5–15–30–50–100% and no memory? or something similar

I have been trying to make a program from tidos files for the last 6 weeks with no luck…

I registered yesterday to get some help but after today’s ‘’fight’’ i think of giving up…

I managed to burn with success tidos simple, default, and fixed and sixty545 8 mode programs…

The lack of experience talks here, I can burn ready, working hex and eep file but I have realized
that this is as far as i can go… :frowning:

Anyone wanting to share will be greatly appreciated…

man, I can’t believe I finally reached the end of this thread. Even more unbelieveably I think I might have actually absorbed some of the information in it too. Time will tell when I get my programmer and clip :slight_smile:

Hi,
my first post here, so: hello everyone :slight_smile:

I’ve got a question about eeprom write cycles. Looking at the driver.c, function main():

eeprom_read_block() and few lines later: eeprom_write_block().

Looks like the 16 bytes of eeprom are saved everytme the flashlight goes ON. So, the state.click_cell is not really helping here. Am I right?

There are additional EEPROM byte writes in the ISR, and those are spread over some EEPROM cells via click_cell. Otherwise one cell would be used about twice as much as the others.

Yes, that’s true.
If I find some time, I’ll optimize format for constant modes storage - those need 1 parameter instead of 3, so the 18 spare bytes can be used for wear levering. But I’ll do it in a different matter - I’ll divide it into 6 records of 3 bytes each:

- sequence

- last click type

  • click count

And every time when needed I’ll write into the next record, increasing the sequence number. The sequence will allow to find newest record when reading eeprom at startup. This way the eeprom life will be extended 6 times.

I’am no expert but I think that’s something similar to what dr.jones did here.

Oh, I forgot to mention:
Tido, DrJones - you have made a great piece of code! Thank you :beer:

The EEPROM is rated at 100,000 write cycles, but testing shows that they typically last over 5 million cycles. Your switch (and finger) won’t last that long. Wear leveling should not be a concern.

There is some debate about if the chip rewrites a single location or a “page” of EEPROM cells each write cycle. Asking ATMEL gives conflicting answers. I assume that it writes the full page of cells. Different chips have different EEPROM page sizes.

Also, never use the fist page of the EEPROM and after accessing the EEPROM, do a read on an unused page to leave the EEPROM address pointer on unused data. This minimizes the chances of a power glitch corrupting valid EEPROM data.

Thanks, I wasn’t aware of pages in the eeprom (I don’t do uC programming often).
About the cycles - good to hear that it the number is so high. It was a concern for me, because I’ve used CompactFlash cards some time ago to store databases and the CFs were dying like flies :wink:

Besides that, I’ve got a little fix; in the function main() I’ve changed:

if(!state.extended && state.clicks >= NUM_EXT_CLICKS){

to:

if(!state.extended && state.clicks >= NUM_EXT_CLICKS && last_click != tap_none){

so that the extended mode won’t be turned on with a click after the flashlight is on for 2s or longer.

Is there any regulated but non linear buck drivers using attiny. I have a project with a low Vf and want the driver to be reprogramable. But for now, I only found 7135 based drivers : /.

Thanks

Nanjg 105c has this annoying mode memory which is based on time switched on rather than switched off. Can this be changed?

The easy answer is: in it’s stock form, no.
As I do not solder, I can not tell you exactly how to do it. It has been covered in several threads including this one (I believe). If I’m on my computer before someone posts it, I’ll find a link.

EDIT
Here and here

Same, maybe there are some parts on DigiKey but that’s useless to me. Not cost effective.

#562

I don’t know Attiny so I can’t tell if it can be done without the parts. I guess it has no timer so it can’t be done, if it does know time then heck you don’t need any additional parts but everybody did it that way here.

The ATtiny13 has timers, but they don’t run without power… And a (half-)press with a clicky interrupts power, so measuring the off-time isn’t possible without some external components.

After reading the code samples again, I’ve noticed a few things that might help to improve it further and some other random thoughts:

Sleep while looping! Running 9.6MHz cpu with ADC etc running consumes something like 4-5mA. Put the cpu in sleep while looping and wake up with adc interrupt (or add another wakeup source such as timer to wake you up before the watchdog). Especially if you use very low led currents like 5-10mA or so, this really makes a difference in the run time! (A single sleep-command at the end of the loop implements this.) Lowering cpu clock lowers power consuption too: running at 4.8MHz roughly halves power from 9.6MHz and so on.

Oh, as soon as the light is really low and time to turn off, it should turn off watchdog and go to a deep sleep. This would keep the power consuption in the microamp range and leaving it on for a few days should be no problem. Brownout detector should/could be used too but unfortunately only the voltage levels are not too convinient (1.8V + a diode drop at low current is better than nothing, 2.7V level is of no use)

Glitches: If you get glitches by eg. a bumping battery with bad contact while running/cycling on a rough surface you might get low-bat readings that are not real. Once you detected it the lowering of the power is permanent. You can always tackle this with more measurements. Yet better would be a fallback that raises the current up if the battery is later found not to be empty after all. Generally I’d not trust Atmel ADC to be too reliable and noice free in any environment without some filtering/averaging.

Spurious mode changed has been a problem in some environments and it is just an extreme example glitch. I’ve always wondered about methods to detect a power failure early on and shutting the light down (with cpu sleeping) for a few milliseconds. This might help surviving short power outages especially when running at high currents. (This gets very complicated matter without hardware changes when you think more about it. Adding large caps to a cpu supply helps in this case a bit, especially if you sense the voltage at input of the diode instead of the cpu power caps. Another thing that helps a lot is running at as low speed as possible to keep cpu running longer if you’re not shutting it down and waking up through a watchdog)

Lowering power by halving current/changing to a lower mode: I’d really like a smoother transition. The abrupt lowering can be nasty in some cases when you need to rely on the light. Perhaps some slow ramping instead of a step? Battery voltage is a slowly changing variable anyway and you have no need to respond in a second to a change. Lowering in smaller steps might help on the glitch-issue too (a small change is not as bad to do due to a measuring error eiter). On the other hand an abrupt change might be chosen on purpose to notify the user of battery state.

I wonder if on some batteries 3V limit is too high. At least my Panasonics have a lot of juise below that. At least in sixty545s there is a problem I think. If it detects a low batt and pwm=1 it halves that with a shift, which results in pwm=0 (no mininum level defined like on BLF_VLD-0.4). That effectively turns the light off when it cannot suppy 3.0V level any more. (this may be the indend though?) Perhaps you need two limits: one for lowering power and anoter for permanent switch-off. Especially on moonlight levels this could give one a few hours more running time.

A simple method to add temperature protection would be nice as well. I guess there is no way other than adding a ntc somewhere or changing a mcu for a one with internal sensor (like attiny 25/45/85).

Oh, another thing I’ve been thinking on: I’ll probably add a hidden turbo mode on one of my lamps. It might be something like turn on high, wait for a second (perhaps a blink indicator) and quick turn on/off to get to an overdriven mode. If no temperature monitoring is implemented this could be protected with a timer too that gradually lowers it to high after a couple minutes. A similar interface might be great method to hide rarely used moonlight behind a low mode as well. These would help keep UI lo/mid/high and yet allow relatively easy access to more modes without changing mode groups. I guess I’ll have to code it out and try how it suits my needs. (This might also end up seeming a confusing UI. Making a good one-button UI is no easy task in any case!)

The released codes are great pieces of software. I think one of the major challenges is to put in everything (including the sos everyone seems to hate) and yet keep it configurable, with clean user interface and compact enough. Making the perfect modes for everyone in one file is not an easy task.

With code that uses sleeps, this may not always be true. There is a balance between the time/power completing the execution of the code and that spent sleeping. I have some code that consumes less total power running a 9.6 Mhz than with slower clock rates.

OK, I'm at my wits end with this.

I've gone through 3 ISP programmers and 4 SOIC clips, resorted to soldering the SOIC leads directly the to ISP program to guarantee a clean connection, and have checked for continuity from the clip all the way back to the programmer. Everything checks out.

...and yet I get the same problem as described in the AVR wiki (under test the connection - cannot set sck period etc).

Every. Single. Time.

What could it be other than the ISP and SOIC clip? My PC recognizes the ISP and avrdude seems to function (otherwise it wouldn't give me that error). The ribbon cable is short (20cm) and I have used the ribbon cable the SOIC cable came with for my wiring.

Could it be the driver's chip set? They are marked as "ATMEL TINY 13A" so it shouldn't be them. Anything else?

See the big problem is I've now blown through $70 on parts (the previously mentioned 3 ISP programmers and 4 SOIC clips) and I don't want to spend any more cash. Has anyone got a known working set up that they would be willing to part company with? I'd of course be happy to pay because I know it works!

I'm desperate.

- Matt

Assuming you have the wire order from the chip to the programmer correct, my guess is you would need to try a different driver. IIRC The driver I use(confirmed working), I found by Googling ‘usbasp driver’ or something to that effect. I use the cheap caseless programmer from FastTech.

OK, so can you define what you mean by driver? I'm using windows 7 64-bit and have used the guide available here.

Just in case however I just downloaded and installed (not for the first time) the windows USBASP driver from fischl.

Everything installed fine and the device shows up in my device manager as it should. I've also run the testusblib-win check and that works as well.

But still I get nothing but the same error over and over again.

I'll buy this ISP programmer from Fasttech but only because it's so cheap. Most likely it'll be added to my pile of 'not working' stuff.

I suspect the problem lies not in the ISP, the SOIC or the actual uC, but rather my PC somehow. I have no idea where though because all the software checks out.

I have that one and it works fine, that is I only did a "backup" of nanjg's ordinary sw, I didn't try to burn a new sw to attiny...