STAR Firmware by JonnyC - Source Code and Explanation

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

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.

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

Thanks all.

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