STAR Firmware by JonnyC - Source Code and Explanation

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

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.

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.

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

Odd - so far so good on this. I’ll keep testing it and report back.

Odd - so far so good on the code. Thanks

Hmm… good question. I didn’t realize there was still a flavor of STAR without dual PWM support.

I’m not sure how much work it would be. I just checked for updates upstream, hoping it had already been done, and there haven’t been any since January. The methods used in other versions of STAR have varied, and the dual switch driver isn’t quite like any other. So, it would be more than just a simple merge or a cut-and-paste job. I think there’s at least room to add it though; I get 796 bytes when I compile STAR_dual_switch.

TK, would it be easier to add mode memory to the STAR momentary FW? I feel like that’s all it would take to make it work as a dual-switch FW, and it already has dual-pwm

(of course, I think we’d all love it if you were to make your own dual-switch FW :wink: Soft-toggling memory would be really nice on a dual switch light, and better control of the second channel would be welcome as well)

You know, I’m not sure what the easiest option would be.

There should be room to add a bit of eeprom save/restore code to STAR_momentary, but I doubt there would be room to add much more.

The momentary switch code is significantly more complicated than clicky switch code and uses more room, so it’s kind of hard to fit both. However, I haven’t seriously tried so I’m not sure how hard it is.

If I can do it without so many interrupt handlers, maybe I can save enough room to fit both plus extras, but I get the feeling I’ll have to basically start from scratch in order to make any significant progress.

Question: Is there a way to have STAR dual-switch recognize when the e-switch is held while power is turned on? So that moon or strobe is accessible from off by holding the mode switch while the main power switch is clicked? Perhaps by checking e-switch status once outside of the main loop so it only checks it when power is first applied?

Sure, it should be very possible to have a different response for “power connected while switch is up” versus “power connected while switch is down”. I don’t think anyone has tried it, but it should be easy.

I haven’t been doing e-switch stuff lately, but have been itching to start on a FET+1 e-switch project. I definitely won’t have time for like a month though, and would need some extra parts.

If only we all had more time, right? :slight_smile:

I need to increase my own understanding of how the code actually functions. It’s probably my weakest point.

I tried combining my e-switch version with my NOINIT (power switch) in order to get full functionality on both switch's, but ran out of code space. I just ordered a few ATTiny45's - they have 4 * code and data space. There's been some successful porting effort goin on, so hoping I can get these up and running.

Update: Mission Accomplished! Got it working now on a ATtiny45. Some details here: https://budgetlightforum.com/t/-/34900, post #115.

Awesome. :slight_smile:

I’m hoping I can fit both by reducing the use of interrupts and volatile variables in the e-switch code. I’ll probably still need 2K to fit both the A6 code and the smooth ramping code though.

Ahh, yes. The only down side to the 25's now is the cost, but I really haven't done much shopping around yet. Mouser is a killer for shipping and NYS taxes, so $30 becomes $40 easy. Dunno yet where to go next. Would like to get temp sensor working, but also would love to get what I have now into a X6R, Convoy L4, Warsun X60, Y3, etc. We know of course, temp sensor and 25/45/85's have been implemented by or for BLFers, but no one apparently has posted any helpful details - obviously could be good reason why they can't, dunno.

Would this be the right one?

That is the larger size. You would need to bend the pin down slightly for most drivers, except the 22mm DD+7135 wight driver board. A direct drop in would be the SSU package on other boards/drivers. If you are willing to use the larger SU package, you can get 10 for $16.20 here:

http://www.ebay.com/itm/201060737002?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

These are what I'm using. They seem to work fine. As of last night, I have 3 of them up and working in different types of drivers. Of the 5 I have connected to a programmer, all 5 successfully connected..

Well at least it looks like it's worth looking around. These are the 25's with the same package as the 13A's:

ATtiny25V-10SSU (I ordered these from Mouser, qty 10 for $19.50, total order: $32.64, total payment: $39.63)

ATtiny25V-10SSUR

ATtiny25V-10SSH

ATtiny25V-10SSHR

In the same Mouser order, I also ordered qty 3 of these: ATTINY85V-10SU for $2.42 each.

Just doing a search on the SSU part # on AliExpress found qty 10 for like $13-$14 which is a pretty good deal, just hope these haven't been pre-programmed with the reset bit set as an I/O pin - this happened to me for a qty 10 order of 13A's on eBay.

Tom E wrote:

I tried combining my e-switch version with my NOINIT (power switch) in order to get full functionality on both switch's, but ran out of code space. I just ordered a few ATTiny45's - they have 4 * code and data space. There's been some successful porting effort goin on, so hoping I can get these up and running.

Update: Mission Accomplished! Got it working now on a ATtiny45. Some details here: https://budgetlightforum.com/t/-/34900, post #115.

At the above link, Tom E wrote:

. . . I did get brown out detection OFF time method working, and it's working in the eswitch version. So, I have firmware that is 1074 bytes running on a 45, about 26% code space used, and has a fully functioning power clicky switch support with mode memory and OFF time support, as well as full e-switch support! Best Of Both . Dang, this is getting easy...

Using that Fuse calculator too, I am using these fuse values to enable this combo of features:

-Ulfuse:w:0xE2:m -Uhfuse:w:0xdf:m -Uefuse:w:0xfe:m

Basically, I melded the STAR_NOINIT stuff into my eswitch version. This is where I ran out of code space before, and why I got into the 25/45/85's, specially since ImA4Wheelr got it basically up initially.

For the fuses, I analyzed what was done for the full brown-out detection, and made the same settings for the 45 family. With the Fuse Calculator, it was pretty easy to do.

Really sounds complicated to combine those functionalities. Would love to try in a couple of lights if you at a point you wouldn't mind sharing it. Could it be used in a e-switch light to assist with lock out? Something like, the light can't be turned off with the momentary switch. Would force user to "lock out" to turn off. That way, the risk of forgetting to lock out is significantly reduced.

I wouldn't mind posting it as-is, just that it hasn't been tested in a light yet, so thought I'd wait, but of course, couldn't get to it as soon as I hoped.

It's here, ZIP'ed: Google Drive shared folder, file called: switch_NOINIT.zip. Let me know if you can access/dnld it ok.

Well, then it would work like a L4 (I believe), and that's what I was trying to avoid. My goal was full functionality from the side switch. If you can't turn it off from the side switch, it's not fully functional. I agree it would help from forgetting to lock out the light though - good point, but I would not want to sacrifice ON/OFF because of that.

Update:

Just installed it in my X6R. Swapped the 13A out for a 25V on the piggyback wight FET+1 driver, and it worked out pretty well - used a hot air gun, and the one I got doesn't target a part well, so other parts loosened up but didn't move around. Reflowing did the same thing. What I did was used solder wick to remove the old solder off the pad, then applied new solder paste - think it works out better this way.

Not sure what happened, but didn't find the fuse settings I used in previous testing (or messed them up??). I used these on the 25 and seems to work well:

-Ulfuse:w:0xE2:m -Uhfuse:w:0xDE:m -Uefuse:w:0xFE:m

Also, the brown-out NOINIT timing is a bit long. I would prefer it quicker - you have to have the light off for maybe 1-2 secs or so for it to keep the same mode.