STAR Firmware by JonnyC - Source Code and Explanation

1335 posts / 0 new
Last post
RMM
RMM's picture
Offline
Last seen: 1 month 1 week ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

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!  

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

Mike C
Mike C's picture
Offline
Last seen: 1 hour 3 min ago
Joined: 01/22/2014 - 08:03
Posts: 2098
Location: Sweden

ToyKeeper wrote:
Mike C, I did the same thing in the blf-a6 firmware. Smile

So, the blf-a6 code can be used as a reference for handling eeprom more space-efficiently. It also shows how to store multiple values, if desired, or how to store just the mode index. (full blf-a6 uses multiple values, trimmed-down version just stores one value)

BTW, there are some library functions which can be used instead of accessing the eeprom registers directly. This should make the code a little more portable to different MCUs, and might also make the code smaller or less likely to break.


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 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.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 41 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8279
Location: (469219) 2016 HO3

Mike C wrote:
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 Smile

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. Smile
Mike C wrote:
Once I’m done with the 85 firmware I’ll just switch to it on all future builds, … 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.

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. 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:
http://budgetlightforum.com/node/38364

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.

Mike C
Mike C's picture
Offline
Last seen: 1 hour 3 min ago
Joined: 01/22/2014 - 08:03
Posts: 2098
Location: Sweden

ToyKeeper wrote:
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. Smile

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.

zeremefico
zeremefico's picture
Offline
Last seen: 19 hours 57 min ago
Joined: 03/27/2012 - 02:44
Posts: 1292
Location: Greece

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

₪₪₪₪ ΟΥΔΕΝ ΚΡΥΠΤΟΝ ΥΠΟ ΤΟΝ ΗΛΙΟ ₪₪₪₪

My YouTube channel

Flashlights & edc gear

K40M F16

RMM
RMM's picture
Offline
Last seen: 1 month 1 week ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

zeremefico wrote:
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.  

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

zeremefico
zeremefico's picture
Offline
Last seen: 19 hours 57 min ago
Joined: 03/27/2012 - 02:44
Posts: 1292
Location: Greece
* 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?

₪₪₪₪ ΟΥΔΕΝ ΚΡΥΠΤΟΝ ΥΠΟ ΤΟΝ ΗΛΙΟ ₪₪₪₪

My YouTube channel

Flashlights & edc gear

K40M F16

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 41 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8279
Location: (469219) 2016 HO3
zeremefico wrote:
* 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.

zeremefico
zeremefico's picture
Offline
Last seen: 19 hours 57 min ago
Joined: 03/27/2012 - 02:44
Posts: 1292
Location: Greece

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

₪₪₪₪ ΟΥΔΕΝ ΚΡΥΠΤΟΝ ΥΠΟ ΤΟΝ ΗΛΙΟ ₪₪₪₪

My YouTube channel

Flashlights & edc gear

K40M F16

s1m888
s1m888's picture
Offline
Last seen: 2 days 1 hour ago
Joined: 07/12/2014 - 02:18
Posts: 169
Location: S. E. Asia

Anyone can help me with my problem? I built this driver 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?

Microa
Offline
Last seen: 2 days 12 hours ago
Joined: 06/29/2011 - 21:20
Posts: 232

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 )

Mike C
Mike C's picture
Offline
Last seen: 1 hour 3 min ago
Joined: 01/22/2014 - 08:03
Posts: 2098
Location: Sweden

s1m888 wrote:
Anyone can help me with my problem? I built this driver 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?

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.
s1m888
s1m888's picture
Offline
Last seen: 2 days 1 hour ago
Joined: 07/12/2014 - 02:18
Posts: 169
Location: S. E. Asia
Mike C wrote:
s1m888 wrote:
Anyone can help me with my problem? I built this driver 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?
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?

Mike C
Mike C's picture
Offline
Last seen: 1 hour 3 min ago
Joined: 01/22/2014 - 08:03
Posts: 2098
Location: Sweden

s1m888 wrote:
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.

Crux
Crux's picture
Offline
Last seen: 10 months 3 weeks ago
Joined: 05/03/2011 - 16:27
Posts: 227
Location: Northcoast, Ohio, USA

s1m888 wrote:
Anyone can help me with my problem? I built this driver "[WIP] 17mm DD+single-7135 driver / single sided / Dual-PWM":http://www.budgetlightforum.com/node/36710 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?

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.

Mike C
Mike C's picture
Offline
Last seen: 1 hour 3 min ago
Joined: 01/22/2014 - 08:03
Posts: 2098
Location: Sweden

Crux wrote:
Measure the voltage at pin7 (ADC input), it should be in the 0.5V to 0.75V range, if not, find out why.

Oops, your right. I got mine mixed up… edited my post a little.
s1m888
s1m888's picture
Offline
Last seen: 2 days 1 hour ago
Joined: 07/12/2014 - 02:18
Posts: 169
Location: S. E. Asia
Crux wrote:

s1m888 wrote:
Anyone can help me with my problem? I built this driver 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?

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.

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.

Crux
Crux's picture
Offline
Last seen: 10 months 3 weeks ago
Joined: 05/03/2011 - 16:27
Posts: 227
Location: Northcoast, Ohio, USA

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.

pilotdog68
pilotdog68's picture
Offline
Last seen: 2 months 3 weeks ago
Joined: 05/30/2013 - 23:31
Posts: 6419
Location: Held against my will in IOWA, USA

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

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 54 min 41 sec ago
Joined: 01/12/2013 - 14:40
Posts: 8279
Location: (469219) 2016 HO3

pilotdog68 wrote:
Is there am maximum number of modes that can be put into STAR Momentray?

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.

pilotdog68
pilotdog68's picture
Offline
Last seen: 2 months 3 weeks ago
Joined: 05/30/2013 - 23:31
Posts: 6419
Location: Held against my will in IOWA, USA

ToyKeeper wrote:
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.

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

_the_
_the_'s picture
Offline
Last seen: 1 week 6 days ago
Joined: 07/08/2011 - 06:22
Posts: 3587
Location: Finland

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.

=the=

Disclaimer: Above post might contain referral links, but only to items that I myself have bought, tested & approved. Or items that, based on my experience, can be considered as good deals & worth sharing.

s1m888
s1m888's picture
Offline
Last seen: 2 days 1 hour ago
Joined: 07/12/2014 - 02:18
Posts: 169
Location: S. E. Asia
Crux wrote:

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.

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

Crux
Crux's picture
Offline
Last seen: 10 months 3 weeks ago
Joined: 05/03/2011 - 16:27
Posts: 227
Location: Northcoast, Ohio, USA

That was a weird one, but I'm glad you fixed it. Enjoy!

zeremefico
zeremefico's picture
Offline
Last seen: 19 hours 57 min ago
Joined: 03/27/2012 - 02:44
Posts: 1292
Location: Greece

Microa wrote:
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 )

Do I still use the 200 resistor (after replacing diode) along with R1 & R2?

₪₪₪₪ ΟΥΔΕΝ ΚΡΥΠΤΟΝ ΥΠΟ ΤΟΝ ΗΛΙΟ ₪₪₪₪

My YouTube channel

Flashlights & edc gear

K40M F16

Microa
Offline
Last seen: 2 days 12 hours ago
Joined: 06/29/2011 - 21:20
Posts: 232

Dear zeremefico,

I should better to edit VCC to B+. Don’t be confused with the VCC of the MCU. The VCC of the MCU ( Pin 8 ) must not higher than 5.5V.

The voltage divider R1 and R2 are employed to lower the B+ voltage into the ADC reading range of 1.1V reference. I was confused what 200 resistor and which driver you are talking about.

Would you please post the schematic of your driver.

zeremefico
zeremefico's picture
Offline
Last seen: 19 hours 57 min ago
Joined: 03/27/2012 - 02:44
Posts: 1292
Location: Greece


This is my design:-)

₪₪₪₪ ΟΥΔΕΝ ΚΡΥΠΤΟΝ ΥΠΟ ΤΟΝ ΗΛΙΟ ₪₪₪₪

My YouTube channel

Flashlights & edc gear

K40M F16

Microa
Offline
Last seen: 2 days 12 hours ago
Joined: 06/29/2011 - 21:20
Posts: 232

Oh, I see. The solder pads of the diode was replaced by a 20K ( 2002 ) resistor. Then the resistance of the voltage divider R1 is 20K + 19.1K ( 1912 ) = 39.1K and the R2 is 4.7K ( 4701 ). When the battery is 6.1V, the ADC value is 152.

ADC=(6.1*4700*255)/((39100+4700)*1.1)
ADC=152

Microa
Offline
Last seen: 2 days 12 hours ago
Joined: 06/29/2011 - 21:20
Posts: 232

May I ask how to supply power to the MCU of your driver?

Major
Major's picture
Offline
Last seen: 3 years 5 months ago
Joined: 11/10/2011 - 13:59
Posts: 232
Location: Peak district, UK

Quote:
EEARL=eepos; EEDR=lvl; EECR=32+4; EECR=32+4+2; //WRITE //32:write only (no erase) 4:enable 2:go
.

Would someone be kind enough to tell me what is being written to EECR when it says 32+4+2.
.
Is it binary or hex or something
.
I’m used to doing EECR |= (1<<EEMPE); etc
.
Just can’t figure out how the numbers relate to the register
.
.
EDIT: ok, got it, ignore me. It’s binary

Pages