X85 Firmware v1 : http://www.mikec.se/Stuff/X85.zip
Here is a first release of my firmware that I use for my drivers. It’s been totally changed many times, is constantly undergoing changes, has a heap load of crap that is unnecessary, it’s messy and hard understand, and most certainly has bugs in it… But this latest version I’ve tested seems good so far…
The zip file linked above also contains the BAT files I use to flash with AVR dude. As I use the no init “brown out detection” trick for temporary storing stuff it is important that the fuse settings are set correctly, check the BAT files for fuse settings I use. One BAT file is for flashing normally, another when flashing and enabling PB5/reset pin as IO, and finally a test BAT file just to test the clip connection before flashing.
I’ll only start with very basic instructions and will have to fill on more as time goes, it’s just too much. Also, I was thinking about making a “release” version of it, cleaned up without all the development stuff, but to be honest I don’t want to have to manage it. I’ll release what I use in my lights, be it full of stuff that no one else needs or not.
The drivers it supports are the ones I will be listing. The F8 in the OP, G-12 (17mm with 12xAMC7135), G-16 (20mm with 16xAMC7135), BMF-SRK (latest version post #1036: What did you mod today? - #1026 by Mike_C) and the ZY-T08. All of these drivers are available as of now according to the OP in this thread. I just haven’t made dedicated driver threads for them yet, I need a break from my computer screens now…
When compiling for a certain driver type, definitions are used. Here is a quick list of the most import ones:
Driver type: One of these must be defined, the others commented out or removed.
#define F8 // F-8 & ZY-T08
#define G12
#define G16 // G-16 & BMF-SRK
#define LOW // Low output modes for development testing.
Switch setup One must be defined, the other commented out or removed.
#define DUALSWITCH
#define OFFSWITCH
Driver config Define DOUBLE_CELL if driver is for light with 2S config, comment out for 1S.
Define PB5_IO if reset pin will be enabled as IO, comment out if not.
#define DOUBLE_CELL
#define PB5_IO
Note: I have made a fuse reset system with Arduino and a board I’ve designed so I can clip on to the MCU and reset it while it’s in the light. If you don’t have this it will be a pain in the * to flash the MCU again, so you might not want to enable PB5/Reset pin as IO. If not set to IO there are some limitations, and the solder pads on my drivers must be soldered so what ever would have been on PB5 should be soldered to PB3. All my drivers have these solder pads. Pin config for all drivers:
PB0 = PWM dedicated AMC
PB1 = 1 x AMC
PB2 = 2 x AMX
PB3 = 4 x AMC and solder pad.
PB4 = input pin (voltage divider, off time cap and E-switch).
PB5 = Solder pad.
On the F-8 the FET is connected to a solder pad only. This solder pad can be soldered to connect to either PB3 or PB5.
If connected to PB5, then any amount up to all 8 AMCs can be used, but PB5 must be set to be used as an IO with the correct fuse settings. Once set to IO the MCU can’t be flashed again unless you use a high voltage serial programmer and reset the fuses. I have an Arduino and built a addon board according to this page: High Voltage programming/Unbricking for Attiny – Arduino, ESP8266, ESP32 & Raspberry Pi stuff I had a few problems on the way, but it’s now working fine.
If you connect the FET to PB3, then maximum four AMCs can be used as the remaining four would now on the same pin as the FET.
G-12 kind of works the same way, but has four additional AMCs instead of the FET. G-16 has eight additional AMCs. With PB5/Reset pin as IO, any amount of AMCs up to full number can be used, otherwise it’s any amount up to four, then all of them on for boost mode.
I only use PWM on the single PWM dedicated AMC between constant current steps. With 8 x AMCs on as highest mode available before turning on the FET, I see no need to PWM the FET. Not even with 4 x AMC would I care about PWMing the FET, so I won’t be making any firmware version that can PWM the FET.
Interface and modes: There are four “standard” interfaces. How they work is described in the C file.
UI 1 and 2 have up to 4 modes including BOOST.
UI 3 uses RAMP1 and BOOST.
UI 4 uses RAMP2 only.
I use UI 4 for moon mode because it’s not possible to accidentally go from moon to full boost within just a few button presses.
#define UI 1
#define MODECOUNT 4
Modes: The mode values consist of two bytes. The first is PWM value of the PWM dedicated AMC, the second is the amount of AMCs on in constant current.
MAX is basically all output pins on in constant current. However, as I have mode level readouts I’ve defined the readout results differently when all pins are on depending on what driver it is.
#define MODE1 20,0
#define MODE2 100,0
#define MODE3 0,2
#define BOOST 0,MAX
#define RAMP1 15,0
#define RAMP2 15,0
I hope the rest of the definitions down lower are self explanatory, at least enough until I get some instructions written… The amount of time it’s taken me to get to this stage is pretty long, so don’t hold your breath for full instructions, it’ll take some time. There are comments next to a lof of stuff, some of them should assist.
Almost everything is user configurable… but how to configure it all is quite complicated… If everything is defined correctly from the start, not much should need to be user configured. However, I’ve noticed that when compiling for DOUBLE_CELL (2S config) drivers, the voltage should be calibrated. I had to keep the same resistor values for 2S or the off time cap would take too long to charge. To solve this I switched to 2.56V internal reference voltage for 2S drivers. It works, and should work OK out of the box, but the measured results are more off than with 1.1V on 1S lights so I do the calibration routine… Well, to be fair I wrote this firmware so I know how to use it, it’s pretty easy for me so I calibrate all my lights.
A list of what can be configured on the light by the user (all options configurable with both dual switch and off switch only setups).
UI 1 to 4, mode count 1 to 4, all mode brightness levels, mode direction, boost timer, low voltage monitoring, low and critical voltage thresholds, critical low output mode or shutdown, temperature monitoring, max temp threshold, mode memory (can include or exclude boost).
Special modes and functions:
Strobe and beacon with brightness modes and speed adjustment, SOS with brightness modes( no speed adjust), noob mode, safety lock, two reset to default routines (one without calibration values, the other a full reset).
There is also the start of an experimental routine that checks the temperature profile of the host (cooling time). I haven’t touched this code in a long time. So far I am OK with just high temp step down, but I’d like to have some sort of thermal regulation later.
I first made the dual switch version with all it’s options. When making a off switch version I originally stripped out most of the config crap, but later changed my mind and “ported” all dual switch config options to off switch and then combined it all by #definitions. By doing it this way the code is definitely not optimized, it just makes managing easier as I don’t have to change function specific code in two places.
I’m planning on making an E-switch only version… someday…
That’s enough for now, I can answer questions about this stuff here and add instructions as I go along… providing there is some sort of interest of coarse.