Hello!! New user trying to programm a nanjg 105c!!

Guys, I don’t use BLF-VLD or DrJones programs, and I don’t even have AVRStudio installed on my laptop…

But, I know lots of you do. Someone send a copy of a (working) compiled hex/eep to OP so that he can see if the failure is in code/compiling or burn/programming.

If you need an easy way to send him the files, zip them up and drop them at
www.brightlightmodules.com/BLF

PPtk

Burning is not my problem for sure as I can burn the programs on the chip but the only ones I get to work are the sixty545 8 mode program and Tido’s simple… *I have burned tidos default and fixed also with success so it seems that the luch of programming knowledge is the problem for me…

I just can’t figure out what to do and how to do my program using tido’s files…

Whatever I do seems ok but when I burn it it doesn’t work…

If anyone can make or have ready a working program of 5–15–30–50–100% without memory and share it or a simple driver.c file that can be easily modified it would be great…

As it seems I can only burn already working hex and eep files fine but I do not manage to modify a c file with success…

I feel your pain. I finally installed all the software and need to read through that daunting thread. 600+ posts in that thread and info scattered all throughout. It would be wonderful if someone with experience would write a fresh step-by-step thread on how to do it from beginning to end. I'm sure I'm not the only one who appreciate the time taken.

georgek, didn’t the new luxdrv source with the changes I PMed you work?

Dr Jones I have been trying from the time I have read the pm you send me to find the lines but with no luck. Two are the possible situations, I am blind or something is wrong with the file I have…

Take a loom please…

I am pasting your luxdrv3.0

//
// LuxDrv 0.30 DrJones 2011
//
// 994 bytes with ramping and timer
//
// License: Free for private and noncommercial use for members of BudgetLightForum
//
// changes:
// 0.1 first version: levels,strobe,beacon,timer(136) (638bytes)
// 0.2 ramping(200), improved timer(180), skip mode1 as next mode if already in mode 1 (898bytes)
// 0.21 changed EEPROM handling to reduce power-off-while-writing glitches —>eepsave(byte) (874bytes)
// 0.22 bugfix in ramping; mode not stored on (very) short tap (878bytes)
// 0.3 battery monitoring added; step down and indicator in beacon mode (994bytes)

//ToDo:
// ? off-time checking; requires adding diode,R,C
// ? blink your name in morse code :slight_smile:

#define outpin 1
#define PWM OCR0B //PWM-value

#define adcpin 2
#define adcchn 1

#define portinit() do{ DDRB=(1<<outpin); PORTB=0xff~~~~(1<<adcpin); }while(0)

#include <avr/pgmspace.h>
#define byte uint8_t
#define word uint16_t

//########################################################################################### MODE/PWM SETUP

//251, 252, 253, 254 are special mode codes handled differently, all other are PWM values

#define F_CPU 4800000 //CPU: 4.8MHz PWM: 9.4kHz ####### use low fuse: 0x75 #######
PROGMEM byte modes={ 0, 6,51,255, 254, 251, 252, 253 }; // with ramping
// dummy main modes ramping, ramped mode, strobe, beacon, timer
#define TIMER 5 //use timer (5 min, max 6 in this setup)
#define RAMPING //use ramping
#define MINPWM 5 //needed for ramping
#define RAMPMODE 4 //the number of the ramping mode (254) in the modes order; e.g. ramping is 4th mode -> 4; not counting dummy
#define LOCKTIME 12 //time in 1/8 s until a mode gets locked. 12/8=1.5s
#define BATTMON 125//enable battery monitoring with this threshold

//PROGMEM byte modes={ 0, 6,51,255, 5,6,14,37,98,255, 251, 252, 253 }; // 9kHz modes, 5 is lowest, no ramping
//// dummy main modes more levels strobe,beacon,timer

//###########################################################################################

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/eeprom.h>

#define WDTIME 0b01000011 //125ms

#define sleepinit() do{ WDTCR=WDTIME; sei(); MCUCR=(MCUCR &~0b00111000)|0b00100000; }while(0) //WDT-int and Idle-Sleep

#define SLEEP asm volatile (“SLEEP”)

#define pwminit() do{ TCCR0A=0b00100001; TCCR0B=0b00000001; }while(0) //chan A, phasePWM, clk/1 ->2.35kHz@1.2MHz

#define adcinit() do{ ADMUX =0b01100000|adcchn; ADCSRA=0b11000100; }while(0) //ref1.1V, left-adjust, ADC1/PB2; enable, start, clk/16
#define adcread() do{ ADCSRA|=64; while (ADCSRA&64); }while(0)
#define adcresult ADCH

#define ADCoff ADCSRA&=~(1<<7) //ADC off (enable=0);
#define ADCon ADCSRA|=(1<<7) //ADC on
#define ACoff ACSR|=(1<<7) //AC off (disable=1)
#define ACon ACSR&=~(1<<7) //AC on (disable=0)

//_

volatile byte mypwm=0;
volatile byte ticks=0;
volatile byte mode=1;
byte pmode=50;

byte eep[32]; //EEPROM buffer
byte eepos=0;

#ifdef RAMPING
byte ramped=0;
#endif

byte lowbattcounter=0;

void eepsave(byte data) { //central method for writing (with wear leveling)
byte oldpos=eepos;
eepos=(eepos+1)&31; //wear leveling, use next cell
EEARL=eepos; EEDR=data; EECR=32+4; EECR=32+4+2; //WRITE //32:write only (no erase) 4:enable 2:go
while(EECR & 2); //wait for completion
EEARL=oldpos; EECR=16+4; EECR=16+4+2; //ERASE //16:erase only (no write) 4:enable 2:go
}

inline void getmode(void) { //read current mode from EEPROM and write next mode

eeprom_read_block(&eep, 0, 32); //+44 //read block
while((eep[eepos]==0xff) && (eepos<32)) eepos; //+16 //find mode byte
if (eepos<32) mode=eep[eepos];
else eepos=0; //+6 //not found

byte next=1;
if (mode==1) next=2; //+10

#ifdef RAMPING
if (mode & 0x40) { //RAMPING
ramped=1;
if (mode & 0x80) { next=RAMPMODE+1; mode&=0x7f; } //mode: for savemode
//else next=1
}else //ENDRAMPING
#endif

if (mode & 0x80) { //last on-time was short
mode&=0x7f; if (mode>=sizeof(modes)) mode=1;
next=mode+1; if (next>=sizeof(modes)) next=1;
} //else next=1; //previous mode was locked, this one is yet a short-on, so set to restart from 1st mode.

eepsave(next|0x80); //write next mode, with short-on marker
}

ISR (WDT_vect) { //WatchDogTimer interrupt
if (ticks<255) ticks;
if (ticks==LOCKTIME) eepsave(mode); //lock mode after 1.5s

#ifdef BATTMON //code to check voltage and ramp down
adcread();
if (adcresult<BATTMON) { if (++lowbattcounter>8) {mypwm=(mypwm>>1)+3;lowbattcounter=0;} }
else lowbattcounter=0;
#endif
}

int main(void) {

portinit();
sleepinit();
ACoff;
#ifdef BATTMON
adcinit();
#else
ADCoff;
#endif
pwminit();

getmode(); //get current mode number from EEPROM

byte i=0;

#ifdef RAMPING
byte p,j=0,dn=1; //for ramping

if (ramped) { //use the ramped mode
pmode=255; i=30-MINPWM~~; while(i—){pmode=pmode~~(pmode>>3)–1;} //get PWM value //never gives 250…254
} else
#endif

pmode=pgm_read_byte(&modes[mode]); //get actual PWM value (or special mode code)

switch(pmode){

case 251: mypwm=255; while(1){ PWM=mypwm; _delay_ms(20); PWM=0; _delay_ms(60); } break; //strobe 12.5Hz //+48

case 252:
#ifdef BATTMON
adcread(); i=adcresult; while (i>BATTMON) {PWM=8; SLEEP;SLEEP; PWM=0; SLEEP; i-=5;} SLEEP;SLEEP;SLEEP;
#endif
mypwm=255; while(1){ PWM=mypwm; _delay_ms(20); PWM=0; i=70;do{SLEEP;}while(—i); } break; //beacon 10s //+48

#ifdef TIMER
case 253: i=TIMER; do{ //+180
byte j=i; do{PWM=255; _delay_ms(20); PWM=0; _delay_ms(300); }while(—j); //blink remaining minutes
byte k=30; do{ byte m=0; do{ //wait 1 minute
if (m<i) {_delay_ms(233);PWM=8;_delay_ms(90);PWM=0;}
else _delay_ms(333);
}while(++m<6); }while(—k);
}while(—i); //for TIMER min
i=100; do{ PWM=255; _delay_ms(30); PWM=0; _delay_ms(70); }while(—i); //strobe 10s
while(1){PWM^=8;SLEEP;} //”off”
break;
#endif

#ifdef RAMPING
case 254: ticks=100; //crude way to deactivate the 2s-lock //RAMPING
while(EECR & 2); //wait for completion of getmode’s write
while(1){ p=255; i=30-MINPWM-j; while(i—){p=p-(p>>3)–1;} //ramp up
PWM=p;
eepsave(192+j);
SLEEP;
if (dn) {if (j ) j—; else {dn=0;SLEEP;SLEEP;} }
else {if (j<30-MINPWM) j; else {dn=1;SLEEP;SLEEP;} } //wear leveling
} break;
#endif

default: mypwm=pmode; while(1){PWM=mypwm;SLEEP;} //all other: us as PWM value

//mypwm: prepared for being ramped down in WDT on low-batt condition.

}//switch
return 0;
}//main

Johny,

I have read through the thread more than 5 times but i don’t seem to have any success…

I can admit that I learned how to burn the hex and eep into the chip and verify them…

But they have to be tested and working from someone experienced. The 8mode sixty545 made,the simple, default, and fixed from tido and the luxdrv1 from drJones(but for this I get only one low mode, I dont know why).

DrJone even told me which line to modify but I was not able to even find the lines int the file all day today (I think that there is something wrong with the file I have or I will need to have my eyes checked)

You got the old version of luxdrv, download it again…

How stupid am I??

I have been trying all day to find something tha didn’t exist in the file…
hahaha fortunately I won’t need to have my eyes checked!!

I will download it 2morrow cause I am on a mobile now and build the hex and eep and try it out!! I hope it will work!!

Thanks a lot drJones!!!

You Guys here I blf are the best!!!

Thanks to everyone especially DrJones, The Ninja Guy and Sixty545 for helping me so much!!!

You guys rock!!!

Missed this thread.
A formal welcome to you georgek.
You made a great choice joining BLF. Everyone is very nice and willing to help. We are like one big family. :slight_smile:

And we expect to be written into your will… J)

Will do. Everyone gets a flashlight part. :wink:

I call dibs on the shiny parts… :party:

a tacticool shiny part?

I can only get to you when I get my Eclipse and stuff going, upload some default drivers myself and then go make my own. I may or may not make a simple guide if that is needed JohhnyMac.

I am happy that I am a part of this family now…

I have to admit that I have never received so much help so quick in any other forum…!!

I have some drivers and xm-l u3 to write in my will who wants what?? oh and hundreds of tools…! :slight_smile:

what flashlight you moded?

I modded a tk35 clone with an xm-l u3,

I also made my own custom pcb boards so I don’t have to destroy the original curcuit by disoldering everything to use them as contacts for the nanjg 105c…
And made the to have the batteries in parallel…

I also remover the mode switch…

Pity. In my opinion the separate mode switch is one of the best properties of the TK35 (and it’s clone). (You know the TheKlone35 thread?)

yes dr Jones, I know it, and i liked a lot the driver you made that can use the mode switch…

but unfortunately at the time I started moding the light and making the pcbs I was trying hardly to even make a working hex and eep from tido’s files and from yours luxdrv and did not knew a lot…

I was so piassed that I said hell, I will just put a standard nanjg 105c and made the pcbs for one switch…

after I finished everything hardware related I saw that I could just tell you too send me a driver…

now to make the light again suitable for mode switch I will have to remake the pcbs and I don’t have time…

In a month from now I will get back home so I will have some time to make new pcbs and I will be glad to talk to you on how to make them for your 2 switch driver and buy some drivers from you ready to use with 2 switches!!