Adventures in TinyAVR 1-Series

The Unicorn goes from 2.7A to ~10.5mA (rated 850lm to 3lm), so about about 255:1 dimming range, with a 16mΩ shunt, Vsense= 43.2mV meaning that he manages to read 170uV with a 10bit ADC.

In the gekko he improved the dimming range, 900 to 1lm, probably 2.9~3A to 3mA, so about 1000:1, with a 10mΩ shunt, Vsense = 30mV down to 30uV!.
The board even says 5A-1mA, which would mean a even higher range : Обзор YLP Gekko 1.0 | Обзоры налобных фонарей
(There is one additional resistor and capacitor near the MCU, no idea what they are for).

So yeah, fancy maths indeed.

Edit : the resistor and cap are probably a low pass filter to generate noise via PWM for dithering as mentionned in this App note

There is also an App note about oversampling with Attiny0 and 1 series with example code.

Hi again, been on vacation in Switzerland climbing, cycling, hiking etc etc, and us usual my vacations are email and computer free… so a late reply as I’m catching up a bit.

I’ll just clarify this a little…

With the 3217 I ran it 3.33MHz, then when power off with clicky switch is detected I ran the periodic power on check interrupt by using the ULP (ultra low power) clock at 32.768kHz. With 125ms intervals I got plenty of time, around 10 seconds if I remember correctly. The problem I have with my 1616 driver is not changing the clock, it’s that when the clock switch is done the OTSM cap is drained to the point where detectable off time is too short for me to use (around 1 second). I couldn’t solve it out so I just went with ULP clock all the time. Issues with slow ramping have been sorted so I don’t really have any reason to use any other clock than the ULP now.

With all of this said it could very well be a driver design issue. I’ve only used the 1616 with my boost driver which is 17mm. It’s the first driver that forced me off the larger 3217 due to space constraints. The boost driver has 2 x 68uF input caps and these of coarse have to be depleted before the pin interrupt can detect power off, which in turn can mess a bit with remaining capacity on the OTSM cap once the pin interrupt triggers. Instead of figuring it out completely I just went with ULP all the time as it appears to buy me enough time to use OTSM as intended with my current boost driver design.

Thanks for the clarification.

BTW Digikey just received new stock of Attiny1616-MNR , currently has 1780 in stock.

What is the advantage of OTSM (leaving the MCU powered by a capacitor while the battery is disconnected) instead of OTC? OTC would seem to use smaller parts. Just wondering.

With OTSM you actually keep track of time and can say with certainty “the light was off for 0.73 seconds”. With an OTC you’re just taking a measurement of the capacitor which is fairly imprecise and will change depending on whether the light is hot or cold.

In addition to what gchart wrote, you get different readings depending on the battery voltage with OTC. If light temperature and the actual off time are both exactly the same you will get a different reading if battery voltage is 4.2V compared to if was 3.5V. If you only have a single type of off press in the firmware, not short off and long off doing different things, then OTC is reliable, tried and tested. I have short and long presses in my firmware, OTC is not consistent enough for that.

I find an old posting I made about the subject: Texas Avenger "TA" Driver series - Triple channel + Bistro or Narsil + Clicky or E-switch - The Ultimate open source driver! - #1389 by Mike_C

Thanks, that was interesting, I didn’t realize that the capacitors were that unstable with temperature and (apparently, from the linked thread Off-Time Memory Dependent On Altitude? - Resolved! ) with air pressure. There are stable types of capacitors but I guess they are bigger. I’d hope that resistors are pretty stable either way. You can measure the battery voltage to calculate the RC timing if R and C are known, and you can measure the temperature too, but maybe the capacitance change with temperature is not predictable enough to calculate. It’s still interesting to hear that OTC ends up being too imprecise to distinguish a short from a long button press.

Do you mean you use ULP (32khz clock) literally all the time, and the Anduril UI still works? Is there a reasonable way to switch out of ULP at least some of the time, when more CPU is needed?

There are more stable capacitors yes, X8L for example : 3% max change over 60°C. Though they still have initial tolerance, I see them at 10% from what Mouser has. Plus the DC bias, but that depends what value is needed. I suppose that battery voltage is something that could be accounted for since it’s known ?

Mike writes his own firmware.

IIRC the avr-1 has an internal RC clock that is calibrated at the factory. It’s still nowhere near as accurate as a crystal, but maybe it could be used to measure the OTC capacitance by timing the recharge when the light is turned on. Is accuracy better than 10% really needed to distinguish between a short and long press anyway? I’d expect short press < 150ms, long > 300ms, or something like that, where it’s ok for in-between measurements to not be definite. So 10% either way won’t matter.

I wonder if it’s possible to use the serial port as an accurate timebase to calibrate the other stuff while the chip is being flashed, since the baud rate will derive from a crystal clock in the USB gizmo. Maybe that gets too fancy if it is even doable, though. I’m presuming that putting an xtal onto the driver itself is not really feasible. It would be nice for some things, like turning on the light at a certain time of day. People do keep asking for that.

I use ULP all the time but with my own firmware, never tried Anduril. Switching clock is easy, not and issue for me unless I’m doing it during off press. So far I have not needed to switch clock from ULP but my firmware isn’t complete yet.

No, it won’t matter but I don’t really care, OTSM works fine for me so I personally couldn’t be bothered with all the above.

I can mention that my motivation to stick with OTSM is also due to the way my firmware is written. My firmware is for both off switch (clicky) and E switch (momentary), and it’s much easier to write support for this with OTSM because it’s “real time” press detection just like E-switch presses. With OTC the off presses have to by dealt with on light start up after each press while the E-switch presses are dealt with in real time, two totally different press interpretation methods which just complicates things, at least for me.

And… they’re gone.
But they expect 6000 later this month and 36000 in October.

Edit : the 6000 lasted ~3 days, now they have 34800 in stock

Please help me to modify the RampingIOS-ConvoyH1 to read 2S(8.4V) battery on PA3(pin7) of T412 instead of the VCC.

Damn…There were 23k a few days ago but someone bought the lot.

I think it needs a voltage divider otherwise it’ll fry the chip. Does the driver have one on that pin?

The power for the MCU is supplied through a LDO and there are R1=82K and R2=12K voltage divider on that pin. The internal Vref = 1.1V is remained unchange.

I’ll post code up soon, I have another light that I did RampingIOS with: 2S using a voltage divider. Stand by.

I had cannibalized part of the BLF GT’s Anduril configuration to get the voltage readout in Anduril for my L6… but I lost track of where I saved that. Whoops.

Sorry that it’s not very well documented with comments; it was a copy & paste from a different driver. I commented some things, but you’ll still see old stuff in there like references to UT01.

http://www.ghart.com/blf/firmware/RamingIOS/RampingIOS-WurkkosTS70.c

Many thanks for your help. I shall look into the code and try to figure it out.