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

I'm with Tom E. I have no expertise in the area, but it would seem like you would have to sign a software license agreement or get an copywrite notification of some sort when you purchase or use a qlite driver.

Bill gates got filthy rich off doing that very same thing. :open_mouth:

Did anyone notice a whining on MEDIUM modes (around 700mA output) ??? Low modes are silent, high as well (since no PWM on high, anyway) but medium is there… most of the times the completed module/flashlight needs to be right next to the ear to hear it but apparently there is a way for it to be completely gone…

Dr. Jones’s NLITE is dead silent in all modes but running 18khz PWM… any easy way to change PWM in Tido’s code to 18khz ???

Yes, usually my nanjg drivers do whine on medium mode as well, nothing on low or high however. Actually I think it’s very faint on low mode, but I thought I noticed something last time. You’re definitely not the only one.

Maybe someone might help us with PWM, the drivers at 18khz seems to be dead silent (I believe KDv2 drivers are at 18khz as well, never heard a single one to make any sound)…

I do however like the “cleaner” look of NANJG 105c compared to KDv2… KDv2 seems like it’s printed on cardboard… :slight_smile:

Check out my post here. You need to enable Fast PWM, which is set in the code. I'm not looking at the code right now, but it might be as easy as setting TCCR0A to 0b00100001.

Hello, does anybody know if Tido’s drivers could be used in a flashlight with a momentary switch? I’m trying to replace the circuits of my flashlight with a Nanjg 105C board. Any clue you could give me is welcome because I’m a completly noob :slight_smile:

See here: http://drjones.dyndns.info/

http://budgetlightforum.com/user/417

Very interesting information, thanks a lot. I’ll contact him.

This forum really needs thread search.

Verification:

What is the default PWM frequency setup by Tido in the code?
I have my own calculation and decoded the TCCR0A and TCCR0B but want to verify.
Seems like DrJones uses the same in luxdrv.

Why use phase correct PWM instead of Fast PWM? Pros/cons please.

When one changes PWM freq. I think no other changes are needed.
When one changes the clock are any other changes needed? I hope it can get the delays correctly.

Talking here about default setting that it will start on.
Sure if one plays with clock in code then I think delays etc. do get messed up.

Thanks.

This is from the luxdrv source code:

# MODE/PWM SETUP

#define F_CPU 4800000 //CPU: 4.8MHz PWM: 9.4kHz ####### use low fuse: 0x75

This is what I have compiled in, anyway. Can't answer bout the phase correct or Fast PWM's -- no idea... I think these comments were there originally. I haven't really changed it much - fiddle with compile switch's to get what I want, and have various mode configurations in my source code, and copy/paste when I want to add a new set. I got mine set with Atmel Studio 6.0 - works great, but takes a long time to load for some reason. I didn't like the way the source code was formatted, so cleaned it up, just format wise - don't like loops all embedded on one line, stuff like that. Seems like the author thought the code generated would be more efficient if spaces, tabs, and CR/LF's were left out, looks like... Sorry - I'm a software developer goin back since '78 and have seen a lot of code, compilers, assemblers, OS's, drivers, micros, some PIC's, early gen PC's, etc.-- Yikes! I'm old!

JackCY:

PWM frequency depends on the CPU frequency and the PWM settings (mode and prescaler). Tido's BLF-VLD is supposed for 1.2MHz as CPU frequency (9.6MHz with CKDIV8), resulting in 2.3kHz PWM frequency.

Phase correct PWM has the advantage of being completely off with a value of 0 and completely on with 255. Fast PWM doesn't switch fully off with 0, but it's faster.

If you change the PWM settings, no other changes are required.
If you change the CPU frequency, you need to change the fuses and the F_CPU line.

Tom E: "Seems like the author thought the code generated would be more efficient if spaces, tabs, and CR/LF's were left out, looks like... "
Offense taken.

Hmm the fuses Tido has there in BLF-VLD 0.4 are 79/ED, so 4.8MHz, no divide, 64ms delay, in code there is phase correct PWM and prescaler of 1. BOD 1.8V and selfprogramming enabled. AH! Found it, he sets the F_CPU in the project settings as a compile parameter. Didn’t notice it gets there, the make files are automatic.

Yes for Luxdrv I can see F_CPU in code, nowhere used but F_CPU setting is needed for the delay.h for sure and maybe even sleep.h?

What motivated you DrJones to write your own drivers instead of modding the BLF-VLD?
I have to say BLF-VLD is big, probably unnecessarily but has tons of things there.
The EEPROM seems to be used for the variable modes I suppose, apart from storing the current mode I guess.

Do BLF-VLD, Luxdrv, nlite use PWM on the max setting? Or do they switch the output on steadily without PWM? Or with PWM but constantly on without the single blip down some firmware has?

<— is getting back in business once again, forgot some of the stuff already

May try to decipher the two drivers available and write some of my own.

TomE: format the code, no big deal. Comments are nice BLF-VLD has tons, sure Luxdrv not so much but the code should be self explanatory hopefully once one understands what is what.

I’ve uploaded nlite so far, will test it, but need some of my own custom drivers for other things.

I thought it was 4.8MHz phase correct which brought PWM to 9.somethingkHz (don't have the code in front of me). And I believe F_CPU should only affect delay.h.

That's what I did. I'm not as good of a programmer as Tido or DrJones, but it's fun and it allows me to customize it how I want.

Where did you find these fuses? I guess only the first ones were used with 1.2MHz then; the lowest implemented modes shouldn't even light up at 9kHz PWM.

Yes, F_CPU should not affect sleep.h.

All 3 mentioned firmwares use a PWM level of 255 for high, which means 100% on, no 'blip' as in QLITE.

> What motivated you DrJones to write your own drivers instead of modding the BLF-VLD?
I just had done a few ATtiny13 projects before and found programming a flashlight myself much more intriguing than using someone else's code.

I have too many things to do and program so I appreciate it when I don’t have to reinvent the wheel completely :wink:

The BLF-VLD fuses are in the Eclipse project setting. And also the same are on wiki I think.

What’s the thing with the blip? What did they do wrong? In Qlite drivers? The drivers some people buy so they get “better” firmware without reprogramming?
PWM 254 instead of 255?

They used inverted fast-PWM, where a value of 255 switches completely off, but 0 only switches on for 255 of 256 CPU cycles.

Thanks, I have to read up on the precise PWM output values for the two modes.
My silly question, why even use PWM for 100% output? It seems all drivers do when I look at code. Why not just flip the output ON? In case of correct PWM no difference, just more code :expressionless: So it’s more of a why yes if PWM can keep the ouput steadily on.

You answered your question :)

And I can tell you, in my advanced firmwares I often have to fight for every byte to get all the functionality into ATtiny13's 1kB flash.

Is there a way to get low mode or moonlight mode even lower?
If I remember correctly, seems like the lowest PWM value you can set in Dr.jones code is 5. Anything lower and the led doesn’t light up. I assume it might could be lowered by reducing PWM frequency. When I take a 2800ma amc7135 driver and add a few amc7135’s (increasing current) the output increases in low mode as with all modes. Can a moonlight mode (1 or 2 lumens) still be achieved some how when increasing the number of amc7135’s on a Nanjg 105c driver.