E-switch UI Development / FSM

I did modify the GT configs to make it working with ramping

and there is again the problem tweaking the voltage readout
that voltage fudge factor –15 makes the firmware go wtf I quit, and a 182k over the 47k is not really a nice solution

Hello guys. I’m new to the flashlight game and I have a Sofirn SP36 still shipping to me. After some research, it seems like Anduril is much better than the stock firmware. Would anyone help me explain how do I flash it to my sp36 when it’s here? What tools do I need?? Thank you so much :slight_smile:

Been looking at the voltage monitoring code (fsm-adc). I assume you want to do good old voltage divider readings, so USE_VOLTAGE_DIVIDER must be turned on, then the VOLTAGE_FUDGE_FACTOR is irrelevant.

The voltage divider readings is scaled based on ADC_22 and ADC_44, which I assume have to be set according to what resistors you use.

You could probably copy the values from NarsilM.

I'm not sure if anyone tried it this way? Looks like the old voltage_blinks[] arrays in tk-voltage.h are not used in Anduril because fsm-adc has it's own copies. I dunno if TK or others ever tested/used this with external voltage divider resistors?

The "stock" firmware is NarsilM, v1.2. Updated version than what came in the Q8, same baseline as the BLF GT. The UI mostly got outstanding reviews out of 100's posted between Amazon and Banggood on NarsilM, not to mention many accolades in video reviews, so it can't be that bad? Slightly better than the "lo-med-hi-strobe-sos" of an UltraFire?

But if you still do wanna upgrade, first challenge is getting access to the driver, then you'll need the programming clip/USB cable, then the latest hex file, probably from here: http://toykeeper.net/torches/fsm/?C=M;O=D. We mostly use AVRDUDE to do the download. There's some really good info already here on BLF somewhere of how to get the cable and software tools you'll need - hope someone else can chime in.

Ahh I see. Yeah it’s NarsilM is much better than simple old style control haha. Anyways. I’ve heard that the sp36 has glued board? And thanks for your answer !! :slight_smile:

Thanks!! Gonna add this to my bookmark!!

As I said two weeks ago, and as Tom said just now, the fudge factor is not relevant for a light which uses a voltage divider. Use the voltage divider method instead, by setting USE_VOLTAGE_DIVIDER… just like in the BLF GT cfg and hwdef files.

The driver is glued, and not easy to remove. I’d suggest looking in the SP36 thread for info about how to get the driver out.

After that, the firmware part just needs some cheap hardware and free software. Click the Link in my signature for more information.

Ahh thanks for your reply. :slight_smile:

I had already the voltage divider activated from GT cfg
But at 3V per cell it reads 3.7V on the blinkout
the voltage fudge factor works to –10, but at –15 the voltage readout blinks 2 times then bugs out

I also wrote that the ADC values in the GT file do not change the voltage reading at all

those lines do not work I dont know where it takes place that the voltage reads so I could modify it

this bugs out the voltage reading, and i can not find any TK voltage file or so which calibrates the readings

When I get home on 26th, I can take a look at that for you.

Do you have some specs for me? (e.g. Voltage divider 40k / 60k on PB2)

Divider 360/47k as usual has 0.7V too high reading with GT config file

I’m not that familiar with “as usual”. But are we talking about this schematic?

R1=?
R2=?

Yes R1 360K R2 47k

needs different ADC values than 1000k 47k on 4S builds

Lexel - from exactly what you describe, it sounds like the USE_VOLTAGE_DIVIDER is not set, least where you want it to be set.

If ADC_44 and ADC_22 don't do anything, and VOLTAGE_FUDGE_FACTOR does do something, that only means USE_VOLTAGE_DIVIDER can't be set. That looks pretty obvious to me in fsm-adc.c, which is where the voltage readings are done. Pin assignments are critical of course.

no I get definately the reading from Pin7 as if I change the divider or input voltage the voltage readout differs
MCU is set on 5V LDO

that fudge also affects divider while the ADC 22 does nothing

it seems that somehow the divider resistors are read out but are interpretated by the 1S code

I use the original GT config(PWM values are from 1S overwritten) just copied the fudge factor in for testing,
finally editing it out and done it tweaking the divider

on the GT driver 2 weeks ago I did the same correcting the voltage readout difference with the fudge factor
after people said me that affects the voltage reading

Oops, just realized VOLTAGE_FUDGE_FACTOR is used for the voltage divider (as you just said):

static inline uint8_t calc_voltage_divider(uint16_t value)

{
// use 9.7 fixed-point to get sufficient precision
uint16_t adc_per_volt = ((ADC_44<<7) - (ADC_22<<7)) / (44-22);
// incoming value is 14.2 fixed-point, so shift it 2 bits less
uint8_t result = ((value<<5) / adc_per_volt) + VOLTAGE_FUDGE_FACTOR;
return result;
}

Tricky thing is the AtoD should be 10 bits, but only 8 bit ADC voltage levels are used -- weird. DEL wrote some really good code for doing this, and I simply stole it (errrr copied it) for NarsilM. Don't muck with something that works, sort of thing.

Didn't check the math/bit stuff but the equation certainly takes ADC_22 into account - depends what units adc_per_volt is in.

yes but i would prefer the ADC 44 and 22 values to calibrate the voltage divider like NarsilM does with the TK.cal file

like I wrote when I change the fudge factor to –15 to get that 0.75V down the readout code bugs out it blinks 2 times then quits working

At last, two things I understand in this thread. :smiley:

:beer: