STAR Firmware by JonnyC - Source Code and Explanation

I’m actually confused here… subtle changes in code make huge differences in bytes used. I think it’s the optimize for size that does a pretty good job when it can, then when it can’t optimize the difference is pretty big. Not experienced with with stuff at all. Working with the volatile bytes takes memory, but so does static bytes.

Anyhow, the latest 13A code I’m writing uses brownout for all presses, and a measurement of the offtime cap for short presses. Ditched long presses altogether.

I might have missed it, so I ask for help:
I am using a zener modded FET version of nanjg driver. I am trying to adjust the low voltage warning for 2s cells.
Are the following correct & enough for that?
#define ADC_LOW 260 // When do we start ramping
#define ADC_CRIT 240 // When do we shut the light off

What resistors? You can't go to 260; 255 is the limit.

* To find out what value to use, plug in the target voltage (V) to this equation
* value = (V * 4700 * 255) / (23800 * 1.1)
*
Followed above. Totally wrong?

The hardware can only use values from 0 to 255. Anything outside that range can’t be handled by code, and requires changing the resistor values instead.

In general, you probably want to keep your values near the middle of that range and not go all the way to the edges. Measurement can get a little weird at the extremes.

Also, you’ll get more precise results by measuring the actual ADC values instead of relying on a formula. But that assumes you already have the resistors configured to give you usable values. The formulas should get you pretty close though.

Can somebody share the resistor values for 2 & 3s configuration?

Anyone can help me with my problem? I built this driver [WIP] 17mm DD+single-7135 driver / single sided / Dual-PWM and installed the blf-a6 firmware. In battcheck mode i always get 5 blinks even if the voltage of the battery is 3.0v. So i flashed it with battcheck firmware to calibrate it but i always get 2-5-5 blinks at whatever voltage of the battery. I am using 22k for R1 and 4.7k R2, do you think that is the problem?

I use R1=82K and R2=12K for 2 cells. R1 directly connected to B+.

VCC

|

8202 (R1 82,000 ohms)

|

|—— PB2 of the MCU

|

1202 (R2 12,000 ohms)

|

GND

ADC = (V_bat * R2 * 255) / ((R1 + R2 ) * V_ref)
196 = (6.6 * 12000 * 255) / ( (82000 + 12000) * 1.1 )
190 = (6.4 * 12000 * 255) / ( (82000 + 12000) * 1.1 )
180 = (6.1 * 12000 * 255) / ( (82000 + 12000) * 1.1 )

The voltage check routine is written with a 19.1K for R1 in mind. With a 22K resistor the input pin is reading a different voltage level. You will have to adjust the battery check values if you want to use a 22K resistor.

Do you mean the battcheck.c firmware is written for 19.1K R1 and i have to edit it so that it can read correct voltage if i use 22k R1? Or do you mean i have to adjust the ADC value of the blf-a6 firmware because it is written for 19.1K R1?
From my understanding, the battcheck.c firmware will read the voltage, then interpret it as 3 groups of blinks so that we can adjust the ADC value. Example on my qlite driver i got 1-3-4 blinks at 3.0v. Then i have to adjust the ADC for 3.0v to 134. But with the driver i built i always get 255 value from 3.0v to 4.2v. How do i edit the battcheck.c firmware so that it will read correct voltage for 22k R1?

I don’t use either of these firmwares so I haven’t tested, just took a quick look at them. The A6 firmware assumes R1 us 19.1K. The battcheck has no notes on what R1 should be, but I assume that it’s also based on R1 being 19.1K as it, together with the 4K7 R2, appears to be the standard. I use these resistors in all my single cell drivers because they work, no need for me to change.

I just did a check and the voltage difference is however not so big between 22K and 19.1K (just under 0.1V), so I guess this is not the problem. Have you checked with a DMM that the PB2 pin on the MCU is receiving correct voltage after the divider? EDIT: If you read 3.2V on the MCU’s PB2 pin with those resistors you have probably swapped R1 and R2.

Something isn't right here, those values should work just fine. There must be another problem you have yet to discover, are R1 and R2 swapped? (R1 goes to batt+, R2 goes to GND) Is R2 open? Measure the voltage at pin7 (ADC input), it should be in the 0.5V to 0.75V range, if not, find out why. If the resistors were removed from another board, they may have been damaged. If they are new, double check their value to be sure they are correct.

Oops, your right. I got mine mixed up… edited my post a little.

The resistors are in the right place and they are new, resistance value is correct. The voltage at pin7 is 0.56v.
Maybe i have a bad MCU? I flashed it with the blf-a6 firmware and modes are working fine.

Did you load BattCheck.hex or did you compile your own version?

I can't believe there is a problem with the MCU, but I've never heard of this problem you're having. I guess its possible an ESD hit took out the ADC and left all else intact...

I got nothin'

If you do replace the MCU, and that works, I'd be pleased but puzzled.

Is there am maximum number of modes that can be put into STAR Momentray? Momentary

It appears to be limited only by available RAM and ROM. With alt PWM enabled, you’re probably limited to about 15 modes, and without that you might be able to get 20 or 25 modes.

If you want enough modes to make a smooth ramp though, you might want to look into Ferrero_Rocher/Ramping_UI_table.c instead.

Thanks! I really only need 7-8 for a driver I’m giving away, so it looks like I’m golden.

Just FYI - It hasn't been announced "officially", but the TheStar FW has been available in TK's repository for some days already (both on- and off-time versions are there).

Feel free to try it and report your findings to me. Thanks in advance.

If this is too much OT for this thread, the discussion can continue in the old TheStar thread.

I just replaced the mcu and everything works fine .now. Thanks