STAR Firmware by JonnyC - Source Code and Explanation

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.

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!

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 ~toykeeper/flashlight-firmware/trunk : contents of ToyKeeper/blf-a6/blf-a6.c at revision 249

Thank you!

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

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?

wiggle/check your cables/wiring

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.

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.

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?

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.

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.

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…

Thanks for the heads-up and effort.

Search for the line:

if (low_voltage(ADC_LOW)) {

Replace ADC_LOW with ADC_CRIT. Should work…

Thanks - I’ll give it a try now.

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?

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.

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…

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?

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 :slight_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