STAR Firmware by JonnyC - Source Code and Explanation

Just to be sure, the download link in the OP has the most recent versions, correct?

Yes, it now links directly to the repository.

I’m struggling with how to properly set the dual-pwm output.

Is there a post that details how to set it up? I can’t find it…….

I would want to use the dual pwm for a FET + 7135 driver. Ideally I would want the moonlight and low (maybe also medium?) to use the 7135.

The the STAR firmware I am seeing the dual pwm based on the pwm rate, but how would I turn on the 7135 with no pwm, while keeping the FET off still?

Without making changes to the code, with the clicky version you can't turn the 7135 on to 100% (which is what would be needed for no PWM) and leave the secondary FET output off. With the momentary version it is easy to do that.

What confuses me is that you're talking about two completely different things. At first you're talking about moonlight and low (maybe also medium), then in the next sentence you're talking about turning on the 7135 with no PWM while keeping the FET off.

For the clicky you just set your modes, as normal, then set the threshold PWM level to where you want the secondary output to turn on.

Well I know the moonlight/low would be using pwm, but it would be nice to set the 7135 to on with no pwm as medium.

Gotcha. Well, you could make it happen, but you're going to have to poke around with the code a little bit.

Is there a reason why STAR could not be modified to use the momentary style of modes?

Why are they different?

I’m pretty sure that, yes, STAR could be modified to support that. It probably just hasn’t been yet.

I got a Moonlight Special recently and am planning to make a fairly generic off-time clicky firmware for it. Not sure what the exact feature set will be, but it should at least allow independent control of the 1x7135 vs the FET or Nx7135 pins, and should have both a battery check mode and the ability to do short/med/long presses to do three different actions.

I just have to put a test host together first and make some time to write the code. (fortunately, Monday is a holiday so it might happen very soon)

I’ll be interested to see what you come up with

I wrote a momentary FW based upon STAR momentary with the following mode selection UI.

From OFF:

  • Short press turns ON to last mode.
  • Long press turns ON to moonlight.
  • Double press turns ON to turbo.

From ON:

  • Short press turns OFF.
  • Long press cycles to next mode.
  • Double press cycles to previous mode.

I am trying to replicate the OLight S20 Baton but without flash modes. Any feedback would be welcome.

EDIT: link to code here

Please post your code somewhere and put a link here.

Code can be found here:

Thanks for posting. I will take a look at this soon!

In the meantime I see that your UI description is very similar to what akv was asking for over in this thread: akv - looking for a good value flashlight so I am going to post a link over there. This sounds very good for akv.

You might be interested in Baton.c / Baton.hex in my code repo, under ToyKeeper/Ferrero_Rocher/ . The link is below, in my signature.

It implements the Olight Baton interface (including soft lockout), but without the flash modes.

Thanks for the link. I took a look and Baton.c and see a lot of similarities with my code.

I compiled the code and ran it on my test breadboard and found one quirk. The first press from off results in a dim light which then switches to either the last mode or moon depending on the duration of the press. I think this is because you used FAST PWM always. Changing PWM_MODE to PHASE eliminated this quirk.

Indeed. That’s why the comment at the top of the file says “FAST has side effects when PWM=0, can’t shut off light without putting the MCU to sleep”. :slight_smile:

Unfortunately, PHASE has some downsides too — it’s often audible (high-pitched whine), and it flashes slow enough that it kind of bothers my eyes. So I usually go with FAST instead, if I use only one.

That can be solved with running attiny at 9.6 MHz (-Ulfuse:w:0x76:m)

I had a feeling there was a good reason not to do this… and then wight explained it in another thread. He says:

Also, I think the attiny uses more power at faster clock speeds.

I think I’ll stick with 4.8 MHz for now.

Another potential option to eliminate both the “ghost moon” and audible whine would be to run in phase-correct mode with a PWM ceiling of 128 instead of 255. Or maybe even a ceiling of like 192. Might be high-pitched enough to not be heard. This increases the pulse frequency without increasing the clock speed. The downsides are slightly reduced output resolution and incompatibility with dual PWM.

But if you use PHASE with level of 0, you get true off. You can use FAST for all other levels. For level 255, use PHASE to get true on. This is what is done in STAR_momentary.

I cleaned up the UI and adopted the blink-on-power option from your Baton.c code.

Here is the modified UI:

From OFF:

  • Short press turns ON to last mode.
  • Long press turns ON to moon.
  • Double press turn ON to turbo.

From ON:

  • Short press turns OFF.
  • Long press cycles to next mode. Keep pressing to continue cycling.
  • Double press cycles to previous mode. Keep pressing to continue cycling.

Notes:

  • There is no previous mode from moon. This is to prevent jarring transition from moon to turbo.