Is there a way to use Linghtning Storm or Candle Mode with Aux LEDs instead of Main ? If not i would love to see this on my Wurkkos TS10.
Thanks for the data, a press-fitting adapter around the battery does eliminate a possible misalignment issue.
There’s one other size-related possible issue I just remembered: when I started experimenting with my FC13 and its 18350 tube, its tail spring didn’t put enough pressure on the back of the battery to assure a reliable contact – so it failed the famous[1] “Maracas test” (turning on the light and shaking it as viciously/vigorously as possible makes it go off, or at least blink – as if the tube was briefly unscrewed and then screwed back again). So I had to pull on the spring end with pliers to force it to extend a little, and that fixed it (but not before the spring came out in my hand and demanded a lot of effort to get it back in place – and I’m still not sure it’s firm enough or if will come apart anytime).
So, I gotta ask: does your TS11 pass the Maracas test? If it does, then only the possible voltage sag issue would remain.
[1] term learned from @1Lumen: Nightwatch NS14 review | 43,000 lumens flashlight | 1Lumen.com
Thanks for the confirmation. Re: the weird behaviors you mentioned, a full battery could perhaps show a larger voltage ‘swing’ when demanded and produce … but it’s hard to know for sure, better to just try and eliminate it as a possible issue as me and @AK-Adventurist are doing right now.
Fixed… for real, this time. In the end it was just one missing character in this line. At least I thought so.
ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm; // Enabled, free-running (aka, auto-retrigger)
Do you see it? The control register is set to the given value. But my changes to bring everything in the right order has moved one important line before this line:
// set the RUNSTDBY bit so ADC will run in standby mode
ADC0.CTRLA |= 1;
So first, bit 1 of CTRLA
was set, then everything got replaced with the next line. This is totally my fault because previously the order was switched. Let’s clean this up, it’s not bad to set all control registers at one place because eventually it will result in the same outcome. And let’s use a proper definition instead of the magic number… 1
… what?! Why 1
?
#define ADC_RUNSTBY_bm 0x80 /* Run standby mode bit mask. */
D’oh! This can’t work, the ADC did never run in standby mode! Depending on the remaining instructions before going to sleep, it finished, or it didn’t.
To sum it up, here is my proposal that should fix this bug and cleans up control register setup a little bit.
--- a/ToyKeeper/spaghetti-monster/fsm-adc.c
+++ b/ToyKeeper/spaghetti-monster/fsm-adc.c
@@ -83,11 +83,6 @@ inline void adc_sleep_mode() {
// attiny1634
set_sleep_mode(SLEEP_MODE_ADC);
#elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- // set the RUNSTDBY bit so ADC will run in standby mode
- ADC0.CTRLA |= 1;
- // set a INITDLY value because the AVR manual says so
- // (section 30.3.5)
- ADC0.CTRLD |= (1 << 5);
set_sleep_mode(SLEEP_MODE_STANDBY);
#else
#error No ADC sleep mode defined for this hardware.
@@ -133,10 +128,10 @@ inline void ADC_on()
ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | ADC_PRSCL;
//ADCSRA |= (1 << ADSC); // start measuring
#elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- set_admux_voltage();
VREF.CTRLA |= VREF_ADC0REFSEL_1V1_gc; // Set Vbg ref to 1.1V
- ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm; // Enabled, free-running (aka, auto-retrigger)
- ADC0.COMMAND |= ADC_STCONV_bm; // Start the ADC conversions
+ ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm | ADC_RUNSTBY_bm; // Enable ADC, free running mode, run in standby
+ ADC0.CTRLD |= ADC_INITDLY_DLY16_gc; // Delay first measurement to stabilize reference
+ set_admux_voltage();
#else
#error Unrecognized MCU type
#endif
It was a combination of:
- not configuring the ADC to run in standby
- starting the conversion before configuring the delay to stabilize the reference
Hey hey hey!!! GREAT NEWS!!!
So I presume that you can no longer get the issue to happen on your TS11, contrary to before that change, right?
If so, first of all, CONGRATS!
And second, with your authorization, I would like to produce a full set of hexes incorporating it, both for TK’s pristine rev 725 and for it with my 8C mod.
The TS25 with the 18350 is compressing the spring over 3/8", its under good tension(assumedly perfect since this tube and cap combo are sold for a 35mm battery, just of bigger dia. )
My TS11 is always loaded with a 18650, I have no need for compact carry on a light that is never carried… Its very tight as well, probably 1/4" spring compression with its(currently) Sofirn SC18 tail cap(and body from a HD15).
I went back to a spring loaded tail cap specifically for testing this, for these reasons you’ve mentioned, and also, in normal use I have No tail spring in my TS11, (Nor on three other lights that run flawlessly) I’m using custom 3D printed tail caps, they are non conductive, so I use a custom flat metal end spacer, and small magnet to connect the batteries to the tube. That way it is tight tension directly to the battery.
If anything it compresses the plastic threads slightly to hold tension. Have had no issues there with anything being loose, but I removed this from the equation on the TS11 and went back to a stock spring cap to make sure a resistance difference from stock wasn’t causing the issues, and have stayed with it for all test since. But there has been no glitch/bug difference with either cap setup.
The TS11 will pass what I call a whack test, either slapping my palm with the light head, or tapping the workbench; no flicker etc… Have not bothered with the TS25, since I never questioned the battery tension there.
Thanks for reporting back.
Now that @SammysHP reports having fixed the issue (at least with the TS11), I’m waiting for his OK to produce new hexes incorporating his fix for all lights, then I will ask you to kindly test both your TS11 and TS25 with it and see whether any issues remain.
Stay tuned!!
Correct, seems to be fixed. Tried with different voltages and it’s running for 15 minutes without issues.
Sure, go ahead! It’s GPL after all and I hope that @ToyKeeper can merge it soon.
Next step would be to add better smoothing or a hysteresis because right now it alternates between blue and magenta every second…
Again, congrats! You fixed something that has escaped a lot of eyes and minds, including mine!
I’m going right ahead and incorporating your fix and producing the two sets of hexes with them. Will again post links here when they’re ready.
One idea for that would be to use a “moving average” implemented by storing the last N (say, 3) measurements in an array, with the newest always replacing the oldest, and then using their arithmetic average as the final value. Maybe I will give it a try once I produce those initial set of binaries…
[quote=“SammysHP, post:467, topic:218045”]
To sum it up, here is my proposal that should fix this bug and cleans up control register setup a little bit.
```
```
[/quote]
This is failing to compile for a lot of lights (including all the Wurkkoses) with the following error:
</s> <s>avr-gcc -DCFG_H=cfg-wurkkos-ts25.h -Wall -g -Os -mmcu=attiny1616 -c -std=gnu99 -fgnu89-inline -fwhole-program -DATTINY=1616 -I.. -I../.. -I../../.. -fshort-enums -B /home/normal/mnt_-_src_-_flashlight/http_-_packs.download.atmel.com/Atmel.ATtiny_DFP.2.0.368/gcc/dev/attiny1616/ -I /home/normal/mnt_-_src_-_flashlight/http_-_packs.download.atmel.com/Atmel.ATtiny_DFP.2.0.368/include/ -o anduril.o -c anduril.c</s> <s>In file included from ../spaghetti-monster.h:62:0,</s> <s> from anduril.c:77:</s> <s>../fsm-adc.c: In function ‘ADC_on’:</s> <s>../fsm-adc.c:132:55: error: ‘ADC_RUNSTDBY_bm’ undeclared (first use in this function)</s> <s> ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm | ADC_RUNSTDBY_bm; // Enable ADC, free running mode, run in standby</s> <s> ^</s> <s>../fsm-adc.c:132:55: note: each undeclared identifier is reported only once for each function it appears in</s> <s>
I presume you have a different set of AVR include files than I have here, where that macro is defined.
Anyway, I’m now having a closer look to try and fix it.
[quote=“dmenezes, post:474, topic:218045, username:dmenezes”]
Anyway, I’m now having a closer look to try and fix it.
[/quote]
And here’s my quick-and-dirty fix:
</s> <s>--- ToyKeeper/spaghetti-monster/fsm-adc.h.orig-2023070501 2023-04-26 03:34:53.000000000 -0400</s> <s>+++ ToyKeeper/spaghetti-monster/fsm-adc.h 2023-07-05 14:59:13.554135370 -0400</s> <s>@@ -4,6 +4,11 @@</s> <s> </s> <s> #pragma once</s> <s> </s> <s>+#if ATTINY==1616</s> <s>+ //We are defining this directly as it's missing from include/avr/iotn1626.h (at least for Atmel.ATtiny_DFP.2.0.368)</s> <s>+ #define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */</s> <s>+#endif</s> <s>+</s> <s> #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION)</s> <s> // use raw value instead of lowpassed value for the next N measurements</s> <s> // (2 = 1 for voltage + 1 for temperature)</s> <s>
With that, ./build-all.sh
builds the exact same set of hexes than before your fix.
Anyway, testing it here on my lights before releasing the hexes.
Just a typo, pasted the wrong patch here. Fixed above.
Got it, thanks. The really curious part is that your mistyped macro was indeed defined in a lot of avr/include files, just not on the one specific to the AT1616:
$ grep -ri ADC_RUNSTDBY_bm .
./include/avr/iotn424.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn427.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn426.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn3224.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn824.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn1624.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn1626.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn826.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn3227.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn3226.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn827.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./include/avr/iotn1627.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn427.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn3226.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn1627.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn1626.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn3227.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn426.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn424.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn1624.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn3224.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn826.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn827.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./xc8/avr/include/avr/iotn824.h:#define ADC_RUNSTDBY_bm 0x80 /* Run standby mode bit mask. */
./avrasm/inc/tn824def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn427def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn826def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn3226def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn1627def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn3224def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn1626def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn3227def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn1624def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn426def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn424def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
./avrasm/inc/tn827def.inc:.equ ADC_RUNSTDBY_bm = 0x80 ; Run standby mode bit mask
EDIT: and the EVEN MORE curious part is that the correct macro has EXACTLY the same value (0x80) !!!
./avrasm/inc/tn1616def.inc:.equ ADC_RUNSTBY_bm = 0x80 ; Run standby mode bit mask
LOL
Anyway, removing my fix to your fix and using your new diff above.
And here they are:
- TK’s pristine (or accordingly to @AK-Adventurist, “unmolested”
) rev 725 plus @SammysHP ADC fix: https://www.durval.com/xfer-only/anduril_multi-channel_rev_725-SammyHP_ADC_fix.zip
- Ditto, plus my 8C_quick_aux_switch mod: https://www.durval.com/xfer-only/anduril_multi-channel_rev_725-8C_quick_aux_switch+SammyHP_ADC_fix.zip
A quick test on my TS10 seems to indicate all is OK, but everyone please do test extensivelly on all lights and kindly report back.
I’m specially interested in @AK-Adventurist TS11 and TS25 tests as he was the one that originally brought these issues up.
Thank You!
Delivering hexes to the uncoded masses… lol
WOOOHOOOO!!!
@SammysHP you are a genius!!
AND thank you to @dmenezes again for the fast hex production, and all of your help too!
Does indeed fix all issues I had with the TS11!
no blink in standby, no blink in lockout, no 30 second (or any time frame so far) auto unlock, and no unlock after 8C aux switch, or 7C aux changes!!
I have only flashed the 8C mod, since I had the most problems with that one. (on a fresh 4.1v battery as well just in case)
I am a bit leary of re flashing the TS25… Its been my EDC since it came and I’m getting more than a bit tired of re-setting up all of my output modes lol. I’ll charge an 18350 and the 21700 today, and flash it before tomorrow morning though, let you know how it is before I disappear until Sunday(church camping trip).
All hail @SammysHP, the wizard of ADCs and interrupts!
I aim to please!
Seriously, thanks for reporting back, and glad everything seems to be working now, at least with the TS11 and a full 4.1V battery!
Hope we can hear from you about the half-dead battery tests before your camping trip, but if not, have a great one and tell us all when you get back!
Hey, just had a curious thought, @Light_Veteran started all of this in a way, the 8C aux switch was their idea… Yes I’ve had issues with the main branch on the TS11, but the 8C mod started me seeing it.
I just tried to read back through the last month of this thread but am not sure I didn’t miss something… Did it work ok without any glitches of your light @Light_Veteran ?
Anyway, like I said, just curious if any of this happened to show up in other lights its been put on, outside the ones(T10, TS11, TS25) we’ve been checking here recently.
Yeah, reasonably easy to just store the last N values or a sample every N, and if it it’s close to the threshold and crosses it (perhaps more than once over the moving window?) to just hold the value low.