STAR Firmware by JonnyC - Source Code and Explanation

If you really want that, it’s technically possible… but the 100Hz part wouldn’t use the onboard PWM hardware. You’d have to set the 8kHz level to run automatically, then turn the 100Hz channel on and off manually with the MCU.

If you limit things to only what the dedicated PWM hardware can do, both channels must run at the same frequency. The difference between them is their duty cycle… so one can run at 100% and the other channel at 8%.

I am using STAR_dual_switch in the Yezel Y3. It has a rear clicky and a electronic side switch. So I can switch the light on with the rear clicky and than cycle trough the modes using the side switch. It has mode memory, so you can use the rear clicky to switch the light off and on and it stays in the chosen mode. It is good for signaling or morse code for example.

Now I would like to ask if this firmware can be updated with dual-PWM output because I would like to switch the driver to a FET+7135 driver.

Hi guys,
I need to modify something in the software so I figured I ask here.

I have a headlamp with a XM-L led. The driver is on the back of the head in the battery case.
The lamp has a momentary switch on the back of the led housing. This way there are 3 wires running from the led to the battery case. When I press the button the 3rd wire (the control) goes to LED ground thus pulling low the control pin on the controller.
Now, stock driver is crap and I designed my own using 9xAMC7135 and attiny.
The issue is that AMC7135 is on the - side of the LED thus the ground being unconnected when the light is off. This means that I have no way of pulling the controller leg low.
So now I have two options. Replace (once again) the wiring going to the LED and another wire for a total of 4, or modifying the software so I can pull the pin high on the controller. The LED+ wire is live all the time and I can mod the internal connections of the button.
What would I need to modify in the firmware to pull the pin high instead of low?
After some breadboard tests I found that pin 2 (PB3) must be pulled low with stock firmware.
Thank you.

Er, I’m not entirely sure if you just answered your own question or not.

The attiny can tell you if a pin is grounded or not, and you can reverse the interpretation of that if necessary… I think it just requires switching some 1s and 0s or putting a logical “not” operator in a few lines. I can’t really answer much about the hardware level of the issue though.

For me it would be easier to just edit the code and choose pull-up instead of pull-down as a matter of state detection.
That way I would not need to mess with the wires. But I provisioned my pcb for both cases where I added an extra resistor in line with the button wire.

I’d like to know where and how should I alter the code for what I need.

DIDR0 |= (1<<ADC3D); // Disables digital input on PB3. Not really needed, but saves power.

DDRB |= (1 << PB3); // Sets PB3 as output.
PORTB |= (1 << PB3); // Sets PB3 high.

Great, thank you!
I will test it tonight when I get home.

That was configuring the pin as output and setting it high. It might be worth trying to keep it as input but activate the pull-up resistor.

From the datasheet: “If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated.”
To do that you just use the last line in my above example because the initial DDRB values are already 0:

PORTB |= (1 << PB3);

I haven’t use IOs the way you need to in this case so I can’t say it will work. At least you have a couple of things to try.

I tried everything I could and it’s not working.
So here’s the relevant bit of code:

Couldn’t make it work.
It says “0 being low for pressed, 1 for pulled-up for released”. 0 is pressed in default config. So I need 1 for pressed.
The pull-up resistor is high because:

So I don’t need to do it.
Now, there’s something with the underlined bit of code. I need to reverse the way it registers the push signal. From low to high.

I don’t know if or how that can be done.

You need to add a pull-down resistor to keep the line normally low, then pressing the switch will pull the line high. Any value from 1k to 100k can be used if you disable the pull-up resistor on that input. But using a 1k ohm pull-down will overcome the internal pull-up even if not disabled (at the expense of a fraction of a Milli-amp of extra current draw, this could be an issue with e-switch lights). It is important that the positive side of the switch is the same voltage as the controller IC. If the voltage is higher, the IC may be damaged.

I'm not sure about the code, firmware wigs me out, I'm always off by one...

First try adding the pull-down resistor, then revisit the code, it just may work!

Edit: Put a meter on that line and verify it goes from a zero to a one when the switch is pressed.

Keep us posted.

Where I can find the “optimize for size”-option in Atmel Studio? At the moment my hex file is to large for the Attiny13A :frowning:

On the File menu at the top of your screen click “Project”, click the bottom selection “(project name) Properties”, click “Toolchain” on the left, and look for “Optimization”. Optimization level set to -Os Optimize for size.

Hi all,

Is the clickie version of this firmware default to use on time or off time memory?

The basic clicky STAR uses on-time. STAR_noinit uses fixed offtime via a memory decay trick. Or STAR_offtime uses configurable offtime via an offtime capacitor. Take your pick.

Ok, for the STAR_noinit. You say this uses a "decay trick". Does that mean that I can use that with a nanjg 105C and it will give the board off time memory?

I have a version of wights single sided 17mm FET DD board I would like to use it on. It has an OTC with a value of 1uf. I am guessing the STAR_offtime would be the way to go with that?

Yes & yes. You got it right. :)

Thank you! Flash Size is 0.94 KB (972 Bytes) now. That should work?

yeah should be fine. when you flash you should see exactly the size being written to the attiny. I think it’s 1024 bytes max.

Ok, I seem to be having some trouble with the Star offtime. I assume this is the one I am suppose to be using for the FET driver?

~toykeeper/flashlight-firmware/trunk : contents of JonnyC/STAR/STAR_off_time/STAR_off_time.c at revision 249



Even using the code as is, I am not able to get it to build correctly. At least I dont think I am. It says 0 errors but 5 warnings

Warning 1 unused variable 'prev_mode_idx' [-Wunused-variable] line 366

Then for lines 192,186,183, and 177 I get this warning over and over.

Warning 2 'modes' is static but used in inline function 'check_stars' which is not static [enabled by default]

What should I do about this?