FOC-Stim: a new approach to DIY stim hardware.

This is the place for all suggestions, releases and feedback regarding Milovana Hardware efforts.
diglet
Explorer At Heart
Explorer At Heart
Posts: 390
Joined: Sun Dec 11, 2022 5:43 pm

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by diglet »

40A is the maximum the hardware can deliver given sufficient cooling and very low resistance motor. I believe ST tested this hardware to 25A with forced air cooling, and the mosfets are rated for 160A pulsed. You will not see such high of a current in this application due to the internal resistance of the inductors and transformers.

Yesterday, I tested what would happen in the event of a software failure that would send the maximum voltage (12v) to the transformers. Over my test resistors (2 x 220ohm) which I placed on the output side of the box, I measured 180mA over 600µs after which the transformers saturated. This will deliver a nasty shock, for reference the strongest signal I tested in play is about 100mA over 300us. The large transformers used in most stereo units can deliver much larger shocks.


I don't want to sound too condescending wrt safety, but I just grabbed transformers some transformers off the shelf I had already tested to be adequate in size, ordered a kit of inductors/capacitors and started programming. The galvanic isolation the transformers offer made me comfortable enough to try it.

If you want additional analog protection, you can add a TVS diode to the input for additional protection against a failing power supply. Filter capacitors to block high or low frequencies are not needed in my opinion. I don't know what other hardware protections you can add, maybe a fuse on the input? Smaller transformers?


I don't know why combining foc + stereostim would behave differently than 2x stereostim or 2x foc. It may have something to do with the lack of a shared clock, but that should also be a problem with 2x foc since the pulse timing in foc is not super accurate. The audio algorithm in Restim has sample-accurate timings.
darthjj wrote: Fri Dec 20, 2024 12:04 pm Can you use just 2 of the outputs on a FOC-stim? Not sure what kind of electrode configuration I could use with 2x triphase
The hardware supports it, but the code requires all 3 outputs to be connected to the same body. At some point, I will add some code to detect if one of the wires is broken/loose.

The capacitor specs are not critical. Any ceramic cap >12v and >=4.7uf, <= 20uf will work.
mantrid
Explorer At Heart
Explorer At Heart
Posts: 166
Joined: Sun Dec 30, 2018 6:40 pm
Gender: Male
Sexual Orientation: Straight
I am a: Switch

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by mantrid »

What is the benefit of this design? You have three outputs but sum of all currents must be zero. This results in two degrees of freedom (DOF). The same can be achieved with stereo amplifier and a current controlled output driver. (For better understanding: How you want to drive 10mA on one electrode and 0 on the two others? That's not possible.)

If the inputs U,V,W can be controlled independently, you should use terminals 6 of the transformers as common. Then you have 4 electrodes and 3 DOF. (The same could achieved with a 3 channel amplifier and current controlled output driver.)
GAsm -- A guide assembler with EStim support to generate interactive teases that run in a browser.
diglet
Explorer At Heart
Explorer At Heart
Posts: 390
Joined: Sun Dec 11, 2022 5:43 pm

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by diglet »

The benefit of this design over a class A/B current driver is that it is more efficient, has low component count, and has no phase shift. The full digital approach also offers some safety benefits (imo). The benefits of current controlled designs over voltage controlled designs are numerous, I find the stim experience to be much better than stereostim although the signal generator is identical.

I followed someone on discord building/designing a voltage controlled current source and it did not appear to be easy. There are no off-the-shelf parts that work for our use case, the best match I was able to find are multi-channel LED drivers. Still if you have built a voltage controlled current source, it will feel very similar to foc.

The 3-channel amplifier you speak of has 12 mosfets of which 8 are non-redundant, such amplifier can indeed drive 4 electrodes with 3DOF. This is a tripple half-bridge design with 6 mosfets, it can only drive 3 electrodes with 2DOF. Hypothetically, I only need 2 transformers and 2 inductors to do that, but I decided to go for a symmetric design, the math was less yank.


Edit: half bridge, not H bridge.
darthjj
Explorer At Heart
Explorer At Heart
Posts: 134
Joined: Wed Jun 16, 2021 6:42 am

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by darthjj »

diglet wrote: Fri Dec 20, 2024 3:47 pm Yesterday, I tested what would happen in the event of a software failure that would send the maximum voltage (12v) to the transformers. Over my test resistors (2 x 220ohm) which I placed on the output side of the box, I measured 180mA over 600µs after which the transformers saturated. This will deliver a nasty shock, for reference the strongest signal I tested in play is about 100mA over 300us. The large transformers used in most stereo units can deliver much larger shocks.
This is the kind of stuff I meant with thorough safety analysis :) Thanks for indulging me!

Under normal operation, the load resistance doesn't matter since it's current driven, right? Would you get different measurements in this test with higher resistance, or would the max charge still be the same? I think a human body part is theoretically 2100-2400 Ohm if you count 2x "wet skin" + a bit of inter-body conduction varying on distance. But if the max charge does not depend on the load, I think the delivered charge would be 0.18A * 0.0006s = 108uC. Does it make sense to compare this with a taser (which delivers a charge of 15 - 500uC according to wikipedia), or is there a difference between higher current * short time and lower current over a longer time even though the charge is the same? I assumed the board would be able to continuously deliver the charge you measured as AC, or did I misunderstand something?

I feel my stereostim is "safe enough" because it's a fairly simple and static circuit. Even if the transformers are overdimensioned, the audio amplifier isn't likely to suddenly fail in a way that it starts to deliver higher voltage. While not necessarily pleasant, even at its max volume it doesn't cause full body spasms that would prevent me from turning it off or removing the electrodes. I count on catastrophic hardware failures in both audio amplifiers and power supplies being extremely rare, because otherwise you'd hear more about people's loudspeakers randomly blowing up, or common electronic devices exploding when their PSU starts giving them high voltage instead of what they were designed for.

I'm absolutely not trying to claim that the FOC-stim is dangerous during normal operation or anything like that, but at least for me it would feel safer if I knew that it was impossible for software errors to cause serious harm. I hope it's extremely unlikely that both the software fails in a way that the volume gets set to max, and the software current limiter doesn't work as expected, but weirder things have happened. I have worked with different SIL and ASIL classified software development, and despite rigorous testing, specifications and reviews even teams of experienced developers make mistakes :)
diglet wrote: Fri Dec 20, 2024 3:47 pm I don't know why combining foc + stereostim would behave differently than 2x stereostim or 2x foc. It may have something to do with the lack of a shared clock, but that should also be a problem with 2x foc since the pulse timing in foc is not super accurate. The audio algorithm in Restim has sample-accurate timings.
It does sound a bit strange, doesn't it? Perhaps I expressed myself poorly, when I said I wanted to use the in parallel I meant on different parts of my body at the same time. Breadfan's second post made it sound like perhaps he was connecting both devices to the same electrodes, i.e. literally in parallel.
diglet
Explorer At Heart
Explorer At Heart
Posts: 390
Joined: Sun Dec 11, 2022 5:43 pm

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by diglet »

Under normal conditions, the load resistance doesn't matter because FOC-Stim estimates a model of the skin resistance/inductance. It uses this model to adjust the waveforms such that the current follows the pre-planned pulse trajectory.

The resistance of the skin with good quality electrodes is substantially smaller than 2000 ohm. My model estimates about 100 ohm for each conductive rubber electrode, or 200 ohm body resistance in total. Large internal electrodes have a resistance even lower than that, but I have not tested FOC with internal electrodes yet.

In failure scenario's, the maximum output is limited by transformer saturation, whose unit is volt*second. The lower the body resistance, the more charge the transformer can deliver before saturating. I think the comparison with a taser is quite reasonable. For muscle activation, heat and chemistry, it doesn't really matter if you deliver the charge in 600us (my test) or 10-100us (wikipedia's claimed taser pulse duration).

The board is definitely capable of continuously delivering 106µC pulses. But I think a failure that causes that to happen is orders of magnitude more unlikely than a failure resulting in only a single pulse.

I'm not so trusting of analog equipment. They tend to behave pretty badly when cables break, there is a lot of static electricity or your computer bluescreens. I guess it depends on your viewpoint whether it's safer or less safe than a purpose built microcontroller programmed by a random bloke on the internet with too much spare time. ;-)

I appreciate the discussion.
darthjj wrote: Sat Dec 21, 2024 10:38 am It does sound a bit strange, doesn't it? Perhaps I expressed myself poorly, when I said I wanted to use the in parallel I meant on different parts of my body at the same time. Breadfan's second post made it sound like perhaps he was connecting both devices to the same electrodes, i.e. literally in parallel.
Edger477/Breadfan's setup has 5 electrodes, of which one is connected to two boxes at the same time.
darthjj
Explorer At Heart
Explorer At Heart
Posts: 134
Joined: Wed Jun 16, 2021 6:42 am

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by darthjj »

diglet wrote: Sat Dec 21, 2024 11:54 am
If you've measured it I trust your numbers. I was looking at some diagrams which claimed 1000 Ohm for wet skin, and I counted it twice since the current both has to go into your body at one electrode and out of it at another.

If it's any consolation, I wouldn't trust my own code more than yours for something like this :D I've done silly mistakes like burning expensive servos by using normal API functions, just because I didn't know you had to initialize a global timer first.
mantrid
Explorer At Heart
Explorer At Heart
Posts: 166
Joined: Sun Dec 30, 2018 6:40 pm
Gender: Male
Sexual Orientation: Straight
I am a: Switch

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by mantrid »

diglet wrote: Fri Dec 20, 2024 9:46 pm The benefit of this design over a class A/B current driver is that it is more efficient, has low component count, and has no phase shift. The full digital approach also offers some safety benefits (imo). The benefits of current controlled designs over voltage controlled designs are numerous,
The advantage of current controlled vs. voltage controlled is obvious. What is the advantage over a current controlled stereo amplifier?

Whenever possible, safety should be implemented using passive components, not with complicated software.
diglet wrote: Fri Dec 20, 2024 9:46 pm The 3-channel amplifier you speak of has 12 mosfets of which 8 are non-redundant, such amplifier can indeed drive 4 electrodes with 3DOF. This is a tripple half-bridge design with 6 mosfets, it can only drive 3 electrodes with 2DOF. Hypothetically, I only need 2 transformers and 2 inductors to do that, but I decided to go for a symmetric design, the math was less yank.
Math is the same. Only difference is that you have to set V = -U-W manually in your design, to satisfy U+V+W = 0. With a (current controlled) stereo amplifier C = -L-R is satified by design.

You can have 3 DOF with 3 push/pull drivers. You just have to AC-couple (using a capacitor) terminals 2 of the transformers to GND. (You could couple directly, if you could drive negative voltages.)

The general equation system for shunts below the push/pull drivers is:

Code: Select all

/ 0  1  1 -1 \ / U \   / S_U \
| 1  0  1 -1 | | V | = | S_V |
| 1  1  0 -1 | | W |   | S_W |
\ 1  1  1  1 / \ C /   \  0  / ,
where U,V,W,C are the terminal currents and S_U, S_V, S_W are the currents measured by the shunts. (AC coupling of C implies implies the constraint that the DC component of C must be zero. This is satisfied if the DC components of U,V,W are 0.)

If C is floating (your design or if a motor is connected), it is enforced to be 0. Then, the equation system is only solvable if U+V+W = 0.
GAsm -- A guide assembler with EStim support to generate interactive teases that run in a browser.
diglet
Explorer At Heart
Explorer At Heart
Posts: 390
Joined: Sun Dec 11, 2022 5:43 pm

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by diglet »

mantrid wrote: Sat Dec 21, 2024 4:16 pm The advantage of current controlled vs. voltage controlled is obvious. What is the advantage over a current controlled stereo amplifier?
I explained that already. It is more efficient, has no phase shift, and relies on a board you can actually buy for cheap. As far as I'm aware of there is no commercially available current controlled amplifier board or IC that fits our use case. You can definitely make one yourself if you solder 30 components on a board.

I looked into making one, and concluded designing a solution like FOC-Stim from scratch was easier and more likely to useful to other members of the community.
mantrid wrote: Sat Dec 21, 2024 4:16 pm Whenever possible, safety should be implemented using passive components, not with complicated software.
Yes but also I don't really see what your point is. The outputs are isolated from the input, the transformers filter the low frequencies and inductors the high frequencies (about 5khz max for any meaningful nerve activation). What more do you need? Filtering frequencies doesn't really work anyway, there are valid reasons to want short bursts of 10khz waveforms intermixed with some 500hz components. Good luck designing a hardware filter for that with acceptable component count. Safe waveform envelope depends on parameters not known at design time, such as electrode size and skin resistance.


The math I was talking about wasn't for calculating the current at the fourth leg, but for learning the model parameters. The current sensors on this board are not good enough to do current control by peak/valley detection, I control it with an MRAC model.

Yes, it is possible to get 3DOF with 3 H-bridges if you invent a new voltage rail at VDD/2, but that introduces numerous complications. If you want more DOF, the least complicated approach is to just add more half bridges. There is a reason you don't see 3-phase inverters with only 2 half bridges :-)
mantrid
Explorer At Heart
Explorer At Heart
Posts: 166
Joined: Sun Dec 30, 2018 6:40 pm
Gender: Male
Sexual Orientation: Straight
I am a: Switch

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by mantrid »

diglet wrote: Sat Dec 21, 2024 6:11 pm I explained that already. It is more efficient, has no phase shift, and relies on a board you can actually buy for cheap. As far as I'm aware of there is no commercially available current controlled amplifier board or IC that fits our use case.
Just use a normal (voltage controlled) amplifier with a large serial resistor (and no parallel one).

Disadvantages:
  • You loose power, typically about 10W
Advantages:
  • You can use audio infrastructure ==> portable software
  • Impedance is dominated by serial resistance ==> its easy to tailor other components like filters
diglet wrote: Sat Dec 21, 2024 6:11 pm Yes but also I don't really see what your point is. The outputs are isolated from the input, the transformers filter the low frequencies and inductors the high frequencies (about 5khz max for any meaningful nerve activation). What more do you need? Filtering frequencies doesn't really work anyway, there are valid reasons to want short bursts of 10khz waveforms intermixed with some 500hz components. Good luck designing a hardware filter for that with acceptable component count.
  • Voltage limitaton to avoid getting zapped when removing electrodes while volume has not been turned down: TVS diodes
  • Lower frequency limit for audio transformers is typically about 16 Hz. That's IMHO to low: High-pass filter using a capacitor
  • A (poly)fuse to protect the transformer (isolation brake)
You do not need to filter out high frequencies. (Unless you need to smooth PWM / chopping waveform from current regulation. But even that can be done with one or two passive components).
GAsm -- A guide assembler with EStim support to generate interactive teases that run in a browser.
ZeeWWW

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by ZeeWWW »

Would anyone be willing to post a step-step build of their FOC unit? It would be great if they could.

Thanks.
diglet
Explorer At Heart
Explorer At Heart
Posts: 390
Joined: Sun Dec 11, 2022 5:43 pm

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by diglet »

mantrid wrote: Sat Dec 21, 2024 6:55 pm Just use a normal (voltage controlled) amplifier with a large serial resistor (and no parallel one).
This sounds like a nice idea but it doesn't really work in practice.

A three phase setup with ~1000hz wavelets and 4 ohm series resistor requires a fairly low winding ratio (I use 10) to push the required current. I ran into some clipping problems with a winding ratio of 16 so I switched to 10. The low winding ratio is the opposite of what you want for constant-current.

If we want to use a higher series resistor and somewhat higher winding ratio for better current driving capabilities, I would need to use a 24v power supply, not good from a safety perspective. Skin resistance roughly halves when going from 20% to 100% of tolerable volume and depends on frequency, even with 10 ohm series resistors it's not really current controlled. And it doesn't get rid of the phase shift either.

I don't want to use audio. Restim + funscripts is the far superior way to create estim experiences.
mantrid wrote: Sat Dec 21, 2024 6:55 pm Voltage limitaton to avoid getting zapped when removing electrodes while volume has not been turned down: TVS diodes
That sounds unlikely to work. There is no place before the transformers where you can place the TVS diodes since the box needs all the available voltage headroom to drive the circuit at the higher frequencies. If you place the TVS diodes after the transformers, the rating will need to be quite high to support electrodes >500ohm. Such TVS diodes are unlikely to prevent zaps with low resistance electrodes.

Low output impedance design mostly prevents zaps when removing electrodes.

This is not safety critical, which means a software solution with response time 100µs is perfectly acceptable.
mantrid wrote: Sat Dec 21, 2024 6:55 pm Lower frequency limit for audio transformers is typically about 16 Hz. That's IMHO to low: High-pass filter using a capacitor
I will have to look into the frequency limits for the selected transformers.

The software is not going to magically generate frequencies below 500hz (the default limit) unless you tell it to. If the hardware/software experiences some fatal crash, a low pass filter is unlikely to do anything.

And again, safe waveform envelope highly depends on parameters not known at design time. 800hz is too low for my electrode setup (explained in other topic), your electrode setup might tolerate 200hz. Electrode resistance varies by an order of magnitude. I'm not saying software solves everything, but software at least gives you the option to say: you are delivering exactly this amount of charge, the waveforms you are using require an electrode area of at least 5cm^2.
mantrid wrote: Sat Dec 21, 2024 6:55 pm A (poly)fuse to protect the transformer (isolation brake)
Good idea.
mantrid wrote: Sat Dec 21, 2024 6:55 pm You do not need to filter out high frequencies. (Unless you need to smooth PWM / chopping waveform from current regulation. But even that can be done with one or two passive components).
When playing audio from an untrusted source, you absolutely do need to filter out high frequencies to prevent burns. FOC-Stim fixes this by not allowing you to to generate high duty cycle, high-frequency signals in the first place via protocol limitations.
darthjj
Explorer At Heart
Explorer At Heart
Posts: 134
Joined: Wed Jun 16, 2021 6:42 am

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by darthjj »

diglet wrote: Sun Dec 22, 2024 12:52 pm Restim + funscripts is the far superior way to create estim experiences.
For tri-phase, sure, but there's an occasional need for 2-channel experiences too :)
mantrid
Explorer At Heart
Explorer At Heart
Posts: 166
Joined: Sun Dec 30, 2018 6:40 pm
Gender: Male
Sexual Orientation: Straight
I am a: Switch

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by mantrid »

I was interested in this topic because your approach is technical interesting and has some potential. However, I see no benefits over properly tailored conventional design. (I made a spreadsheet (attached to this message) for this purpose many years ago. Even without that spreadsheet it is much easier to tailor a conventional design than correctly implementing current control using the motor driver dev-board.)

Suggestions to improve the design and solve problems caused by the dev-board (the shunts do not measure the phase currents directly...) were negated.

Instead of this, you tried to convince me, that my well working device is not real:
diglet wrote: Sun Dec 22, 2024 12:52 pm
mantrid wrote: Sat Dec 21, 2024 6:55 pm Just use a normal (voltage controlled) amplifier with a large serial resistor (and no parallel one).
This sounds like a nice idea but it doesn't really work in practice.
and that it is bad because it is not perfect (perfect current controlled drivers do not exist), while your implementation seems not even be capable to control the current directly:
diglet wrote: Sat Dec 21, 2024 6:11 pm The current sensors on this board are not good enough to do current control by peak/valley detection, I control it with an MRAC model.
(Current is controlled by some kind of a feedback loop, not a "peak/valley detection". The last busszword means, you have made simplifications -- not very informative.)

From this and statements like
diglet wrote: Sun Dec 22, 2024 12:52 pm Restim + funscripts is the far superior way to create estim experiences.
I conclude, that you are not interested in opposing opinions or improvements. That is why I'm stopping my participation in this discussion.

Just this final note: The reason for using current control is that it is predictable because it is independent of the output impedance. (This is only an advantage if one know what one does). The disadvantage of current control is that it can cause high current densities with bad electrode contacts.
GAsm -- A guide assembler with EStim support to generate interactive teases that run in a browser.
diglet
Explorer At Heart
Explorer At Heart
Posts: 390
Joined: Sun Dec 11, 2022 5:43 pm

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by diglet »

mantrid wrote: Mon Dec 23, 2024 10:09 am Instead of this, you tried to convince me, that my well working device is not real:
No, I didn't say your well working device is not real. I gave specific components which (I modeled just that morning following your recommendations) do not meet my requirements for a good-enough current control.

If you disagree, please give me a conventional design with peak output power 150mA, frequency range 500hz <= x <= 4000hz (known, varying), body resistance 50 ohm <= x <= 1000 ohm (unknown, varying) and an output current of, say, 1%. I would really prefer to be wrong on this one, but my math indicates the laws of thermodynamics are slightly problematic here. FOC-Stim is fairly close to meeting these requirements today.
UFungus
Explorer
Explorer
Posts: 42
Joined: Mon Jan 17, 2022 8:13 pm

Re: FOC-Stim: a new approach to DIY stim hardware.

Post by UFungus »

ZeeWWW wrote: Sun Dec 22, 2024 10:15 am Would anyone be willing to post a step-step build of their FOC unit? It would be great if they could.

Thanks.
I second that. This tech sounds absolutely fantastic. I understand that this might just not be intended to be built by someone like me and if so, carry on gents, but I honestly don't feel like the layman has enough information to work with given the risks involved with these kinds of devices. The BOMs I've seen are a little confusing and while diagrams mean everything to most people in this thread, I have no clue how to actually put one of these together only from looking at that or a few pictures of the finished product.
Post Reply