STAR Firmware by JonnyC - Source Code and Explanation

1335 posts / 0 new
Last post
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 43 min ago
Joined: 01/12/2013 - 14:40
Posts: 10759
Location: (469219) 2016 HO3

vestureofblood wrote:
Is there something else in the code that effects the level of light output besides the values of each mode?

The reason I ask is because I can set value of moonlight all the way down to 1, and it does give a reasonable low mode with one cell.    On a zener modded board with 2 cells its a bit bright still though.    I have other firmware I can flash that puts moonlight lower than this.

On a FET board, it’s difficult to get a true moon mode. In general, a value of PWM=1 will produce anything from 1 to 15 lumens depending on the cell and emitter(s) used. You can go lower by using fast PWM=0, but it’s incredibly voltage-sensitive and I’ve seen it put out as much as 4 lumens on a full cell (and down to 0.001 on a low cell, same light). You’ll get somewhat more stable output with phase-correct PWM, but the lowest level on that is 1 and it’ll probably be too bright for moon.

I tried using fast PWM=0 plus dynamic voltage-determined PFM (pulse frequency modulation) to get a better FET-only moon mode, but even that merely reduced the problem rather than really fixing it. You’re welcome to try it if you like though; the code is in ToyKeeper/cypreus/cypreus.c .

This is one of the reasons people use FET+1 drivers instead. The +1 gives you a single 7135 chip which can drive all the modes under about 140 lumens. It should produce a nice moon mode, plus stable current-regulated “low” and “medium” modes. It can also help reduce output sag on modes above that, and make the PWM even less visible.

nofear87
Offline
Last seen: 2 months 1 week ago
Joined: 03/07/2015 - 05:40
Posts: 114

What Phase Modes are the best for the Nanjq AK47A Fet Mod?

I used the Star_momentary firmware (link )

git says:
18 kHz PWM (“fast”) or 9.4 kHz PWM (“phase-correct”, usually used for custom FET driver versions) definable per output mode

So I have to choose “Phase” for every mode?

#define MODE_PWM 0,PHASE,PHASE,PHASE,PHASE,PHASE

I ask because the default values works well, too.

Thanks!

finges
Offline
Last seen: 19 hours 3 min ago
Joined: 11/19/2014 - 14:50
Posts: 504
Location: Germany

I would use PHASE only for the lowest moonlight and highest turbo mode. For all other modes in between use FAST.

As I understand correctly it gives a better, more stable moonlight mode.

As seen here http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/view/he...

nofear87
Offline
Last seen: 2 months 1 week ago
Joined: 03/07/2015 - 05:40
Posts: 114

finges wrote:
I would use PHASE only for the lowest moonlight and highest turbo mode. For all other modes in between use FAST.

As I understand correctly it gives a better, more stable moonlight mode.

As seen here http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/view/he...

Thank you!

Now I try to flash a brand new attiny 13A SSU

Quote:

avrdude -p t13 -c usbasp -u -Uflash:w:star.hex:a -Ulfuse:w:0×75:m -Uhfuse:w:0xFF:m

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0×1e9007
avrdude: NOTE: “flash” memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file “star.hex”
avrdude: input file star.hex auto detected as Intel Hex
avrdude: writing flash (1014 bytes):

Writing | ################################################## | 100% 0.61s

avrdude: 1014 bytes of flash written
avrdude: verifying flash memory against star.hex:
avrdude: load data flash data from input file star.hex:
avrdude: input file star.hex auto detected as Intel Hex
avrdude: input file star.hex contains 1014 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.54s

avrdude: verifying …
avrdude: verification error, first mismatch at byte 0×0000 0×00 != 0×09
avrdude: verification error; content mismatch

avrdude done. Thank you.

The Attinys on Nanjg works without any problems…but on the new ones I got a verification error. What could be a reason for this?

seasam
Offline
Last seen: 5 years 3 months ago
Joined: 01/31/2015 - 13:15
Posts: 189
Location: GA, USA

wiggle/check your cables/wiring

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 43 min ago
Joined: 01/12/2013 - 14:40
Posts: 10759
Location: (469219) 2016 HO3

I got errors like that when I had five wires connected on my clip instead of six wires. I could write data but couldn’t read it.

Another thing to check is whether you have any pins grounded (or any stars soldered). That can interfere with flashing.

vestureofblood
vestureofblood's picture
Offline
Last seen: 11 hours 43 min ago
Joined: 08/17/2012 - 15:21
Posts: 1994
Location: Missouri

What do I need to do in order to properly disable the Turbo timer on the Star off time.

I tried commenting out the turbo time out line, and it gave me an error.   It said undeclared ( fist use in this function)

I want to keep the turbo mode, just not the timer.

In Him (Jesus Christ) was life; and the life was the light of men. And the light shineth in darkness; and the darkness comprehended it not.
http://asflashlights.com/ Everyday Carry Flashlights, plus Upgrades for Maglite.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 43 min ago
Joined: 01/12/2013 - 14:40
Posts: 10759
Location: (469219) 2016 HO3

vestureofblood wrote:

What do I need to do in order to properly disable the Turbo timer on the Star off time.

I tried commenting out the turbo time out line, and it gave me an error.   It said undeclared ( fist use in this function)

I want to keep the turbo mode, just not the timer.


I think you’re supposed to use MODE_HIGH instead of MODE_TURBO, if you want it to not step down.

Or you could use both (5 modes instead of 4) and comment out the parts which implement the step-down logic.

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

Quick question:

I’m trying use only ADC_CRIT and disable ADC_LOW.

When I comment out ADC_LOW I get the following compile error”

ADC_LOW’ undeclared (first use in this function)

Instead of commenting it out would I be better off setting it to 0?

Mike C
Mike C's picture
Offline
Last seen: 16 hours 39 min ago
Joined: 01/22/2014 - 08:03
Posts: 2582
Location: Sweden

I haven’t looked at that code for ages so I can’t tell you exactly which lines, but commenting out ADC_LOW is not the only thing you have to do.
Later on in the code, the voltage reading routine compares the read voltage to ADC_LOW. As you’ve commented out the ADC_LOW definition the compiler doesn’t know what to compare it to. Setting ADC_LOW to 0 or at least something lower than ADC_CRIT might not be the prettiest method, but it’s the easiest and should work.

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

I’m not too code savvy so I wasn’t sure what else to comment out.

I’ve set ADC_LOW to 0 and so far am having trouble getting ADC_CRIT to shut the light off.

No benchtop so I’ll keep running the cell lower and see if I just haven’t tripped it yet.

Mike C
Mike C's picture
Offline
Last seen: 16 hours 39 min ago
Joined: 01/22/2014 - 08:03
Posts: 2582
Location: Sweden

I still had Star 1.1 on my hard disk so I checked. If the low voltage check passes, the critical volt check will not be executed… So you can stop your test, it will not work. Gimme a sec and I’ll see if there is a simple way of doing it…

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

Thanks for the heads-up and effort.

Mike C
Mike C's picture
Offline
Last seen: 16 hours 39 min ago
Joined: 01/22/2014 - 08:03
Posts: 2582
Location: Sweden

Search for the line:

if (low_voltage(ADC_LOW)) {

Replace ADC_LOW with ADC_CRIT. Should work…

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

Thanks – I’ll give it a try now.

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

Tried the above.

Near 3v the light blinks before stepping down to what I assume is low mode.

What I’m hoping to do is skip the low mode and go straight to shutoff. Being able to keep the blinks would be helpful as well.

Any additional thoughts?

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

I suspect the problem lies in the next line of code:

if (mode_idx == 0 && ALT_PWM_LVL <= modes[mode_idx])

By changing ADC_LOW to ADC_CRIT I think we’ve just changed the trigger to take us to the line of code above.

I think instead of looking for an alternate mode it should instead blink and then shut down.

Mike C
Mike C's picture
Offline
Last seen: 16 hours 39 min ago
Joined: 01/22/2014 - 08:03
Posts: 2582
Location: Sweden

The version of Star I have doesn’t have ALT_PWM level, so I’m sure we are not looking at the same code.

However, you are right. I forgot about that part. As it is now it goes to step down on critical, then shuts off. You want it to shut off straight away.

So, another quick fix without extensive editing… Keep the last change and then change:
if (mode_idx == 0 && ALT_PWM_LVL <= modes[mode_idx])

to:
if (1)

Not a pretty solution, but requires minimal editing… unless I’ve missed something else…

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

Success! Repeatable shutoffs at 2.994v.

Thanks for your help.

To improve myself a bit. What does the last change to “if (1)” actually do?

odd
Offline
Last seen: 3 years 8 months ago
Joined: 02/12/2012 - 16:17
Posts: 29

This should work:

Comment out “#define ADC_LOW” and replace the voltage-mon section with this one:

EDIT: Too late :~ , but its a cleaner soultion Smile

#ifdef VOLTAGE_MON
#ifdef ADC_LOW
if (low_voltage(ADC_LOW)) {
// We need to go to a lower level
if (mode_idx == 0 && ALT_PWM_LVL <= modes[mode_idx]) {
// Can't go any lower than the lowest mode
// Wait until we hit the critical level before flashing 10 times and turning off
#endif
while (!low_voltage(ADC_CRIT));
i = 0;
while (i++<10) {
set_output(0);
_delay_ms(250);
set_output(modes[0]);
_delay_ms(500);
}
// Turn off the light
set_output(0);
// Disable WDT so it doesn't wake us up
WDT_off();
// Power down as many components as possible
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_mode();
#ifdef ADC_LOW
} else {
// Flash 3 times before lowering
hold_pwm = ALT_PWM_LVL;
i = 0;
while (i++<3) {
set_output(0);
_delay_ms(250);
set_output(hold_pwm);
_delay_ms(500);
}
// Lower the mode by half, but don't go below lowest level
if ((ALT_PWM_LVL >> 1) < modes[0]) {
set_output(modes[0]);
mode_idx = 0;
} else {
set_output(ALT_PWM_LVL >> 1);
}					
// See if we should change the current mode level if we've gone under the current mode.
if (ALT_PWM_LVL < modes[mode_idx]) {
// Lower our recorded mode
mode_idx--;
}
}
// Wait 3 seconds before lowering the level again
_delay_ms(3000);
}
#endif
#endif
Mike C
Mike C's picture
Offline
Last seen: 16 hours 39 min ago
Joined: 01/22/2014 - 08:03
Posts: 2582
Location: Sweden

Nice.

The short explanation: “if (1)” means “do this”.

The long explanation: “if” expressions check the terms you put between the (). If those terms are true, the result passed back is 1. So by replacing the terms with “1” I’ve sort of passed the result “true” to an “if” check.
The if(1) line itself is not needed, but in order to remove it you need to remove more stuff. For example, this is what it looks like now:

if (1) {
-do this code
}
else {
-code here will never be executed because if (1) never fails
}

You can make it look like this:

-do this code

If you remove the if check you have to remove the {} characters and else statement along with all the code in that else statement.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 43 min ago
Joined: 01/12/2013 - 14:40
Posts: 10759
Location: (469219) 2016 HO3

FWIW, the step-down may allow the light to run for a significantly longer time, since voltage often recovers after decreasing amperage. It also acts as a way of getting more warning before shut-off. But if you don’t like it, you don’t like it. Smile

BTW, did anyone try simply setting the LOW and CRIT values to the same number? It seems like a straightforward way to do it (but would probably not disable step-down).

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

Thanks all.

Toy I did try this and unfortunately the LOW always grabbed before the CRIT. Meaning it would switch to a lower level.

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

All of the tests I had successfully run for the low voltage shut off were done on Turbo that defaulted to Turbo Low.

I’m now running the tests again and the low voltage shut off is not working.

Should ADC_CRIT work in all modes?

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 43 min ago
Joined: 01/12/2013 - 14:40
Posts: 10759
Location: (469219) 2016 HO3

I’m not sure… I haven’t tested STAR extensively. In my mods I usually cut out that part of the code because it takes too much space, and replace it with something smaller / simpler. The one I’ve tested the most is BLF-A6, since it’ll be factory-installed and I want to make damn sure it works correctly. It still needs a somewhat unfortunate amount of calibration for each different model of driver it runs on though.

If you have a bench power supply, it greatly helps testing. If not, a LiFePo4 cell or even a 3V CR123 or CR2032 cell can work for LVP tests. It can also be useful to temporarily bump up the LOW/CRIT levels to make it trigger at a higher voltage, just to make sure it works, and then put them back down where they should be.

Mike C
Mike C's picture
Offline
Last seen: 16 hours 39 min ago
Joined: 01/22/2014 - 08:03
Posts: 2582
Location: Sweden

HighEfficiency wrote:
All of the tests I had successfully run for the low voltage shut off were done on Turbo that defaulted to Turbo Low.

I’m now running the tests again and the low voltage shut off is not working.

Should ADC_CRIT work in all modes?


The code I’m looking at should work, but I’m looking at standard star v1.1. I haven’t touched it for a long time though, I use my own firmware and it does everything differently.
odd
Offline
Last seen: 3 years 8 months ago
Joined: 02/12/2012 - 16:17
Posts: 29

HighEfficiency wrote:
Thanks all.

Toy I did try this and unfortunately the LOW always grabbed before the CRIT. Meaning it would switch to a lower level.

Did you try my suggestion?
It removes all the stepping down part.

Mike C
Mike C's picture
Offline
Last seen: 16 hours 39 min ago
Joined: 01/22/2014 - 08:03
Posts: 2582
Location: Sweden

The cleanest would be to remove everything in the while(1) except shutdown code, and sleep code after if there is any:

while(1) {

if (LowVoltage(ADC_CRIT)) {
Shut down code…
}

Sleep code (if any)

}

If you can post your code somewhere easy to read I can give a go at a quick edit, but I can’t test it as I don’t have any ATtiny13A drivers anymore.

HighEfficiency
HighEfficiency's picture
Offline
Last seen: 4 years 2 months ago
Joined: 02/05/2014 - 11:33
Posts: 74
Location: USA

Odd – I have not yet tried your code but will today. I’ll report back.

Mike – Thanks for the suggestion. Let me see how Odd’s code works and I’ll try and find a way to post my code if it doesn’t work out.

Thanks all for the help.

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

How much work would it be to add dual-pwm to the dual-switch firmware?

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

Pages