STAR Firmware by JonnyC - Source Code and Explanation

1335 posts / 0 new
Last post
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 1 day 10 hours ago
Joined: 01/12/2013 - 14:40
Posts: 10761
Location: (469219) 2016 HO3

Indeed. On the Ferrero Rocher, I see one labelled 41. On the Moonlight Special, it’s labelled E2. The ADC readings between the two differ by about 10, which is enough to make LVP and battery charge estimations not work well.

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

ToyKeeper wrote:
Indeed. On the Ferrero Rocher, I see one labelled 41. On the Moonlight Special, it’s labelled E2. The ADC readings between the two differ by about 10, which is enough to make LVP and battery charge estimations not work well.
Mystery solved – that’s PMEG1020EA. The lower forward voltage should improve the driver’s overall drop-out by a small amount.

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)

ZOTZ
ZOTZ's picture
Offline
Last seen: 4 years 7 months ago
Joined: 02/03/2015 - 15:13
Posts: 7
Location: montreal, québec

Hi guys, First time im posting in your forum but its been a while that i read your stuff. Pretty amazing what you have done with this little nanjg-105c. Tido, JohnnyC , drJones and all other programmer could be proud of yourself!

I have programmed around 20 drivers (nagj-105c with 4 stars)with your technics but some fails . Let me explain!:)

First , i modified the code by simply add more Modes to the star mom like 1,8,14,100,255 . 90% of the Times everything work the way it should. But some refuse to get 5 mode even if i reflash several times. It only work on 4 modes with the turbo in??? Any idea what could go wrong.

After i got one that the turbo is really fast even if i programmed it to 60 sec??? is duration is around 10 sec??? reflashing and it change nothing any idea whats happening here Smile

tks for your help

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

ZOTZ wrote:
Hi guys, First time im posting in your forum but its been a while that i read your stuff. Pretty amazing what you have done with this little nanjg-105c. Tido, JohnnyC , drJones and all other programmer could be proud of yourself! I have programmed around 20 drivers (nagj-105c with 4 stars)with your technics but some fails . Let me explain!:) First , i modified the code by simply add more Modes to the star mom like 1,8,14,100,255 . 90% of the Times everything work the way it should. But some refuse to get 5 mode even if i reflash several times. It only work on 4 modes with the turbo in??? Any idea what could go wrong. After i got one that the turbo is really fast even if i programmed it to 60 sec??? is duration is around 10 sec??? reflashing and it change nothing any idea whats happening here Smile tks for your help

Glad to see you here!  

The problem is likely your mode level setting of "1".  That is far too low for most 7135 chips to turn on, especially when there are multiple 7135 chips on the same board.  Depending on the number and type of 7135 chips, you probably need the lowest level to be between 6 and 8. 

The turbo timer on the momentary driver is set in 0.016 second increments.  So for 60 seconds you would need to enter a value of 3750 for the timer (60/0.016).  

Hope that helps!

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

ZOTZ
ZOTZ's picture
Offline
Last seen: 4 years 7 months ago
Joined: 02/03/2015 - 15:13
Posts: 7
Location: montreal, québec

Thanks for your reply, i changed the code for the two driver that have only 4 mode and now is working with 6 modes… ill removed one entry and i should end up with 5 mode Wink problem solved tks!

for the timer… that one i really don’t know what to do with. I changed the number of ticks to 10000 ! so more than 120 seconds and its not responding… 5 sec on and it change to the previous mode , really strange!. All other driver( more than 20!) work perfectly with turbo but only one is not working??? Ill work on it but i think it will end up as a 7135 chips spare parts!

Anyone have a idea what could go wrong with the timer?

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

I wonder if you are seeing the low voltage protection kick in on that driver.  If it steps down from any mode other than the highest mode, then that is probably the case. 

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

Crux
Crux's picture
Offline
Last seen: 3 weeks 6 days ago
Joined: 05/03/2011 - 16:27
Posts: 227
Location: Northcoast, Ohio, USA

Because I'll be running an ATtiny13A from a regulated voltage, would it be better to switch the ADC Vref to Vcc rather than the Internal reference?

It seems like this would allow finer control of battery voltage monitoring. Of course the resistors will still be across the battery and the values will need to be tweaked.

Do I only need to change the REFS0 bit in the ADMUX register and adjust the low voltage stepdown values? Or is it even worth the bother?

-Crux

Mike C
Mike C's picture
Offline
Last seen: 2 days 2 hours ago
Joined: 01/22/2014 - 08:03
Posts: 2584
Location: Sweden

Crux wrote:

Because I’ll be running an ATtiny13A from a regulated voltage, would it be better to switch the ADC Vref to Vcc rather than the Internal reference?

It seems like this would allow finer control of battery voltage monitoring. Of course the resistors will still be across the battery and the values will need to be tweaked.

Do I only need to change the REFS0 bit in the ADMUX register and adjust the low voltage stepdown values? Or is it even worth the bother?

-Crux


Looks like changing that bit is all you need to do to change Vref, but I haven’t tried it myself. If you’re using an off time cap you’ll have to make a few more changes though.
Crux
Crux's picture
Offline
Last seen: 3 weeks 6 days ago
Joined: 05/03/2011 - 16:27
Posts: 227
Location: Northcoast, Ohio, USA

Mike C wrote:
If you're using an off time cap you'll have to make a few more changes though.

I didn't think about that... I have figured that too much capacitance on the output of the regulator will affect the click times, may have to add a bleeder resistor to hasten the discharge. But this will (slightly) increase current draw with no benefit to the LED current. Not a big deal for big batteries.

marruz
Offline
Last seen: 5 years 9 months ago
Joined: 09/05/2014 - 03:52
Posts: 17
Location: Czech Republic

ToyKeeper, thank you very much for your work on this code. I can’t wait to use it in practice. Now I need to find time to try it in practice.

vex_zg
Offline
Last seen: 3 years 3 months ago
Joined: 08/10/2014 - 11:08
Posts: 420
Location: Sweden

Regardless of actual battery voltage (tried varying it with lab PSU), I always end up as ADCH=128 and ADCL between 106 to 110.

Don’t know what to try next. The ADC routine is the standard one from Star_offtime. Went through datasheet, seems everything is the same as with tiny13a, but I’m no expert in uC programming.

Cereal_killer
Cereal_killer's picture
Offline
Last seen: 1 year 9 months ago
Joined: 07/22/2013 - 13:10
Posts: 4005
Location: Ohio
Quote:
#define DUAL_PWM_START 8 // Above what output level should we switch from the alternate PWM output to both PWM outputs? Comment out to disable alternate PWM output

Hey guys, I’m looking at doing a dual PWM build but I’m wondering, does the alternate PWM output stay on once it get’s to the set-point above and if so, what would be the best way to turn it off, so it’s only one or the other outputs? I’m wanting to make it so moonlight is a separate emitter (and it’s own 7135) and that emitter turns off above moonlight.

 RIP  SPC Joey Riley, KIA 11/24/14. Now I am become death, the destroyer of worlds.

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

Cereal_killer wrote:
Quote:
#define DUAL_PWM_START 8 // Above what output level should we switch from the alternate PWM output to both PWM outputs? Comment out to disable alternate PWM output
Hey guys, I'm looking at doing a dual PWM build but I'm wondering, does the alternate PWM output stay on once it get's to the set-point above and if so, what would be the best way to turn it off, so it's only one or the other outputs? I'm wanting to make it so moonlight is a separate emitter (and it's own 7135) and that emitter turns off above moonlight.

Yes, it stays on.  Check out Toykeeper's STARRY mod, or alternatively just change the code from 

void set_output(uint8_t pwm_lvl) {

#ifdef DUAL_PWM_START

if (pwm_lvl > DUAL_PWM_START) {

// Using the normal output along with the alternate

PWM_LVL = pwm_lvl;

} else {

PWM_LVL = 0;

}

#else

to

void set_output(uint8_t pwm_lvl) {

#ifdef DUAL_PWM_STOP

if (pwm_lvl > DUAL_PWM_STOP) {

// Above this level alternate will turn off

PWM_LVL = 0;

} else {

PWM_LVL = pwm_lvl;

}

#else

And also define a DUAL_PWM_STOP value.  Toykeeper's method is much simpler, and more in line with what how the momentary firmware works.  

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

Cereal_killer
Cereal_killer's picture
Offline
Last seen: 1 year 9 months ago
Joined: 07/22/2013 - 13:10
Posts: 4005
Location: Ohio

Ok thanks man. One more question, now that I’m looking at it- what’s the best proper way to enable moonlight when using the alternate PWM output? Before [when using a single PWM, before the new stuff came around] if I wanted to make moon be on without having to solder the star I would do this:

if ((PINB & (1 << STAR2_PIN)) > 0)

Is that still how I should do it or is there a better way?

edit: stupid smileys

 RIP  SPC Joey Riley, KIA 11/24/14. Now I am become death, the destroyer of worlds.

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

Cereal_killer wrote:
Ok thanks man. One more question, now that I'm looking at it- what's the -best- proper way to enable moonlight when using the alternate PWM output? Before [when using a single PWM, before the new stuff came around] if I wanted to make moon be on without having to solder the star I would do this: if ((PINB & (1 << STAR2_PIN)) > 0) Is that still how I _should_ do it or is there a better way?

With JonnyC's firmware if you use the secondary PWM output then moonlight is automatically enabled, since the firmware was originally designed as a firmware to get an exceptionally low moonlight (obviously not to control two different colors, otherwise the interface would be different).  

In short: no need to change anything.  I would take a look at what Toykeeper has done, as it may be easier for you to do what you want with your project.  

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

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

In the starry-offtime firmware, the only solderable star is the one which toggles mode memory. All the other pins are used for other things.

So, you’d probably want to just do something like this in the #defines at the top:

// PWM levels for the big circuit (FET or Nx7135)
#define MODESNx             0,2,12,100,255
// PWM levels for the small circuit (1x7135)
#define MODES1x             3,0,0,0,0
#define MODES_PWM           PHASE,FAST,FAST,FAST,PHASE

Edit: You might also want to remove the HIDDEN_MODES bits too, which aren’t actually hidden yet. I’ll go back and hide those on a day I’m feeling a little better.

Cereal_killer
Cereal_killer's picture
Offline
Last seen: 1 year 9 months ago
Joined: 07/22/2013 - 13:10
Posts: 4005
Location: Ohio

Ok thanks, and I’ll have a look at TK’s FW now too.

What I’m trying to do is make a driver to run my new 17650 light as an EDC, I want to have a triple in it with a nichia 219 powered by 2 or 3 7135’s for a good moonlight (plus low and medium modes) and then have it switch that off and turn on a FET that powers 2 XP-L’s for medium-max (to help with runtime from the little cells), does that seem doable?

I’ve made the changes you specify above and compiled, I got 5 warnings (but all were preexisting), it’ll be a few weeks before I have a board to test this setup tho.

edit: it’s a tail clicky only

 RIP  SPC Joey Riley, KIA 11/24/14. Now I am become death, the destroyer of worlds.

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

That will work, no problem. 

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

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

Cereal_killer wrote:
it’ll be a few weeks before I have a board to test this setup tho.

If it takes that long, I’ll probably have the BLF A6 firmware done (or released, anyway). It should work too, and does a lot more than starry-offtime. I branched it off to a new file because it barely even resembles STAR any more.
Cereal_killer
Cereal_killer's picture
Offline
Last seen: 1 year 9 months ago
Joined: 07/22/2013 - 13:10
Posts: 4005
Location: Ohio

It’s actually a little more indepth than I described above, I don’t know what the A6 FW is but doubt it would be what I need, thanks for the offer tho (and thanks for whatever it is in general).

In this application in actually going one step further and using a head twist as another control method (whether it’s loose or tight). I’ll do a thread on it once it’s done, according to you guys the FW Should be good, just waiting on the board for it to control it all.

 RIP  SPC Joey Riley, KIA 11/24/14. Now I am become death, the destroyer of worlds.

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

Ah, I have a host here waiting for me to mod it and write firmware including a head loose/tight sensor. I just haven’t gotten to it yet.

Nothing supports that yet, but it’ll be interesting to add.

The BLF A6 is a group buy currently in progress, with wight’s hybrid FET+1 driver in a tube light. It’s kind of groundbreaking in several ways. Take a look here for more details:

http://budgetlightforum.com/node/36667

Cereal_killer
Cereal_killer's picture
Offline
Last seen: 1 year 9 months ago
Joined: 07/22/2013 - 13:10
Posts: 4005
Location: Ohio

Here’s how I implement it for my use, feel free to expand on this method (if anyone needs a driver for a different light let me know, it will be harder than simply sizing this one down ~2mm but not to much I dont think. I dont use any sort of head sensor or monitor for a pull down, I simply use the head tighten to supply GND to the FET’s source.

http://budgetlightforum.com/node/29562?page=50#comment-723367 (post 1524 in case you have different page display settings)

 RIP  SPC Joey Riley, KIA 11/24/14. Now I am become death, the destroyer of worlds.

Cereal_killer
Cereal_killer's picture
Offline
Last seen: 1 year 9 months ago
Joined: 07/22/2013 - 13:10
Posts: 4005
Location: Ohio

This has probably already been discussed and the current work is pretty far advanced but I need to go back for a sec with this question to simple star off time WITHOUT dual PWM; exactly when does the MCU check which stars are pulled down? Is it continuous at every mode change or does it only do it at full reset (when the light either reverts back to the start or to the saved mode, i.e. a long press of the clicky).

Thinking of a way to add a moonlight switch, not to instantly jump to moonlight, but a way to select if moon will be in the mode rotation or not by grounding it’s star with some sort of mechanical switch. Would that work or does it not check the stars enough?

 RIP  SPC Joey Riley, KIA 11/24/14. Now I am become death, the destroyer of worlds.

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

Cereal_killer wrote:
This has probably already been discussed and the current work is pretty far advanced but I need to go back for a sec with this question to simple star off time WITHOUT dual PWM; exactly when does the MCU check which stars are pulled down? Is it continuous at every mode change or does it only do it at full reset (when the light either reverts back to the start or to the saved mode, i.e. a long press of the clicky).

Thinking of a way to add a moonlight switch, not to instantly jump to moonlight, but a way to select if moon will be in the mode rotation or not by grounding it’s star with some sort of mechanical switch. Would that work or does it not check the stars enough?

It doesn’t matter which firmware version you look at, all STAR_on_time and STAR_off_time work the same way… they check the stars every time they are powered on.

Note that the stored mode will change when moon is enabled/disabled. (assuming that memory is enabled)

It’s pretty straightforward to see all that in the code: note that the star-checking/modes-setup happens before the main WHILE loop.

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)

Cereal_killer
Cereal_killer's picture
Offline
Last seen: 1 year 9 months ago
Joined: 07/22/2013 - 13:10
Posts: 4005
Location: Ohio
wight wrote:
…It’s pretty straightforward to see all that in the code: note that the star-checking/modes-setup happens before the main WHILE loop.

Yep, I got that. Your right it’s very straight forward, what I dont know, and I still dont get after reading your reply is whether it checks it after every tap of the tail switch when it’s just changing modes, or if it only checks it at the initial start up after a full reset (the time when it either reverts back to the start or back to the memorized level).

I guess I could reword my question; Does a short power cycle to advance to the next mode restart the whole thing and re-initialize (thus checking the stars) or does only a full reset cause it to initialize again?

 RIP  SPC Joey Riley, KIA 11/24/14. Now I am become death, the destroyer of worlds.

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

A short tap should re-check the stars.

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)

Mike C
Mike C's picture
Offline
Last seen: 2 days 2 hours ago
Joined: 01/22/2014 - 08:03
Posts: 2584
Location: Sweden

A short tap restarts everything. If it didn’t the mode change wouldn’t work as all that is done at start up. It’s basically only watchdog interrupts (for turbo timeout) and voltage monitoring that is running, everything else is start up code.

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

That’s what makes clicky-switch lights so “fun” to write code for… it resets completely every time the button is pressed, and must boot fresh after each time. It’s actually a lot like how web application code works; it must start fresh on each page load. Anything which passes between pages must either be sent from the browser each time or saved in a cookie-linked session on the server. Except on torches, the “cookies” are in EEPROM or in a capacitor.

In any case, the star-checking code is not a sub-clause of the OTC-checking code, so it happens regardless of how long the switch was held down.

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

Is there a way to make a driver running Star OT think/act like it’s turned ‘off’ when it is still getting about 2ma of power?

This is a part of my idea in this thread

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

dkuku
Offline
Last seen: 6 years 8 months ago
Joined: 02/24/2015 - 00:18
Posts: 3

How to change the is_pressed() function to positive logic in momentary firmware?
I disabled the pullup resistor and soldered a pulldown resistor to the star and ground

Quote:
int is_pressed()
{

// Keep track of last switch values polled

static uint8_t buffer = 0×00;

// Shift over and tack on the latest value, 0 being low for pressed, 1 for pulled-up for released

buffer = (buffer << 1) | ((PINB & (1 << SWITCH_PIN)) == 0);

return (buffer & DB_REL_DUR);
}


I need it because my headlighe has a switch in front and 3 wires going to the battery and driver
  • +led which is also +batt
  • -led – which is not gnd so cannot use it for the the switch
  • is the switch – I connected the other side it to +led

Pages