E-switch UI Development / FSM

1024 posts / 0 new
Last post
Agro
Agro's picture
Offline
Last seen: 3 weeks 5 days ago
Joined: 05/14/2017 - 11:16
Posts: 6801
Location: Ślōnsk

Frightening Spaghetti Monster.
Or Finite State Machine.

MRsDNF
MRsDNF's picture
Offline
Last seen: 1 month 1 week ago
Joined: 12/22/2011 - 21:18
Posts: 13473
Location: A light beam away from the missus in the land of Aus.

That is better answers than Wiki gave me. Thumbs Up

 

djozz quotes, "it came with chinese lettering that is chinese to me".

                      "My man mousehole needs one too"

old4570 said "I'm not an expert , so don't suffer from any such technical restrictions".

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

MRsDNF
MRsDNF's picture
Offline
Last seen: 1 month 1 week ago
Joined: 12/22/2011 - 21:18
Posts: 13473
Location: A light beam away from the missus in the land of Aus.

ToyKeeper wrote:
It should be pretty easy to run it on a Mtn FET+1 driver if it has tiny85. There may be unusually high parasitic drain though, if the voltage divider resistors are still there. Those aren’t needed for single-cell FSM-based lights, but if they are there IIRC they allow current to leak.

Do these drivers have the voltage divider resistor? There are two resistors clearly shown on the fourth picture. It it near the 7135 chip or on the opposite side?

https://www.banggood.com/Astrolux-S1-BLF-A6-A17DD-L-FET-1-2_8-4_35v-7-4-Modes-Flashlight-Driver-p-1009980.html?rmmds=search&cur_warehouse=CN

 

djozz quotes, "it came with chinese lettering that is chinese to me".

                      "My man mousehole needs one too"

old4570 said "I'm not an expert , so don't suffer from any such technical restrictions".

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3
MRsDNF wrote:
What does FSM stand for?

Finite State Machine, or [F-word] Spaghetti Monster.

Why? Because it takes the mess of spaghetti code typically associated with low-level firmware and locks it away in a box where people don’t have to care about the monster inside. Instead it presents a more user-friendly interface in the form of a finite state machine, because that’s typically how people describe flashlight UIs. A finite state machine is basically a flowchart.

Suggested F words include:

  • Flashlight
  • Flying
  • FSM
  • Feisty
  • Filthy
  • Fabulous
  • Funky
  • Fancy
  • Fetid
  • Fortuitous
  • Frightening
  • Flirtatious
  • Flimsy
  • Frustrating
  • Formidable
  • Flaccid
  • Fantastic
  • Feculent
  • Friendly

Or people can probably think of a few other choice F-words. Wink

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3

MRsDNF wrote:
Do these drivers have the voltage divider resistor? There are two resistors clearly shown on the fourth picture. It it near the 7135 chip or on the opposite side?

https://www.banggood.com/Astrolux-S1-BLF-A6-A17DD-L-FET-1-2_8-4_35v-7-4-Modes-Flashlight-Driver-p-1009980.html?rmmds=search&cur_warehouse=CN

Yes, the one labelled R1, connected to pin 7, is along the path which allows current to leak. Removing it would stop the leak.

For BLF-A6 and Bistro, this is a good thing. The offtime measurement depends on current leaking out at a predictable and high enough rate. And for multi-cell serial lights it’s necessary to scale voltage down to a usable range. But for single cell e-switch lights it’s not desirable.

Those banggood drivers don’t have a tiny85 though, so they can’t run FSM.

MRsDNF
MRsDNF's picture
Offline
Last seen: 1 month 1 week ago
Joined: 12/22/2011 - 21:18
Posts: 13473
Location: A light beam away from the missus in the land of Aus.

Thanks TK for all the explanations. I have put Attiny 85’s on a couple of these drivers and run the eswitch between pin 2 and earth.
When I read through these posts I feel like a Friggin Scared Moose. Silly

 

djozz quotes, "it came with chinese lettering that is chinese to me".

                      "My man mousehole needs one too"

old4570 said "I'm not an expert , so don't suffer from any such technical restrictions".

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

staticx57
Offline
Last seen: 4 days 20 hours ago
Joined: 04/11/2016 - 00:43
Posts: 713
Location: New Jersey, United States

ToyKeeper wrote:
The MAX_1×7135 value determines which ramp level is the highest before the FET activates. It does not determine the PWM value.

If the emitters can only handle 30mA each, and there are three of them, it may not be a good idea to drive them with a 350mA chip. Even with PWM to reduce the average current, the momentary current will still be about 4X the safe level.

But if you try it, it looks like the 7135 part of the ramp should max out at 65/255. (3 * 30mA / 350mA) * 255 = 65. So, after calculating a ramp, multiply all the 7135 ramp values by about 0.257 to scale them down to the desired ceiling level.

Or you could maybe replace the 7135 chip with something lower-powered… or put a lower-powered chip on the aux LED pin and treat it as a 3-channel driver.

I figured that what else it could be while laying in bed thinking about this. Too far into this hobby where this ends up happening…

I would definitely need to test this on the bench with the PWM to see how it behaves. I have seen a test of these where at 120mA they start to go blue… Are there lower power 7135s?

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3
staticx57 wrote:
Are there lower power 7135s?

There should be lower-power chips of the same general type. I’m just not familiar with them.

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3

Lots of code updates lately, though most of them aren’t UI changes. Most are to keep code cleaner and more manageable, splitting hardware-specific bits out into their own files and such. This way, new drivers can be added more easily with less clutter. Drop in a hardware layout definition and a UI config file, and it should be pretty much done.

Due to the way the C preprocessor works though, it does typically still require adding a couple lines to the main source files. But the changes there are a lot smaller than they used to be, and easier to read.

Anyway, I paid off some technical debt so I’m done for the evening.

MRsDNF
MRsDNF's picture
Offline
Last seen: 1 month 1 week ago
Joined: 12/22/2011 - 21:18
Posts: 13473
Location: A light beam away from the missus in the land of Aus.
Thumbs Up Thanks TK.

 

djozz quotes, "it came with chinese lettering that is chinese to me".

                      "My man mousehole needs one too"

old4570 said "I'm not an expert , so don't suffer from any such technical restrictions".

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

ferk
Offline
Last seen: 6 months 3 weeks ago
Joined: 11/05/2017 - 04:36
Posts: 6
Location: Sweden

@TK
I couldn’t compile the latest anduril r344 for BLF Q8 in Atmel Studio 7.0
Got this error: #elif with no expression anduril.c Line 72

But it was an easy fix by changing:

#elif FSM_BLF_Q8_DRIVER
to
#elif defined(FSM_BLF_Q8_DRIVER)

Thanks TK for all your awesome work!

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3

Oops, that’s definitely a typo. Fixed.

I wonder how it even compiled like that. I’ve been using a script lately to build every supported version every time instead of doing just one, and the Q8 version built and worked normally under gcc 4.9.2. But it looks like it really shouldn’t have worked…

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3

Since it’s a thing people might want, and since I think Lexel may have been requesting it, I took a moment to make a Werner-style momentary UI, side e-switch plus tail clicky-switch.

https://code.launchpad.net/~toykeeper/flashlight-firmware/fsm

The short version is:

While completely off (power disconnected):

  • Click tail to turn on at memorized level.
  • Hold e-switch and click tail to enter utility mode.

While on (regular “on” mode):

  • Click tail switch to turn off.
  • Click side switch to go brighter.
  • Hold side switch to go dimmer.

In utility mode:

  • Click side switch to go to regular “on” mode.
  • Hold side switch to go turn on at lowest level.
  • Double click side switch to turn on at highest level.
  • 3 clicks: Battcheck.
  • 4 clicks: Ramp config.

Battcheck mode: Blinks out battery voltage.

  • Click to go back to utility mode.
  • 2 clicks for tempcheck mode.

Tempcheck mode: Blinks out current temperature in C.

  • Click to go back to utility mode.
  • 2 clicks for battcheck mode.
  • 4 clicks for thermal config mode.

Thermal config:

  • During first “buzz”, click N times to set floor level to N out of 150 total levels.
  • During second “buzz”, click N times to set ceiling level to 151 minus N.
  • During third “buzz”, click N times to set number of total brightness steps.
  • Each “buzz” can be skipped to leave the value as-is.

Ramp config:

  • During first “buzz”, click N times to calibrate current temperature to N degrees C.
  • During second “buzz”, click N times to set thermal ceiling to 30 C + N.
  • Each “buzz” can be skipped to leave the value as-is.

Includes LVP and smooth thermal regulation, copied directly from Anduril.

Lexel
Lexel's picture
Offline
Last seen: 10 months 1 week ago
Joined: 11/01/2016 - 08:00
Posts: 5895
Location: Germany

ToyKeeper wrote:
Since it’s a thing people might want, and since I think Lexel may have been requesting it, I took a moment to make a Werner-style momentary UI, side e-switch plus tail clicky-switch.

https://code.launchpad.net/~toykeeper/flashlight-firmware/fsm

The short version is:

While completely off (power disconnected):

  • Click tail to turn on at memorized level.
  • Hold e-switch and click tail to enter utility mode.

While on (regular “on” mode):

  • Click tail switch to turn off.
  • Click side switch to go brighter.
  • Hold side switch to go dimmer.

In utility mode:

  • Click side switch to go to regular “on” mode.
  • Hold side switch to go turn on at lowest level.
  • Double click side switch to turn on at highest level.
  • 3 clicks: Battcheck.
  • 4 clicks: Ramp config.

Battcheck mode: Blinks out battery voltage.

  • Click to go back to utility mode.
  • 2 clicks for tempcheck mode.

Tempcheck mode: Blinks out current temperature in C.

  • Click to go back to utility mode.
  • 2 clicks for battcheck mode.
  • 4 clicks for thermal config mode.

Thermal config:

  • During first “buzz”, click N times to set floor level to N out of 150 total levels.
  • During second “buzz”, click N times to set ceiling level to 151 minus N.
  • During third “buzz”, click N times to set number of total brightness steps.
  • Each “buzz” can be skipped to leave the value as-is.

Ramp config:

  • During first “buzz”, click N times to calibrate current temperature to N degrees C.
  • During second “buzz”, click N times to set thermal ceiling to 30 C + N.
  • Each “buzz” can be skipped to leave the value as-is.

Includes LVP and smooth thermal regulation, copied directly from Anduril.

nice

deus1ex
Offline
Last seen: 2 hours 50 min ago
Joined: 11/01/2017 - 02:40
Posts: 56
Location: Germany

ToyKeeper wrote:
I pushed up new code which implements a blinking indicator LED, using the half-sleep functionality. It’s simpler / easier than before though. Since power usage doesn’t seem to be much different with the WDT on, I made it always tick when in standby (if the option was enabled at compile time).

So, to use it:

  • #define TICK_DURING_STANDBY somewhere to enable it.
  • Optional: #define STANDBY_TICK_SPEED 5 to configure how often it’ll wake up. The available values are in the attiny85 manual, or in fsm-standby.h.
  • Set go_to_standby = 1; to enter sleep mode.
  • In your UI code, catch the EV_sleep_tick event to do something periodically during standby.
  • By default it emits the event every ~0.5s. The arg parameter counts up by one each tick, starting from zero. The counter resets on full wakeup.
  • Standby mode ends when the user presses a button, or when the code sets go_to_standby = 0; .

Anduril supports this in the off and lockout states, to implement a blinking beacon-like aux LED. The aux LED modes are now:

  • 0: off
  • 1: low
  • 2: high
  • 3: blinking

This is configured during lockout mode. Go there, then…

  • Click 3 times to change the aux LED mode in lockout.
  • Click 3 times and hold the last press to change the aux LED mode in “off”.

The ROM is running out of space now. On the Q8 build, it now comes to 8068 bytes (98.5% Full).

Is it possible to change the brightness of the low level of the indicator LED in the code. I have found nothing. Thank you

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3
deus1ex wrote:
Is it possible to change the brightness of the low level of the indicator LED in the code.

Nope, that is set entirely in hardware. It depends on the indicator LED Vf, the battery voltage, and the resistor(s) between them. Note that, in low mode, the attiny’s internal resistor is active, which is why low mode exists at all.

The code can’t change this, because the MCU is asleep and not executing any code. The PWM facility isn’t active.

deus1ex
Offline
Last seen: 2 hours 50 min ago
Joined: 11/01/2017 - 02:40
Posts: 56
Location: Germany

Thanks for the detailed answer. Thumbs Up

RotorHead64
RotorHead64's picture
Offline
Last seen: 10 months 1 week ago
Joined: 10/31/2015 - 02:49
Posts: 430
Location: United States

Hey y'all i'm late to the party and i'm trying to figure this out. I want to run anduril on a TA board that i'm pretty sure is a tripledown layout. Do I just add in a line "#define TRIPLEDOWN_LAYOUT " ? 

And what about the FET+1+20 part? Its just a FET+1+6. Any help will be much appreciated

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3

I’d suggest copying the FW3A config, or even just using it directly, depending on the details of that driver. It’s a FET+7+1, so it should be pretty close.

I recently (in the fsm branch) reorganized how hardware definitions work… there’s a physical layout file, like hwdef-FW3A.h, showing which pins do what and a couple other things. There’s also a UI config file, like cfg-fw3a.h, which configures options specific to Anduril or FSM.

Then there’s a magic #define to tell it which hardware config files to use.

There is a Tripledown definition, but I think it’s designed for a clicky-switch type with OTC and a voltage divider. So I suspect the FW3A definition might be closer, if you’re using it with e-switch instead of OTC, and if you take the voltage divider off. (it’s not recommended to have or use a voltage divider for e-switch lights, since it increases parasitic drain)

If you’re doing multiple cells in series though, it’ll need the voltage divider, and some bits copied/tweaked from the BLF GT configuration. And the 7135 chips are likely to burn out.

Anyway, you can probably just remove a voltage divider resistor and flash the FW3A build directly. If my guesses are right, it should “just work”.

RotorHead64
RotorHead64's picture
Offline
Last seen: 10 months 1 week ago
Joined: 10/31/2015 - 02:49
Posts: 430
Location: United States

Thanks TK. It's going into a sofirn C8F triple e switch only 1S light.

So, I'll just leave the voltage divider out and use the FW3A config.

 

RotorHead64
RotorHead64's picture
Offline
Last seen: 10 months 1 week ago
Joined: 10/31/2015 - 02:49
Posts: 430
Location: United States

What in the world is the optic nerve? Programming? More importantly for me at the moment is can I power the side switch LEDs with the FW3A config?

WTF
Offline
Last seen: 8 months 1 day ago
Joined: 03/05/2017 - 20:13
Posts: 318

ToyKeeper wrote:

There is a Tripledown definition, but I think it’s designed for a clicky-switch type with OTC and a voltage divider.

This is completely awesome.

It means my clicky and e-switch lights that I use daily can have the same user interface.

Just need to change the AtTinys on the Bistro lights to 85’s.

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3
RotorHead64 wrote:
What in the world is the optic nerve? Programming? More importantly for me at the moment is can I power the side switch LEDs with the FW3A config?

Oh, the FW3A doesn’t have a pin for an aux LED. The four main pins are used for 1×7135, Nx7135, FET, and e-switch. But you could probably attach the aux LED to pin 7 (PB2), and define something to make it use that. It should work, but will involve compiling your own version.

I’m also not entirely sure it’ll fit into ROM all at once. The third PWM channel uses extra space, and the aux LED uses extra space, and there may not be quite enough room for both unless you turn off something else.

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3

WTF wrote:
ToyKeeper wrote:

There is a Tripledown definition, but I think it’s designed for a clicky-switch type with OTC and a voltage divider.

This is completely awesome.

It means my clicky and e-switch lights that I use daily can have the same user interface.

Just need to change the AtTinys on the Bistro lights to 85’s.

Not really. E-switch and clicky switch aren’t capable of doing the same things. For example, it’s impossible to do “hold to change brightness” on a clicky switch, because holding (reverse clicky) physically disconnects power.

Anduril does not work on lights which have only a clicky switch. It requires an e-switch.

Comparing it to a computer, an e-switch works like a mouse button. It can be up or down, and the computer keeps processing in both states. But a clicky switch is more like pulling the power cord out of the wall. The computer won’t do anything at all until it’s plugged in again.

WTF
Offline
Last seen: 8 months 1 day ago
Joined: 03/05/2017 - 20:13
Posts: 318

ToyKeeper wrote:
WTF wrote:
ToyKeeper wrote:

There is a Tripledown definition, but I think it’s designed for a clicky-switch type with OTC and a voltage divider.

This is completely awesome.

It means my clicky and e-switch lights that I use daily can have the same user interface.

Just need to change the AtTinys on the Bistro lights to 85’s.

Not really. E-switch and clicky switch aren’t capable of doing the same things. For example, it’s impossible to do “hold to change brightness” on a clicky switch, because holding (reverse clicky) physically disconnects power.

Anduril does not work on lights which have only a clicky switch. It requires an e-switch.

Comparing it to a computer, an e-switch works like a mouse button. It can be up or down, and the computer keeps processing in both states. But a clicky switch is more like pulling the power cord out of the wall. The computer won’t do anything at all until it’s plugged in again.

I don’t have any lights with ramping, never thought of the hold to change brightness thing. I was hoping FSM could do modes just like Bistro.

Out of all the flashlights and bike lights I have only three have the same user interface. I really want to do something about that.

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3
WTF wrote:
I don’t have any lights with ramping, never thought of the hold to change brightness thing. I was hoping FSM could do modes just like Bistro.

It can do modes, like Bistro. There are several interfaces available, though the most popular one is Anduril. And instead of doing smooth ramping, it can do a mode group. Like Bistro, the user sets the number of modes. Unlike Bistro, the user can also set the brightness of the lowest and highest mode, and it’ll automatically space the in-between levels evenly. The actions from there are a little different than Bistro too — hold for a brighter mode, release and hold to go to a dimmer mode.

Or if you want e-switch lights to work almost exactly like Bistro, Flintrock added e-switch support to Bistro-HD. It pretends the e-switch is a clicky switch, even making sure to turn the light off momentarily while the button is pressed. It uses short and medium presses to go up and down. However, since an e-switch can’t actually cut power, turning the light off requires an extra-long press.

WTF
Offline
Last seen: 8 months 1 day ago
Joined: 03/05/2017 - 20:13
Posts: 318
ToyKeeper wrote:
WTF wrote:
I don’t have any lights with ramping, never thought of the hold to change brightness thing. I was hoping FSM could do modes just like Bistro.

It can do modes, like Bistro. There are several interfaces available, though the most popular one is Anduril. And instead of doing smooth ramping, it can do a mode group. Like Bistro, the user sets the number of modes. Unlike Bistro, the user can also set the brightness of the lowest and highest mode, and it’ll automatically space the in-between levels evenly. The actions from there are a little different than Bistro too — hold for a brighter mode, release and hold to go to a dimmer mode.

Or if you want e-switch lights to work almost exactly like Bistro, Flintrock added e-switch support to Bistro-HD. It pretends the e-switch is a clicky switch, even making sure to turn the light off momentarily while the button is pressed. It uses short and medium presses to go up and down. However, since an e-switch can’t actually cut power, turning the light off requires an extra-long press.

Bistro works fine on the clicky lights.

What I would like to do is unify my bike lights somehow. Getting to low mode fast when rounding a bend at speed on a bumpy trail and meeting another trail user needs to be easier. Too often I wind up in programming or strobe mode.

Now that Narsil and Anduril are available for buck drivers it has me thinking about replacing the Pic’s with AtTinys on a board glued to the LED shelf. How the light reacts to overheating is a big concern. The lights with a remote battery pack are quite small for the power they produce. The light needs to be able to protect itself when going slow or stopped but can’t step down abruptly when going fast in tricky sections.

The way you have Anduril responding to heat looks really good. It can’t match the Pic based lights with an actual temperature sensor but having the MCU to the shelf should be good enough. Ideally I’d like to remove some functions so they can’t be accidentally accessed or heavily debounce the e-switch. One button press can turn into many depending what the front tire runs into on the trail. I’m OK with basic Arduino stuff, a quick look at Anduril code tells me I am in for a steep learning curve.

mrheosuper
Offline
Last seen: 2 months 2 weeks ago
Joined: 09/30/2016 - 12:44
Posts: 1515
Location: Ho Chi Minh City, Vietnam

Hello, maybe this question is already asked, but i dont want to get through 300 posts here Sad

i have BLF A6 driver, now i want to flash new FW which supports e-switch, which FW should i flash, thank you
I can reflow the attiny 13 to attiny 85 if needed

Forgot my pen

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3
mrheosuper wrote:
i have BLF A6 driver, now i want to flash new FW which supports e-switch, which FW should i flash, thank you I can reflow the attiny 13 to attiny 85 if needed

The BLF A6 driver has an issue with large voltage spikes on each FET pulse. The attiny13 handles this like a champ, but other attiny models reboot when the voltage goes out of spec. So they don’t work well above 4 or 5 Amps.

So you could stick with attiny13-based firmware, which will only have very simple interfaces, or you could mod the driver even further to fix the voltage spikes, or you could get/make drivers which don’t have that problem.

ToyKeeper
ToyKeeper's picture
Online
Last seen: 8 min 10 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10728
Location: (469219) 2016 HO3
WTF wrote:
What I would like to do is unify my bike lights somehow…

It sounds like a pretty detailed project, doing fairly deep modifications of both hardware and firmware. Have you considered making a thread for it here on BLF? It’d be exactly the sort of thing people love to see and talk about.

Pages