STAR Firmware by JonnyC - Source Code and Explanation

1335 posts / 0 new
Last post
zeremefico
zeremefico's picture
Offline
Last seen: 9 hours 15 min ago
Joined: 03/27/2012 - 02:44
Posts: 1390
Location: Greece

JonnyC wrote:

Hmm, I don’t get that error when I compile. The line in question must be this…

PROGMEM  uint8_t modes[] = { MODES };

Maybe try just adding “const” in there, as it is constant (doesn’t change at runtime), so it doesn’t hurt for me to add that too.

PROGMEM  const uint8_t modes[] = { MODES };

Maybe you’re on a slightly newer version of ARV Studio than me (5.0.1223) so it’s providing better warnings?  I tried enabling all warnings and it still wasn’t giving me that error.

If that’s the fix I’ll have to add that into the file posted on my site.


This gave no error.
Just have to flash & try if everything ok.
is Ulfuse:w:0×75:m -Uhfuse:w:0xFF:m ok?

₪₪₪₪ ΟΥΔΕΝ ΚΡΥΠΤΟΝ ΥΠΟ ΤΟΝ ΗΛΙΟ ₪₪₪₪

My YouTube channel

Flashlights & edc gear

K40M F16

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

ToyKeeper wrote:
I'm not sure why that particular variable was declared as progmem though

I'm not sure either Wink  Another reason why I deserve no credit for this firmware as I'm just picking up stuff as I go.  Finally read more about it, and it just frees up RAM space by storing it in the program space (flash memory) instead (attiny13a has 64 byte RAM, 1024 byte program storage).  So it really doesn't matter in the case of STAR_no_ramp because the program is only 736 bytes, but it becomes an issue when you start adding extra functionality.  This weekend I'll remove it, test it, and change version numbers of the program on my site.  Maybe I'll finally create a GIT repository as well so you guys can see what all changes were made between versions.

This weekend I should hopefully get around to finally adding the ability to define PWM modes (fast-pwm vs phase correct) per mode, and add the ability for a second PWM output in case, for example, you want to drive just one 7135 in moonlight mode.  Hopefully it can be done, we'll see.  The problem with changes like these is the four programs I have out on my site are all slightly different and require testing, with some of them already pushing the limit on program space Sad  It will then be confusing if one program has the new features but the others don't, as I'm sure that will be the case here.

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

zeremefico wrote:
is Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m ok?

Yup, that's what I use.

comfychair
comfychair's picture
Offline
Last seen: 5 years 7 months ago
Joined: 01/12/2013 - 05:39
Posts: 6198

ToyKeeper wrote:
I don't have a fully-working firmware yet though. I broke my SRK's switch wire by taking the driver out for flashing too many times, and I've been too busy to fix it yet. So, that firmware is stalled.

For open-air testing out on the bench, just ground whichever pin at the MCU (or the switch pad on the PCB) with tweezers. Because of stuff like breaking wires when assembling/disassembling a bunch of times while testing, I solder wires to the input side of the driver and use an external battery box with alligator clip leads until I'm nearly sure it's ready for final assembly. I also do that for the reason that on these press-fit drivers, they get a little less tight each time you remove them, so try to keep that to a minimum.

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Should I add any links on my firmware page (http://www.jcapsolutions.com/flashlights/firmware/) to other sources of information on aquiring a programmer, how to flash, Attiny13a pinout, etc.?  If you have any ideas on links shoot them my way, since I don't even know of all of the resources out there.  Then hopefully the page can kind of be a point of entry for people new to this.

zeremefico
zeremefico's picture
Offline
Last seen: 9 hours 15 min ago
Joined: 03/27/2012 - 02:44
Posts: 1390
Location: Greece

That would be nice!
I now have a courui driven @3amps with srk no ramp Firmware. If I decide to use a fet nanjg, should I make any changes to Firmware?

₪₪₪₪ ΟΥΔΕΝ ΚΡΥΠΤΟΝ ΥΠΟ ΤΟΝ ΗΛΙΟ ₪₪₪₪

My YouTube channel

Flashlights & edc gear

K40M F16

comfychair
comfychair's picture
Offline
Last seen: 5 years 7 months ago
Joined: 01/12/2013 - 05:39
Posts: 6198

zeremefico wrote:
That would be nice! I now have a courui driven @3amps with srk no ramp Firmware. If I decide to use a fet nanjg, should I make any changes to Firmware?

The FET drivers will start working down at lower PWM values than 7135 drivers... FETs light up all the way down at 1 or 2, 7135s require a minimum of 5 or 6 for the lowest mode. Other than that, everything else in the firmware works the same.

For FET drivers without an inductor (if you don't know what that means then you don't have one) I use PWM levels of 0,1,6,20,56,120,255.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 2 hours 37 min ago
Joined: 01/12/2013 - 14:40
Posts: 10809
Location: (469219) 2016 HO3
JonnyC wrote:
Maybe I’ll finally create a GIT repository as well so you guys can see what all changes were made between versions. … Should I add any links on my firmware page (http://www.jcapsolutions.com/flashlights/firmware/) to other sources of information on aquiring a programmer, how to flash, Attiny13a pinout, etc.?

For what it’s worth, I’ve already created a DVCS repo with STAR in it, among other firmwares. I’ve been really busy trying to get a house sold during off-work hours so I haven’t added everything I want to it yet, but it’s supposed to go on the market tomorrow and free up a lot of time. Anyway, that project/repo is here:

https://launchpad.net/flashlight-firmware

It’s using bzr+Launchpad instead of git+GitHub, but it’s mostly the same idea. LP has more features but isn’t as popular.

In the repo itself, I have each version of STAR I could find, NLITE (some other DrJones projects coming soon), MikeC01’s STAR derivatives, my own STAR derivatives, example code from tterev3, some info on how to get started, convenience scripts, etc.

So, I have some questions:

  • Can several of us share a code repository to make things simpler for everyone else?
  • If so, is Launchpad okay or should we move it elsewhere?
  • To explicitly prevent/avoid any copyright issues, could we add some type of open-source license to as much of the code as possible?

fellfromtree
fellfromtree's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 07/25/2014 - 15:14
Posts: 470
Location: spelunking

Is there any pins that could run a separate load than the one to the emitter? Like to kick a fan on and off using the temperature sensor.

Thanks

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

fellfromtree wrote:
Is there any pins that could run a separate load than the one to the emitter? Like to kick a fan on and off using the temperature sensor. Thanks

Looking at the ATtiny13A datasheet it looks like 20 mA is about the most you can get out of the pins directly, so you would need to use some type of relay (like the 7135 acts as) to drive a fan.  If you're wondering what pins can output, on the NANJG driver stars 2 through 4 can be configured as outputs.

NightSpy
NightSpy's picture
Offline
Last seen: 4 years 8 months ago
Joined: 08/30/2011 - 18:24
Posts: 794

I think the spec is 40ma max per output, 200ma max for all outputs. But the answer is yes, you have multiple outputs available on the MP. However, the code would not follow anything we’ve worked with yet.

I like the idea of mixing output pins to come up with more complex flash patterns. Seeing how the MP is “generic”, you really have to work from the ground up to integrate your specifications.

That little chip can do a lot. Just don’t overlook what has already been developed in the stock drivers. Some features are not mentioned very often in these threads, like the 2.8V/cell dropout protection where the drivers goes into a low output slow flash. A feature that is a mode onto itself.

fellfromtree
fellfromtree's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 07/25/2014 - 15:14
Posts: 470
Location: spelunking

Ah thanks. Yeah Jonny that would work as long as it has a separate out for the relay.

comfychair
comfychair's picture
Offline
Last seen: 5 years 7 months ago
Joined: 01/12/2013 - 05:39
Posts: 6198

It will not run a relay, you'll need a small FET. Depending on the load you're driving the fet could run it directly or be used to control the coil on a traditional mechanical relay. The MCU does not have any temperature sensing ability though, so it would probably be best to use a separate fan controller with its own thermistor.

I think (wink wink nudge nudge) someone is working on the bits to plug into STAR momentary use the unused PB4/PB0 (pins 3 & 5) to power battery level indicator LEDs... they're very low current, able to be powered directly by the MCU. Once the code is worked out it can be tweaked to make those pins do other stuff.

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

So this is a little sneak peak of the tiny changes I made to the SRK_no_ramp firmware to utilize the 2nd star for a PWM output as well as the normal output.  Also you can set the...hold on a sec, I was just testing it again and now have a blank spot in the middle of my vision.  Ok, I can see what I'm typing again.  You can set PWM mode/function by each individual mode as well.  This will allow you to, for instance, run (with a custom board or added wiring to the 105C) moonlight mode using phase correct PWM off of a single 7135, and then have every other mode run off all 7135's using fast-PWM.

I'm SURE this has been documented before on this site, I was just surprised what little changes it took to work.  I'll be polishing up the code and have RMM take a run at it before I release it.

Note:  I didn't try a real moonlight mode here.  Later I set the PWM value to 2 and it barely glows.

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 6 months ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town

custom board…mwahahahahahaha >)

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

JonnyC wrote:

So this is a little sneak peak of the tiny changes I made to the SRK_no_ramp firmware to utilize the 2nd star for a PWM output as well as the normal output.  Also you can set the…hold on a sec, I was just testing it again and now have a blank spot in the middle of my vision.  Ok, I can see what I’m typing again.  You can set PWM mode/function by each individual mode as well.  This will allow you to, for instance, run (with a custom board or added wiring to the 105C) moonlight mode using phase correct PWM off of a single 7135, and then have every other mode run off all 7135’s using fast-PWM.

I’m SURE this has been documented before on this site, I was just surprised what little changes it took to work.  I’ll be polishing up the code and have RMM take a run at it before I release it.

That sounds great, thanks for attacking this!

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)

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

I finally put together a Github repository.  Here's a link to the "dual pwm" branch where so far I've added the PWM features to STAR and STAR_momentary.  They have been (mostly) tested.  But if someone wants to give them a shot, or maybe just pull the new logic in for their own use, obviously feel free.

https://github.com/JCapSolutions/blf-firmware/tree/dual_pwm

Speaking of which I've finally named my programs a little better.  STAR_momentary instead of SRK_no_ramp, and STAR_dual_switch instead of DualSwitch.  I'll update my site sometime to change the names and point to Github for the downloads.

ImA4Wheelr
Offline
Last seen: 2 months 3 weeks ago
Joined: 02/03/2013 - 14:51
Posts: 7935
Location: SC

Cool.  Thanks JonnyC.

ImA4Wheelr
Offline
Last seen: 2 months 3 weeks ago
Joined: 02/03/2013 - 14:51
Posts: 7935
Location: SC

Oh my gosh.  I just tried the STAR momentary without ramping with Tom E's modifications.  Wow, love it.  High, Low, Strobe, all available at start up.  Can go up, down, to strobe, or off from anywhere.  Very reliable and consistent behavior.  Quite impressive.

The only improvement I can think of is to add an SOS mode.  It can potentially be a life saver.  Maybe only available from Strobe with another long click or or 2 fast clicks.

aw73
Offline
Last seen: 1 year 2 months ago
Joined: 08/01/2014 - 15:01
Posts: 96
Location: Magnolia State

star momentary can only be used with a forward clicky on a qlite driver correct?

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

aw73 wrote:
star momentary can only be used with a forward clicky on a qlite driver correct?

It can only be used by a light with an e-switch, or momentary switch (not a clicky), such as the SRK.  STAR or STAR_off_time is what can be used with forward clicky or reverse clicky light.

aw73
Offline
Last seen: 1 year 2 months ago
Joined: 08/01/2014 - 15:01
Posts: 96
Location: Magnolia State

ok thanks jonny! i love star off-time, but was just looking for a way to quickly access strobe mode. i guess you cant have everything. Sad

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

aw73 wrote:
ok thanks jonny! i love star off-time, but was just looking for a way to quickly access strobe mode. i guess you cant have everything. :(

It's doable to do something like "tap on and off very quickly two times and it will put you into a hidden mode". But that would require extra logic within the watchdog timer, and the program is already full due to my inefficient coding Smile

Of course now I have to look at the program quick just to make sure it would be too tough to tackle...

Well it's doable, it would just require eliminating some features, because I've already racked my brain trying to come up with a better design to make the code more efficient.  Some people here have come up with more efficient delay routines, maybe I'll have to look at those.

aw73
Offline
Last seen: 1 year 2 months ago
Joined: 08/01/2014 - 15:01
Posts: 96
Location: Magnolia State

i tried to eliminate the stars in the code to make more room like mikec did, but it always comes up with errors so i am doing something wrong or not eliminating enough code. i am not a hacker so i dont no what i am doing, but i understand what some things do in the code but am lost in other parts.

if i tried to learn C programming i would probably get a brain hemorrhage or lots of headaches. it seems in code you have to tell the cpu or mcpu the same things several times in different ways to make it understand or so not to make a mistake. maybe one day their will be a high enough language for idiots like me to understand… Big Smile

NightSpy
NightSpy's picture
Offline
Last seen: 4 years 8 months ago
Joined: 08/30/2011 - 18:24
Posts: 794

Jonny; is the low voltage warning (low output slow flash) something built into the chip based on the two divider resistors or is this coded as well?

To me, this is a critical feature as I use these for bike lights where I cannot see them to confirm the batteries are still up.
I rarely run out of power, but I would hate for my unprotected cells to get sucked down below the 2.75V minimum.

JonnyC
JonnyC's picture
Offline
Last seen: 7 months 1 week ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

NightSpy wrote:
Jonny; is the low voltage warning (low output slow flash) something built into the chip based on the two divider resistors or is this coded as well? To me, this is a critical feature as I use these for bike lights where I cannot see them to confirm the batteries are still up. I rarely run out of power, but I would hate for my unprotected cells to get sucked down below the 2.75V minimum.

That's in the code.  I was thinking I could remove the flashing part and just have it step down with a single short blink to the next-lower mode (instead of cutting it in half).  Not sure how much space that would save though.

Really, at this point, especially with the new dual-PWM output / PWM type definable per mode feature, each implementation for someone needs to be customized.  I guess I could put it all in there, but at the top of the file you have to pick and choose what features you want, but you can't have them all.

NightSpy
NightSpy's picture
Offline
Last seen: 4 years 8 months ago
Joined: 08/30/2011 - 18:24
Posts: 794

I really need to learn C++ :~

austime
Offline
Last seen: 7 years 1 week ago
Joined: 07/19/2014 - 17:41
Posts: 47
Location: Melbourne Australia

Hi, I’ve managed to get srk_no_ramp_1.0.c installed on my srk. Is it normal that when i switch from mode 1 to 2 (0 to 16), it temporarily lights up at a very low level (just glowing) before moving on to mode 2 (16)? Then if I do a long hold, it drops to the just glowing again until I release the button (and then it goes to 0 )? Thanks!

comfychair
comfychair's picture
Offline
Last seen: 5 years 7 months ago
Joined: 01/12/2013 - 05:39
Posts: 6198

Yes, that's an issue with fast-PWM and the MCU being awake (while the button is held down) but not outputting a PWM signal.

If you're not using it to control a 7135-based driver, you should really adjust those levels from the defaults in the original source file. Different driver hardware will work with different minimum levels, 7135s need a minimum of around 5-6, other stuff can go much lower. Some hardware may be too bright in the lowest mode with even a PWM of 1.

NightSpy
NightSpy's picture
Offline
Last seen: 4 years 8 months ago
Joined: 08/30/2011 - 18:24
Posts: 794

That brings up an interesting question… is the PWM signal a square wave with an equal on/off cycle or is it a triggered pulse where the off-time can be significantly longer?

Pages