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

Let's make a pool to make someone savvy make a few custom flash ready images with desired modes for us to use. That's it.

Get the soic clip the usb programmer load that load of apps and flash rightaway. About 5 versions per drivery type (the most common would probably fit 90% of requests). Unless i'm missing something it would certainly be doable.

4 modes with low low, 3 modes with XY spacing, 4 mode H-M-L or L-M-H with beacon. etc...

So, I finally am able to flash Tido's code to my drivers! The solution for me was to buy a USBtiny programmer kit from Adafruit, which requires assembly but which also powers the target board. Once I connected my attiny13-controlled SB 2.8A driver to this programmer, I had no problem. Next up is tackling the code so that I understand it well enough to set custom levels for a 4-level fixed mode no-memory driver. I think I am starting to understand, although I agree with the others that having the simple, programmable, and fixedmodes code in separate files in C would greatly increase my understanding. If I ever get the fixedmodes code sorted by itself I will post it (with Tido's permission).

I also have a question about pinswitch: does this feature allow you to program to fixed groups of modes (two sets of Low-med-high for example), where the mode sets can be selected by the state of the pinswitch pin? If so I am interested in learning how I might include another switch, such as tightening/loosening the bezel or tailcap, to change the pinswitch state and access the alternate mode set. Does the attiny13 have the memory for something like this, or am I misunderstanding the pinswitch feature?

This might be of interest - this link http://hlt.media.mit.edu/?p=1229 gives instructions on how to program an ATtiny using an Arduino

For more information about AVR and ATTiny there is also AVR Freaks...a noob's nightmare ^^

I've successfully reprogrammed several drivers now, using a USBtinyISP programmer that supplies voltage to the target through USB power. I'm now working on modifying the code to so that I can have 4 fixed modes, similar to the changes sixty545 outlined for another member.

My problem is similar to others who have tried to build the code in AVRStudio: the error message "undefined reference to 'start_wdt' " comes up continually. I've solved the util.delay issue by defining the speed of the CPU, however I don't know where to start with this last error. I'm positive I have not changed anything in the code that would cause this, as I tried building the code without any modifications and this error still appears. It also occurs with an older version (0.3) of the code I downloaded. Does anyone know why 'start_wdt' is not defined in this code, and how I can fix this so it will build in AVRStudio5?

-Jon

I finally took the time and made my own driver program (from scratch). It mimics sixty454's UI: 11 modes currently, but once a mode is locked (>2s on), it will restart with the 1st mode as next mode. I have my most used modes at the beginning, no need to cycle through the rarely used modes all the time.

It's my 1st version and leaves room for improvement, as it doesn't have many features: Just various levels of brightness, strobe, beacon. No batt level measurement yet, no off-time-measuring ("pinswitch"), not programmable. And it doesn't have BLF-VLD's flexibility.

The other meaning of "leaves room for improvement" is that there is quite some free space: It uses 480 byte currently. The source code is shorter and maybe a bit easier to see through. Further it uses much less EEPROM writes and a wider wear leveling over 32 bytes. Some kind of ramping could be done.

Next thing I'll probably implement is a 5 minute timer; I have a need for that. My watch can do that of course, but a flashlight doing that is somewhat special :) Won't be very precise though I guess, due to ATtiny's frequency variations, but I think it'll suffice.

Implemented the 5 minutes timer; every minute it blinks out the number of remaining minutes, after 5min it strobes for 10 seconds, then it blinks weakly and slowly (in case you missed the strobe). I like it. :) Costs 126 bytes though.

With XM-L and Nanjg 105C at 1.2MHz and Tido's driver I don't get any output on the lowest level (PWM 1) (I guess the 1.7µs pulse is just too short for the AMCs).

Does anyone of you do? With what settings?

Edit: Hm, I just browsed the thread, Tido seems to use 4.8MHz, I guess with a prescaler of 8 with phase-correct PWM that should give a minimal pulse of 3.3µs and a PWM frequency of ~1.2kHz.

Edit: Ah, I got it now... low fuse 0x69, that's 0.6MHz CPU freq, PWM prescaler of 1, PWM frequency 1.2kHz. Thanks Tido!

Dear Tido,

I am thinking to replace the R2 with a NTC resistor to change the battery monitor to a temperature monitor. I would like to ask for your help to change the RAMPDOWN from every five seconds to let say 30 seconds or 60 seconds. If LOWBAT_RAMPDOWN is not defined, whether LOWBAT_MAX_LVL is also needed to be undifined. Many thanks.

I would like to revise my question as changing the rampdown timing can not solve the problem.

The schematic of my driver

The testing set up

The problem is when the temperature rises to the threshold and the light level starts to rampdown. The light will go out every 5 seconds and will not stop blinking even the temperature drops below the threshold. You have to reset the light manually. I would like to ask for your help to solve the problem. Thanks a lot.

After playing with some lights using my driver for a while I'm quite happy with it and published the code here.

Sorry for not reading through whole thread, but is it possible to use two switches for this ATtiny chip? One for turning it on/off and second one to switch modes (as fenix tk35)?

Sure. There are 5 usable pins for input or output, PWM control uses one of them. You could wire the mode switch to any other pin and write a firmware to react to that.

The driver of my previous post which I modified the battery monitor to a temperature monitor is configured as a 3 level driver, High 0x08, Med 0x07 and Low 0x05. The battery monitor is configured as below;

// Config for battery monitoring
#define MONITOR_BAT // enable battery monitoring
#define LOWBAT_TRIG 130 // trigger level for low battery, see README
//#define LOWBAT_RAMPDOWN // decrease output gradually when battery fails
#define LOWBAT_MIN_LVL 0x07 // minimal PWM level to use in low battery situation
#define LOWBAT_MAX_LVL 0x08 // maximum PWM level to start ramping down from
#define ADC_MUX 0x01 // ADC channel to use, see README
#define ADC_DIDR ADC1D // digital input to disable, see README
#define ADC_PRSCL 0x06 // ADC prescaler of 64

The outcome is that the light level is switched to Low instead of staying at Med when the voltage of the voltage divider is smaller or equal to the threshold. Would like to ask someone to help me to fix the issue. Thanks.

LOWBAT_MIN_LVL and LOWBAT_MAX_LVL are PWM levels, not mode numbers. If LOWBAT_MAX_LVL is 8, then low-batt mode starts at 8/255=3% which is quite low already.

I'd try:

#define LOWBAT_RAMPDOWN // decrease output gradually when battery fails <--- on
#define LOWBAT_MAX_LVL 0x80 // maximum PWM level to start ramping down from <--- start lowbatt mode at half brightness
#define LOWBAT_MIN_LVL 0x02 // minimal PWM level to use in low battery situation <--- gradually ramping down to very low

Thanks again,

I see what you meant. I have confused with the mode number and the PWM level.

I am finally able to flash my drivers. Many thanks to Tido for supplying the tools and info to make this possible and thanks to Jonnyc for walking me through the problem I have been stuck on for a couple months.

Just signed up to say thank you for a excellent thread. I've successfully flashed tido's files, working on compiling so i can modify and build files which will allow me to create the perfect (for me!) driver. It's not easy as computers and me dont really get along but it's interesting and great to learn about something I've been curious about for a while. . BTW the last time i did any programming was in the 1980's with a computer that had 1k of memory how crazy was that!

Now your flashlight (with an Attiny13) has 1K of flash memory! Though, I bet it's a little smaller than the computers you were using then.

Kris

Hi Major,

Welcome to BLF!

Your comments bring back memories, this thread makes me think about trying my hand at programming again. My first attempts were in BASIC on a TRS-80 Model 1, back around that time too. Geez, seems like a while back.

Glad to see so much interest, and so many "mature" users in our ranks. 8-)

later,