STAR Firmware by JonnyC - Source Code and Explanation

BTW, I’m not really sure where to announce this, but I added a tagging system and an auto-generated index to the firmware repository. I hope this will make it easier for people to find code relevant to their needs.

The latest index should always be here:

http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/view/head:/INDEX

Nice. I usually end up throwing a few features out the window (Star functionality; LVP blinks, etc.) whenever I need more space, but I'm too lazy and ignorant to do anything more advanced!

I expected someone to have done it, but usually only check standard Star as reference, too many firmwares to go through. You could probably further optimize it by using the brownout detection method for those fast presses instead of storing them in the EEPROM. By doing this you can fit everything you need to store in a single byte. You’ve probably already done it though, but in another firmware :slight_smile:

Once I’m done with the 85 firmware I’ll just switch to it on all future builds, they don’t cost that much more and with some pin bending they fit nicely on the 13A footprint. This byte hunting is sometimes too time consuming. Still have some 13As to use up though, which is why I’m still at it.

Nice with that firmware repository. Might have to get me a trunk there and upload some stuff someday, but it might not be of use to many as I’m using totally different pins than the standard 105 layout. None of my firmwares are directly compatible with them.

I haven’t tried mixing brownout plus eeprom yet, but I may have to do a quick mod to see if it ends up using less space. :slight_smile:

Go for it! I think people would be very interested to see your code, especially because you’re using different MCUs and different pin layouts. We could use some fresh ideas around here. :slight_smile:

Since it’s not really STAR any more, it might be good to switch over to a different thread to avoid cluttering this one any more. I know I’ve dumped too much off-topic stuff in other threads, so I made a new thread for firmware in general:

I would imagine we could also use a thread for info on your driver hardware, if you’re willing to write up the details. I liked the M6 “BMF” thread, and would love to read more about your other work.

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