STAR Firmware by JonnyC - Source Code and Explanation

1335 posts / 0 new
Last post
Hoop
Hoop's picture
Offline
Last seen: 6 hours 31 min ago
Joined: 12/20/2012 - 05:33
Posts: 1051
Location: Spokane, WA

wight wrote:
Hoop wrote:
How might I allow for slower or faster button presses when changing modes with STAR_offtime_no-memory? I would like to allow slower presses to change modes instead of reverting to low. Does the CAP_THRESHOLD value affect this?

I gave my mag-lite to my parents to see how the mode switching worked for them and they fumbled with the control of the light more than I was expecting.

Did they stumble with the offtime timeout, or the fact that it’s a forward clicky with an offtime firmware?

Both! It was mildly depressing.

wight
Offline
Last seen: 1 year 7 months ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA

Hoop wrote:
wight wrote:
[snip]Did they stumble with the offtime timeout, or the fact that it’s a forward clicky with an offtime firmware?
Both! It was mildly depressing.
I’ve seen both problems when demonstrating flashlights to various people so that’s no surprise. The one-button interface thing is a whole new world. There are some great aspects to FWD clickies, being a good introduction to multi-mode lights is not on the list IMO.

As far as the rest (the whole timing issue with half presses), I’m really curious how much better / worse a momentary firmware would be.

EDIT: to clarify, I meant to say… don’t let it get you down. As I mentioned above, it’s a whole new world for many people: it shouldn’t reflect one way or another on your parents and it doesn’t really say anything about the viability of a flashlight business for you either. Just let this experience advise you on how important it will be to gently introduce neophytes. Picking up a one-button-interface device like a FWD or reverse clicky flashlight and learning to use it is akin to getting on a bicycle for the first time. It’s a desirable product but you do have to learn how to use it! I haven’t spent a lot of time on it, but I really haven’t seen a simple way to quickly get someone who’s totally unfamiliar with the concept up to speed.

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 13 hours 1 min ago
Joined: 01/12/2013 - 14:40
Posts: 10761
Location: (469219) 2016 HO3

Mike C wrote:
I guess it’s good that everyone is different, the world would be a boring place otherwise Beer

That’s what I’m here for. ;P

wight wrote:
Picking up a one-button-interface device like a FWD or reverse clicky flashlight and learning to use it is akin to getting on a bicycle for the first time. It’s a desirable product but you do have to learn how to use it! I haven’t spent a lot of time on it, but I really haven’t seen a simple way to quickly get someone who’s totally unfamiliar with the concept up to speed.

Especially with Zebralights. Nice UI, but genuinely too complicated for a lot of people. I can’t hand a Zebralight to a muggle and expect them not to fail… they’ll generally click the button, turn it on in turbo, hurt their eyes (or someone else’s), click it again in an attempt to shut it off (taking it down to medium), then rapidly click until it starts blinking… and then hand it back to me with a negative comment like “that thing is booby-trapped!”.

Alternately, they might wait just long enough after the initial blast before they start fast-clicking, which makes it toggle between turbo and high.

So, probably a good idea to at least try to make UIs somewhat muggle-friendly… i.e. don’t do anything particularly surprising on single-press-from-off.

Tom E
Tom E's picture
Online
Last seen: 2 min 25 sec ago
Joined: 08/19/2012 - 08:23
Posts: 14736
Location: LI NY

ToyKeeper wrote:
It doesn't really matter right now, but a "double" in C is a float with twice the default resolution. Integers above 255 are still integers, they're just 16 bits instead of 8. Technically, it would be called a dword, or double-word, since the word size on the attiny13a is 8 bits. For portability, people usually avoid using "words" because the size varies per architecture, choosing explicit bit sizes instead. But words are handy for speed optimization, since they typically are the fastest for most operations.

I stay with the convention that a WORD is always unsigned 16 bits, DWORD unsigned 32 bits, BYTE unsigned 8 bits. Most C/C++ compilers don't natively support WORD and DWORD, so I usually assign them in a common header. I've worked several times with binary data import/export or comm/dual port interfaces between processors, and it can be a nightmare if you don't have a rigorous set of standard formats. Mixing big Endian (Motorola, etc.) and little Endian (Intel, etc.) is even worse with byte ordering all messed up. In theory the WORD does depend on the processor. The int I make no assumptions on it's size, but guaranteed it's always signed. Some processors it gets debatable what it's WORD size really is. Some do BYTE addressing but have 16 bit registers, or have a mix of 16 bit and 32 bit registers, etc. Usually it's based on memory access or the accumulator size, but that can get complicated too, with different modes. 

I've been working on micros as far back as the Intel 8080, Motorola 6800 back when CP/M was the latest. I bought the original IBM PC for $3,500 back in '81 or so, just to play/learn - did a few mod/upgrades on it of course Wink. Actually I still support products using the 68331, which is a variant of the 68000, and also still support 8051 variants.

Hoop
Hoop's picture
Offline
Last seen: 6 hours 31 min ago
Joined: 12/20/2012 - 05:33
Posts: 1051
Location: Spokane, WA

Yea, thanks for the encouragement wight. I think with a proper 30 second instructional video demonstration it will be easy for the average person. I’ll incorporate it into my product video.

RMM
RMM's picture
Offline
Last seen: 1 year 7 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

FmC wrote:
ToyKeeper wrote:
Except, of course, breaking the core design concept of STAR. It's designed to be configurable at run-time (via soldered stars) instead of compile-time. This costs a lot of space, but makes drivers end-user configurable. /snip
It will be interesting to see if 105c supplies dry up, or if they will be kept in production. Several people, including myself, have been sent the 105d's, which don't have the stars.

I think they'll stick around for a while, but you may not be able to get them from FT anymore (who seems to get them from Convoy).  

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

Hoop
Hoop's picture
Offline
Last seen: 6 hours 31 min ago
Joined: 12/20/2012 - 05:33
Posts: 1051
Location: Spokane, WA

Kind of OT: Any thoughts on running an XM-L2 via Qlite from 3x nimh? I haven’t done extensive testing yet but I’m wondering if it’s just not going to be enough voltage. I may end up going strictly 2× 26650 (1s2p) for my mag upgrade kit.

wight
Offline
Last seen: 1 year 7 months ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA

OL has commented on it a couple of times I think. Sounds like 3xNiMH just isn’t enough. 4x is good though, so if you don’t mind doing a quick boring operation to each host…

I haven’t tried it, but I’ve been meaning to. I expect to find that OL is exactly right, so I’m not sure what I’ll do then. Use old XM-L emitters maybe? Or for mag builds the 3xNiMH, XHP50, and a DQG 26650 boost driver might be OK.

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

pilotdog68
pilotdog68's picture
Offline
Last seen: 6 months 3 days ago
Joined: 05/30/2013 - 23:31
Posts: 6422
Location: Held against my will in IOWA, USA

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

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

RMM
RMM's picture
Offline
Last seen: 1 year 7 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

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

Yes, it now links directly to the repository. 

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

bdiddle
Offline
Last seen: 3 months 1 week ago
Joined: 12/14/2012 - 14:36
Posts: 814

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?

Newb

RMM
RMM's picture
Offline
Last seen: 1 year 7 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

bdiddle wrote:
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.

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

bdiddle
Offline
Last seen: 3 months 1 week ago
Joined: 12/14/2012 - 14:36
Posts: 814
RMM wrote:

bdiddle wrote:
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.

Newb

RMM
RMM's picture
Offline
Last seen: 1 year 7 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

bdiddle wrote:
RMM wrote:

bdiddle wrote:
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.

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

pilotdog68
pilotdog68's picture
Offline
Last seen: 6 months 3 days ago
Joined: 05/30/2013 - 23:31
Posts: 6422
Location: Held against my will in IOWA, USA

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

Why are they different?

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 13 hours 1 min ago
Joined: 01/12/2013 - 14:40
Posts: 10761
Location: (469219) 2016 HO3

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 1×7135 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)

pilotdog68
pilotdog68's picture
Offline
Last seen: 6 months 3 days ago
Joined: 05/30/2013 - 23:31
Posts: 6422
Location: Held against my will in IOWA, USA

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

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

dthoang
Offline
Last seen: 6 months 3 weeks ago
Joined: 10/09/2014 - 13:30
Posts: 319
Location: Austin, TX USA

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
https://docs.google.com/document/d/1S7SqU_1580H_DEnSZG2Ple1e2upZeJvZ8VPz...

one year rookie

wight
Offline
Last seen: 1 year 7 months ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA

dthoang wrote:
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.

Please post your code somewhere and put a link here.

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

dthoang
Offline
Last seen: 6 months 3 weeks ago
Joined: 10/09/2014 - 13:30
Posts: 319
Location: Austin, TX USA
wight wrote:
Please post your code somewhere and put a link here.

Code can be found here:
https://docs.google.com/document/d/1S7SqU_1580H_DEnSZG2Ple1e2upZeJvZ8VPz...

one year rookie

wight
Offline
Last seen: 1 year 7 months ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA
dthoang wrote:
wight wrote:
Please post your code somewhere and put a link here.

Code can be found here:
https://docs.google.com/document/d/1S7SqU_1580H_DEnSZG2Ple1e2upZeJvZ8VPz...

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.

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 13 hours 1 min ago
Joined: 01/12/2013 - 14:40
Posts: 10761
Location: (469219) 2016 HO3
dthoang wrote:
I am trying to replicate the OLight S20 Baton but without flash modes.

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.

dthoang
Offline
Last seen: 6 months 3 weeks ago
Joined: 10/09/2014 - 13:30
Posts: 319
Location: Austin, TX USA
ToyKeeper wrote:
dthoang wrote:
I am trying to replicate the OLight S20 Baton but without flash modes.

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.

one year rookie

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 13 hours 1 min ago
Joined: 01/12/2013 - 14:40
Posts: 10761
Location: (469219) 2016 HO3

dthoang wrote:
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”. 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.

chiefinspectorfinch
chiefinspectorfinch's picture
Offline
Last seen: 4 hours 49 min ago
Joined: 09/27/2010 - 14:33
Posts: 555
Location: Croatia, country with kleptomaniac clero-fascist government

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

Society is like a pot full of nuts and bolts, finest pieces always end up on the bottom...

 

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 13 hours 1 min ago
Joined: 01/12/2013 - 14:40
Posts: 10761
Location: (469219) 2016 HO3
chiefinspectorfinch wrote:
That can be solved with running attiny at 9.6 MHz (-Ulfuse:w:0×76:m)

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

wight wrote:
9.6Mhz is right on the ragged edge with a protection diode in place. Atmel’s datasheet shows that up to 10Mhz is OK for 2.7-5.5v, but the diode drops around 0.2v or more. So at 2.9v the ATtiny13A sees 2.7v. There may be other considerations that push you over the edge in certain circumstances.

In other words if it’s possible I’d try and stick to 4.8Mhz rather than 9.6Mhz, just to have all your bases covered all the time.

I’m saying that it may malfunction once voltage drops low enough. There will be no damage to the driver, but it’s anybody’s guess what could happen. LVP could fail, that would be my primary concern.

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.

dthoang
Offline
Last seen: 6 months 3 weeks ago
Joined: 10/09/2014 - 13:30
Posts: 319
Location: Austin, TX USA

ToyKeeper wrote:
dthoang wrote:
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”. 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.


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.

one year rookie

dthoang
Offline
Last seen: 6 months 3 weeks ago
Joined: 10/09/2014 - 13:30
Posts: 319
Location: Austin, TX USA
ToyKeeper wrote:
dthoang wrote:
I am trying to replicate the OLight S20 Baton but without flash modes.

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.

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.

https://docs.google.com/document/d/1UDpOdG98RQDNvgPmMDsKvbe9mGdbI3vw2-Nu...

one year rookie

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 13 hours 1 min ago
Joined: 01/12/2013 - 14:40
Posts: 10761
Location: (469219) 2016 HO3

dthoang wrote:
ToyKeeper wrote:
… if I use only one.

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 don’t normally use only one. Smile

The reason STAR-momentary defaults to PHASE at both ends is because I kept bugging JonnyC to do it that way (for exactly the same reason). Most of my other changes have remained separate, but he accepted that one.

As for the Baton UI, I kind of stopped working on it because I found I just didn’t like the interface as much as some others. I’ve mostly been using Ramping_UI_table.c on my e-switch lights instead, or Ferrero_Rocher.c (depends on the light). The ramping UI is similar to Baton, but it does smooth ramping instead of stair-stepping, and it auto-reverses so a long press will go either up or down based on context. I didn’t have enough room to fit a battery check mode or soft lockout though (I’m using realtime batt indicators instead, and no lock).

chiefinspectorfinch
chiefinspectorfinch's picture
Offline
Last seen: 4 hours 49 min ago
Joined: 09/27/2010 - 14:33
Posts: 555
Location: Croatia, country with kleptomaniac clero-fascist government

I am aware of voltage limitation but in practice attiny works without problem. Most likely atmel was a bit conservative with voltage specs. Perhaps in extreme conditions (hot or cold) there might be a problem, but in those circumstances I would worry much more for the battery itself…

Society is like a pot full of nuts and bolts, finest pieces always end up on the bottom...

 

Pages