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

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,




Update! So i am able to compile and flash tido's files, incase it helps someone else who's just starting out i had the wrong filename in the makefile (doh!) also i had the chip as a tiny13a switching to tiny13 allowed avrdude and my cheapo ebay $6 programmer to work correctly. Nice moment when it all worked. I'm getting there but am having trouble with the #define's! I would like no memory, programmable, pin switch mode switching, but i'm not sure the mode setting when off for 1second will work with programmable modes, which set when on for a few seconds, please let me know if you've already tried and it does/doesnt work thanks. Better go now, work tomorrow,yawn. Ta

For no mode memory, uncomment the "#define NOMEMORY". Mode programming works with both switching methods. Of course, pin-state based click detection only works if you have added the external capacitor/diode/resistor circuitry.

Hello, everyone.

First of all, thanks for the excellent work you're doing here!

I'm a bit desperate. I'm new to all this stuff (although I've already built many bike lights it never involved programming). I was able to understand most of critical parts of the code, I succeeded in compiling it and making a 2-mode version with no memory. But now I'm really stuck (despite several tons of information I had to learn and process).

I need to switch modes with a momentary pushbutton without interrupting power to the driver. As I understand from the schematics I've seen, the button should short-circuit ground (Pin 4) and some other pin (Pin 3, for example). It seems it has something to deal with the Pin Change Interrupt PCINT0, but, alas, I'm not a coder and I've never used C++ before (only wrote some elementary BASIC stuff many years ago and have already forgotten it all...). Can you just, please, throw some code at me I could use? I'll be most grateful if you also point me on how to tell a short press from a 3sec press and hold.

Thanks in advance.

Hi everybody,

This is seemed off topic. Since I have tried Tido's wonderful program in July, three switches are worn out.

The 2 pieces on the left which I bought from DX only survive for 5 days. The right one which I bought in August finally the power on lock was worn out yesterday. Suppose I switch it 100 cycles everyday, 100 x 30 x 4 = 12,000 cycles. However, the switch is rated 200,000 cycles. Did you guys also have the same problem?

@stronge: That would require a substantial rewrite, as it has to react on an additional switch instead of being switched off. When I get my TK35 clone, I'll probably mod it to a parallel setup with an NANJG105C and then I need to do exactly that. I can post my code then.

@Microa: I doubt it's the firmware's fault... I actually never had to replace a switch yet.

@DrJones: I replaced with a new switch and the light works perfectly well. I think that it would be better to use a on/off switch to control the power, another momentary pushbutton to change mode. The Con is we have to modify the code and the driver board. The clicky switch seems to wear out quickly while changing mode in fast half press.