STAR Firmware by JonnyC - Source Code and Explanation

Thanks to all who have contributed and freely shared their code.

I’m anxious to try out the Star program.

Since others have commented on connection methods in this thread, I thought I’d share my method.

I purchased a pack of 12 mini pin grabbers from a fleabay seller, and they seem to work well on these driver boards - with one minor exception:you can’t attach them to adjacent pins on the Tiny13a (namely 5-6-7).

My solution was to solder a short stiff piece of wire to Vdd of one of the 7135’s (which are all connected to pin 6 of the Tiny13a). This provides an alternate connection point for pin 6 of the Atmel.

So…the mini pin grabbers easily connect to pins 1, 4, 5, & 7 on the Atmel, plus the additional “pin 6” on one of the 7135’s.

Works well for me-ymmv.

Kudos to JonnyC!

I like the Star1.1 firmware very, very much. IMHO - it is well written and well documented. Enough so, in fact, that a hack like myself was easily able to change a few things to better suit my personal preferences.

For instance, I changed the warning flashes to “soft” blinks instead of on/off blinks by changing the appropriate PWM=0 statements to PWM=13. Since I used PWM=15 for low mode, a value of 13 is still easily distinguishable as a warning flash.

I also changed the timing of the warning flashes from 250ms/500ms to 500ms/500ms.

I believe the soft blinks combined with equal dim/bright timing makes the light more usable while the warning is active. This is actually a lot like the warning Willie Hunt programmed into his LVR incandescant regulators many years ago (which is where I got the idea). Many of his regulators were used for bicycle lights, so an on/off warning flash might have been a bit unnerving when travelling at speed on a bike.

While I was at it, I changed the number of flashes announcing eminent shut-off from 10 to 20 to give a bit more time to react.

There are more changes I’d like to make to the low battery step-down and warning code, but I won’t go into that now.

The ability to customize the low battery and critical low battery points is rather nice.

I should mention that the code compiled perfectly using Atmel Studio 6.1 with no errors or warnings at all.

The only real downside I can see is that I now have several lights to tear apart so I can re-flash them :frowning:

Thanks for sharing this with us!

Absolutely BRILLIANT!

How does ADC_LOW 130 and ADC_CRIT 120 translate into volt?

Well, from the luxdrv source, looks like 125 is 3.0v and 5 is 0.1v. I added comments as follows:

#define ADC_LOW 130 // When do we start ramping (3.1v)

#define ADC_CRIT 120 // When do we shut the light off (2.9v)

I've been working with the e-switch version. Added more comments, re-formatted the code a bit, moved all the configurable settings up top with the rest of the settings.


Possible Mod/Enhancement to the e-switch version:

I'm debating adding a 2-4 second time-out (maybe longer) to add a one click OFF. The way it would work is if the light is ON and no clicks for the configured time (2-4 secs roughly), one click turns the light OFF. This means the OFF time-out acts as a lock mode, so you can change modes all you want since turning the light ON, but if left idle, you no longer can change modes. Anyone else see an advantage to this?

Why not just assign some dedicated command for turning off? Double-click, for example?
It would requre adding another check after first click, of course (no click in, say, 0.3 seconds -> next mode; another short click -> off)

Could do that, but you would get the flicker of the temporary mode change (brighter). If you pause and wait to process the single-click to see if a double-click is coming, you introduce a response delay. Double-clicks are great when they simply continue, or feed off the single-click operation.

Then extra-long press (>1s) for off?
There’s a lot of options there, we just need to find the most convenient.

Well with the current design, as soon as a long press exceed 512 msecs, it acts on a long press action (mode decrement), so you have the same mode flash issue. Also, I would prefer one simple single click to turn it OFF.

I just want to say “Thanks” again to JonnyC (and anyone else who contributed to the Star1.1 code) for sharing this with the rest of us.

With a little more fiddling around today, I was easily able to customize it to provide exactly the functionality I’ve been looking for:

  • L, MH, Turbo (1-minute) output levels
  • No low battery step-down warning flash (step-down is warning enough for me)
  • “Soft Blink” critical low battery cut-off warning (20 blinks @ 750ms on / 750 ms/slightly dimmed)
  • 3.17V low battery step-down trigger voltage
  • 2.84V critical low-battery cut-off trigger voltage (might raise that a bit for unprotected cells)

This code accommodates my needs (and my limited programming skills) quite nicely.

Sincerely, Thanks - again,

JW

Me Too! Thanks double JonnyC and RMM!! Just programmed my customized version of STAR Momentary into a ZY-T11 clone (here), UltraFire. Here's what I did:

  • Modes: 0,5,15,92,255 (5=moonlight, 15=6%, 92=36%, 255=100%)
  • Running PWM's at 9.4 kHz (phase corrected)
  • Cut the long press down time from a 1/2 sec to 1/4 sec (much more responsive!)
  • Added a new compile switch option of "Idle Lock", and set the time to 1.2 secs. What this does is if the light is ON, check for a time the button is Idle for - if it exceeds the limit (ex: 1.2 secs), then the short click will turn the light OFF. The long click is still functional
  • Disable TURBO option, enable Voltage Monitoring keeping the low of 3.1v, and critical changed to 2.84v

So for me, I like the Idle Lock feature because with the quicker long press because:

  • From OFF - one click to moonlight
  • From OFF - 1/4 sec hold to High
  • When turning ON, you can change modes all you like as long as mode changes are within 1.2 secs of each other, just as you used to
  • While ON, if you pause from changing modes more than 1.2 secs (i.e. idling), a click will turn the light OFF, but longer clicks will still change modes from higher to lower

The behavior is more like Dr Jones' lumodrv, but not exactly the same. Also the one-click-OFF feature is really nice with a higher numbers of modes, like 5 or 6.

If anyone is interested, I can publish the modified source code - let me know.

Other details of the mod build:

  • QLite 3.04A with 2 7135 350's added (3.74A total), piggy backed on stock driver, stripped all components off the stock driver except the switch. Removed the stupid charger connector too.
  • copper penny added under the pill top for extra heat sinking (Arctic epoxied, surfaces sanded, solder added on edges of penny to fill small gap to the pill walls)
  • XM-L2 U2 1A on 20mm Noctigon -- thinner star from stock results in reflector rattle, so added an o-ring between the reflector and glass -- worked well!
  • copper braided driver spring, need to copper braid tail spring also
  • roughly doing 1,100 lumens or so on a Pana PD. May go up a bit with copper braiding on the tail, using a Pana PF or Sam 20R, and replacing the stock lens with a AR

Tom E

Got a STAR_Tom_E.c for us?


I can post it, somewhere, maybe on Google Driver like RMM did. But, I pm'ed JonnyC with a question/issue yesterday, waiting for a response. I'd like to get his response first to be sure the code is ok... Also I'd like to hear from RMM if this is ok to do?

Thanks JohnnyC and RMM sharing the code. Also, Tom E enrich the features of convenient option.

Please publish the code to let us the AVR dummies can learn and experience the new customized features.

Here is updated source code: https://drive.google.com/file/d/0B1IxYZuk4Djcc09STnlITjh5OW8/edit?usp=sharing

Few Notes:

  • I used Atmel Studio 6.2 to compile this (latest - marked as BETA)
  • I formatted for tabs being set to every 3 columns, not 4
  • I added a few comments and function headers, etc.
  • I'm a long time C programmer, so re-formatted the code to a style I'm used to. Please understand just because you have 3 lines of code in one line in the source code, doesn't mean it will take less memory up when compiled. Comments and blank lines are free - no penalty in the compiled code.
  • I'm not sure of the de-bouncing is working the way JohnnyC intended. I could be wrong -- waiting on JohnnyC to respond to my PM. The "fix" I suggested is not in this code. I'm thinking de-bouncing may not be necessary on this hardware - not sure...

Thanks Tom E,

I built and run the code in Studio 4.18 with no error. I shall flash the 13A to-night to play with.

In playing with it, the 1/4 sec long click/hold is maybe too aggressive. Probably wise to back off a little - I'm gonna try 0.3 secs or 0.35 secs next time. The way it is now, you can accidentally get a long click if you are not quick.

19 would be the value to use for "LONG_PRESS_DUR" to get 300 msecs, 22 for 0.35 secs.

Tom, I replied to your PM. I'll follow up to other questions/comments tonight when I get back in the US (took a trip to Cozumel for a week). Real quick though I'll say I'm glad you all can utilize this and customize it so easily! I will be adding a slightly modified program for off-time memory. Capacitors arrived at my house yesterday and I'll be building my first light to test it out soon.

I can’t seem to stop playing with this code – I’m having too much fun with it.

In addition to customizing the low battery warning blinks as mentioned previously, I’ve made one more tweak I think I’m going to like.

In essence, I’ve configured the driver for 3 basic mode levels, but with a fourth level that is only reached following turbo time-out.

Momentarily releasing the switch following time-out bumps it back into turbo for another time cycle.

Normal mode cycling is simply L-H-Turbo (skipping the turbo step-down level).

It goes something like this:

Low = PWM 15
High = PWM 75
Turbo = PWM 255 (1-minute)
Turbo Step-down = PWM 150

I’ll fine tune the levels and turbo timer once I put the driver into a host and use it for awhile.

The reason I chose to do this is because I found that having 4 or 5 levels resulted in too much “switch fiddling”. It wasn’t long before I found myself missing the simple 3-mode w/memory configuration. (K.I.S.S. comes to mind once again…)

I think the turbo step-down level combined with a short turbo timer will help to manage heat while not drastically hindering usefulness (at least for my needs).

Thanks for reading…

-JW

once the turbo step down happens can you bump it back up to turbo with a 1/2 button press, or do you have to recycle back thru?

most excellent...can we get a code posting of what you did here [in quotes or a link or whatever]?

If you make a change, post the .c code here so others to compile and mess with it too