PID Controller Design for Ventilator (2023 Update)

I understand the basics of PID design, but if you can't describe the thing being controlled, how can you design the controller other than trial and er ror?

The "plant" is a motor on a tall reducing gear (~300:1) turning an arm that presses on a bag producing an air flow with the loop controlled by a press ure measurement.

One issue I'm seeing discussed is a tradeoff on the PWM resolution vs. freq uency. Presently they are using 3.6 kHz with 8 bit PWM control. I kinda w onder if a sigma-delta might be better, but that might require some externa l logic. They seem to be shy of pushing the CPU too much even after changi ng from an Arduino CPU at 20 MHz to an ARM CM4F at 80 MHz.

The big concern is the overshoot when ramping up the pressure between exhal e and inhale. In general, would it be better to simply jump the pressure s et point at once and let the PID controller do its thing, optimizing the re sponse time as best as possible controlling overshoot -or- would it be bett er to run up the pressure set point over a period of time which would seem to place less demand on the PID controller?

The model of the lung seems to include a spring constant (I think of this a s a capacitor) in parallel with a dissipative element (a dashpot or resisto r in electronics). The motor is highly geared to a relatively lightweight arm pushing on a bag with air passing through a tube of relatively low rest riction. So initially the dominate opposition to flow will be the dissipat ion/resistor, i.e. proportional to the rate of airflow. This in turn is pr oportional to the arm speed (although not constant through the stroke due t o the bag geometry). The arm speed is what is controlled by the PWM (appro ximately).

The lung model shows the dashpot and spring in parallel, but I'm not sure t hat's appropriate. The response to air entering the lung will be the sum o f the airway resistance (dashpot) and the lung compliance (spring) which wo uld be a series combination to obtain the resulting air pressure. Well, ma ybe that is right for the mechanical model, but in the electrical equivalen t if pressure is the same as voltage it would be a series arrangement.

Anyway, the lung would seem to be a capacitor and a resistor. So if driven by a P only controller, is there any way it could ring? I was shown data measured that showed huge ringing from an initial step function in the set point.

I watched some videos and it seems they use both pressure regulated and flo w regulated cycles. I expect to see similar results with either method.

Interesting

--

  Rick C. 

  - Get 1,000 miles of free Supercharging 
  - Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C
Loading thread data ...

This graphical programming environment for Arduino has PID modules, and you can use it tweak the PID parameters in the GUI (or any parameters, actually) in real-time via the debugging interface while the code runs on the actual chip. No special interface required just USB cable

Reply to
bitrex

as I understand it in supportive ventilation the pressure application is triggered by patient breathing in, the pressure ramps up slowly to max while sensing the back-pressure from the lung, then the flow rate ramps down from peak in proportion to back-pressure as it starts rapidly increasing near the end of the cycle. there's a trade off between slow rise times and not hitting the required overall tidal volume, and fast rise times which are uncomfortable for the patient!

There are different control schemes; like time-cycled and volume cycled, in time-cycled the total inspiration time is set and the mass flow rate during the "flat" part of the curve is dynamically adjusted to deliver the required volume, and volume cycled, where the peak mass flow rate is fixed and the inspiration time varies.

I don't think I would be "jumping" anything, the output pressure is not a static value in either of the schemes AFAICT, always a dynamic function of the back-pressure. the peak flow rate is related to peak pressure but I don't think outlet pressure is the primary variable

Simple mechanical model of a lung is just like you'd expect - an elastic bellows. Or a vertical dashpot, like a spirometer, with elastics that increase its resistance as the dashpot rises in the tube.

The earliest hydraulic/mechanical ventilators were P-control only I think but the servos and valves had mechanical inertia the "loop gain" was intrinsically limited at high frequency. Can a P-only controller ring? Sure, any negative-feedback system with a phase lag in the loop and enough gain as the lag approaches 180 degrees can ring, you know dat

.
Reply to
bitrex

That is to say if the back-pressure starts increasing _for any reason_ you have to start dropping the outlet pressure proportionally you can't just set it and forget it!

Reply to
bitrex

ing being controlled, how can you design the controller other than trial an d error?

that presses on a bag producing an air flow with the loop controlled by a p ressure measurement.

frequency. Presently they are using 3.6 kHz with 8 bit PWM control. I kin da wonder if a sigma-delta might be better, but that might require some ext ernal logic. They seem to be shy of pushing the CPU too much even after ch anging from an Arduino CPU at 20 MHz to an ARM CM4F at 80 MHz.

xhale and inhale. In general, would it be better to simply jump the pressu re set point at once and let the PID controller do its thing, optimizing th e response time as best as possible controlling overshoot -or- would it be better to run up the pressure set point over a period of time which would s eem to place less demand on the PID controller?

I had not looked at the problem until today, but I'm being told the pressur e should rise within 100 ms of sensing the patient breathing. I believe th is is a comfort thing where they don't want to feel they are unable to brea th.

I watched a video earlier tonight indicating when the patient starts the br eath the machine then essentially forces the breath either by controlling t he pressure as a constant for a set amount of time or by controlling the fl ow rate as a constant until a volume is reached. Both methods have advanta ges and disadvantages. I don't see where they distinguish between patient triggered and machine triggered.

This guy Allan Gonzales is terrible to listen to, but he does keep them sh ort.

formatting link

He shows the only difference between patient triggered and machine triggere d waveforms is the negative pressure from the patient trying to draw air in at the very start of the cycle. His diagrams are pretty poor with no regi stration between the various points on different parameters, but he gets ac ross the main points. You can do a Google search to find other much better diagrams. I don't think there are any new concepts to an engineer.

formatting link

Yup...

Not sure why you say that. What you call "timed" is constant pressure. Th ere is no intended modulation of the pressure... hence "constant". In orde r to use a fixed time the not fixed flow rate has to be well known for a gi ven pressure. If the pressure varies at all it messes this up.

The machine is also measuring the volume by integrating the flow rate. So I don't know why anyone would feel the need to work to a "fixed" inspiratio n time. If there is some variation in lung compliance there could be signi ficant variations in the flow rate and volume. This diagram shows that ver y clearly.

formatting link

I wonder if there are reasons why they do things the way they do or if it i s just "this is what we all do" so they keep doing it that way?

is as a capacitor) in parallel with a dissipative element (a dashpot or res istor in electronics). The motor is highly geared to a relatively lightwei ght arm pushing on a bag with air passing through a tube of relatively low restriction. So initially the dominate opposition to flow will be the diss ipation/resistor, i.e. proportional to the rate of airflow. This in turn i s proportional to the arm speed (although not constant through the stroke d ue to the bag geometry). The arm speed is what is controlled by the PWM (a pproximately).

Yes, that's what I said I believe, dissipation and spring. Mechanically th ey are in parallel, or in an electrical analogy it is a resistor and capaci tor in parallel with voltage representing pressure and current as flow, the charge on the cap as volume.

re that's appropriate. The response to air entering the lung will be the s um of the airway resistance (dashpot) and the lung compliance (spring) whic h would be a series combination to obtain the resulting air pressure. Well , maybe that is right for the mechanical model, but in the electrical equiv alent if pressure is the same as voltage it would be a series arrangement.

iven by a P only controller, is there any way it could ring? I was shown d ata measured that showed huge ringing from an initial step function in the set point.

Where would the lag come from in this system? That's my point. I'm pretty sure I could do a few calculations and produce a table of values that take into account the variable motor speed to air flow relation of the bag and another that models the lung resulting in a very simple controller that nee ds no PID terms.

I'm just not seeing any complications in controlling this device. I have n o idea how they made it ring. Worse they said they read texts on PID contr ollers that said P only will ring with a high coefficent. If the P only ri ngs, it's going to go nuts when you add the I term.

When I hand tweak PID controllers I typically start with a large P term and add in I until it starts to act wonky, then play with them a bit until I g et minimum overshoot with good response. This has always been fairly simpl e devices being controlled.

If you had an RC series circuit on the output of a PID controller, do you t hink you could make that ring? Maybe the motor and bag are more complex th an I realize or the connecting tubing is more complicated than I think. I believe the tubing is around 10% the volume as the bag. Still, it shouldn' t be a big deal it seems. Even if the compliance of the various spaces act like coupled capacitors, the time constants are going to be *very* short.

Not my problem at the moment. We'll see what happens.

--

  Rick C. 

  -- Get 1,000 miles of free Supercharging 
  -- Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

ol.

CPU

the

s

,

s

Not sure what you mean by outlet pressure and back-pressure. What is your model like?

--

  Rick C. 

  -+ Get 1,000 miles of free Supercharging 
  -+ Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

There's some force per unit area of the air coming out of the tube into the lungs, and as air fills the lungs there's some back-pressure resisting that force from the weight of the atmosphere pushing down on the lungs. Like when you blow into a balloon.

The early hydro-mechanical ventilators were back-pressure regulated; when back-pressure reaches a set point the exhale cycle is triggered.

Reply to
bitrex

rm

s.

trol.

e CPU

n

mp the

ot

od

is

x

ps

w
t

ed,

te

r

is

ot

t

our model like?

You reasoning still isn't clear to me. Everything has pressure from the at mosphere. That's why pressure in most cases is relative, not absolute. So that's simply not an issue. The balloon is elastic, that's why they requi re pressure to inflate. Inflating a paper bag is against air pressure only .

What you are calling "back-pressure" is the combination of the dissipative effect (mostly moving air through the various forking passages I expect) an d the compliance of the lungs (the elastic effect which actually does push back but without a lag). That is the pressure the vent has to assert to ge t air into the lungs, proportional to A*I + B*dI/dt which is what I've been describing all along.

That might be a flow regulated unit. The flow is constant, so the pressure increases from the elastic effect until the volume is achieved and the exh ale begins.

--

  Rick C. 

  +- Get 1,000 miles of free Supercharging 
  +- Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

Right. brain fart! the forces are balanced if the "balloon" isn't expanding or contracting.

Reply to
bitrex

Yeah, don't see what else it could be I guess when it's entirely powered by the air supply.

If the PID is controlling pressure tho and what you're actually measuring is pressure differential the thought occurred to me, if you just set it to what the pressure is supposed to be during the main portion of the inhale to get the volume and let the PID "do its thing" what happens if for some reason the patient starts actively pushing back while it's ramping up does the PID read this as "pressure too low" and start trying to force it in harder? and then they stop and it can overshoot? I mean I guess they'd be sedated so that might be unlikely

Reply to
bitrex

It sounds to me like for pressure-control there has to be a well-defined time where the pressure is ramped up while ensuring the volume of air in the patient's lungs is increasing linearly (or however it's supposed to do), however you do that, and then when the pressure set point is reached which will deliver the needed volume if it's kept there for the rest of the cycle the PID kicks in to hold it there by squeezing harder on the source-bag while it empties

If I'm understanding your setup correctly

Reply to
bitrex

Er, reverse that, I think you said it squeezes less hard as you approach the end of the stroke to keep pressure constant.

Reply to
bitrex

On a sunny day (Sat, 15 Aug 2020 22:46:45 -0700 (PDT)) it happened Ricketty C wrote in :

No experience with these things but from _my_ life I know breathing is related to oxygen level in the blood. For example, when I try biking very fast I need deeper and more often breathing than when I am pressing buttons on a mouse or keyboard and sitting still. In the 'overall loop' one should measure oxygen level in the blood and based on that pump more or less air, there is where your loop is. Compare it to those funny thermostats mounted outside that control the heating inside I have seen those, never the correct temperature inside... Measure where you want it controlled, not somewhere else. I would not want to be on a machine that without the oxygen level feedback was just pumping me, could be vary dangerous. Very important with people with covid-19 related changing lung damage.

Reply to
Jan Panteltje

he

an

arm

ed

vs.

ontrol.

the CPU

RM

een

jump the

,

hoot

riod

r?

on is

max

amps

low

ast

cled,

rate

ver

te is

not

k

n_

n't

your model like?

o

e atmosphere. That's why pressure in most cases is relative, not absolute. So that's simply not an issue. The balloon is elastic, that's why they r equire pressure to inflate. Inflating a paper bag is against air pressure only.

ive effect (mostly moving air through the various forking passages I expect ) and the compliance of the lungs (the elastic effect which actually does p ush back but without a lag). That is the pressure the vent has to assert t o get air into the lungs, proportional to A*I + B*dI/dt which is what I've been describing all along.

sure increases from the elastic effect until the volume is achieved and the exhale begins.

The difference is what is controlled. There's no reason why the pressure c ould not be controlled and then timed or still work off the volume. In fac t, it seems to me the flow rate controlled system *could* be timed to get a n accurate volume while the pressure controlled system will produce a varia ble volume depending on the patient parameters. There's still a lot missin g.

You just said the pressure is controlled. So it won't "push back harder". That would be the flow controlled system in which the pressure will vary a ccording to the patient parameters - spring and dashpot and of course if he is awake, breathing back against the machine. "Assist" means the patient is awake. This is the mode the "amateur" systems seldom tackle, so we are adding that.

Sometimes I just want to hit my head on the floor. The guy adds a very dem anding mode after much of the design is supposedly done and still wants to push for getting it done quickly because people are getting tired of workin g on this.

This sort of inconsistency is rife in this project. I wanted to get rid of the ten cent thermistor (that's about 1 and 6 old currency) for a linear d evice that cost a dime. People were complaining about the cost. Mean whil e we have $100 in sheet metal, a $30 motor and gear train, three $20 pressu re sensors and a $30 O2 sensor! They don't want me to use parts that do a better job if they aren't in inventory in the ten thousands, but the pressu re sensors are hardly stocked anywhere.

Now we are trying to pick a new motor and the one they picked can trash the gears if run against a stop. The currents at the max peak rating and the max continuous rating are so close that the inaccuracies in the current sen sor in the motor controller are larger.

So many things would have been worked out had we done a proper requirements analysis. The first two sets of boards are not functional enough to verif y circuits work like the battery charger (I think the input voltage is too low to fully charge the battery as the charging chip is designed - Vboost i s 14.6, Vin is nominally 15V but there's tolerance - not to mention drop ou t voltage!). Still, they are rushing to get the next rev of the board done .

The last couple weeks I've been wanting to walk away, but I'd like to get t hrough a design review on the board. I asked to add hysteresis to the alar m comparators (fully hardware, no software) and provided an LTspice schemat ic which had been verified in simulation. The schematic has negative feedb ack instead of positive.

I know, I know, I'm whining at this point. Thanks for listening.

--

  Rick C. 

  ++ Get 1,000 miles of free Supercharging 
  ++ Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

ty C

ered

n

gistration

ood.

not really, your breathing is mostly related to the amount of CO2 in your l ungs that's why breathing something like pure nitrogen will kill you without you even noticing

Reply to
Lasse Langwadt Christensen

the

han

led

control.

the CPU

ARM

jump

g,

er?

ak

on_

hat

to

n

rom

ot

astic,

ag is

e
d

k

That sounds right but not "harder". The vent bag does not have much "sprin g" to it, just enough to reinflate it. In fact, because of the geometry, c ontact with the bag is over a smaller area at first and as that area expand s during the stroke the area of the "piston" effectively increases. We are using about half the volume of the bag, so will need to press on it about three quarters of a stroke I estimate.

So if the arm moves at a constant rotation the graph of flow rate vs positi on will be roughly a triangle.

--

  Rick C. 

  --- Get 1,000 miles of free Supercharging 
  --- Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

ty C

ered

n

gistration

ood.

athing

ating inside

k was just pumping

Your post is very confusing.

If the heat comes on so hard it sets the house on fire, maybe you should ha ve a controller that prevents that even if the bedroom is not quite warm en ough.

The vent is concerned with getting air into the lungs without causing damag e to the lungs. Setting the volume goals of the machine is up to the opera tor who is monitoring the patient's O2 levels.

If there is a problem with getting the O2 from the air in your lungs into y our blood stream, perhaps you would not want a person monitoring the machin e and just allow it to inflate your chest like a balloon causing embolisms and death. The machine controls aspects that are appropriate for the machi ne to control. More complex factors are controlled by a trained human.

I appreciate that you have designed many control systems and I value your i nput. But you don't understand the problem fully.

--

  Rick C. 

  --+ Get 1,000 miles of free Supercharging 
  --+ Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

I wonder how many old ladies ricky's team plans to kill, trying to learn PIDs and stuff.

--

John Larkin         Highland Technology, Inc 

Science teaches us to doubt. 

  Claude Bernard
Reply to
jlarkin

ketty C

iggered

r in

registration

s
r

blood.

r lungs

you

Perhaps you will be the first little old lady? Care to volunteer?

I love the fact that Larkin tells others to ignore me but can't resist read ing and responding negatively himself!

Yeah, that's a great community spirit. I'm glad Larkin is pulling for us a ll. At least he isn't making a personal attack like he criticizes others f or... no, wait, he is!

I would ask your opinion, but you have made it very, very clear that you do n't actually understand the math of controllers, you just whip up a simulat ion and you are off to the races.

I may well do that myself, but only after understanding the lung/air way mo del well enough to be sure the simulation is modeling something useful.

--

  Rick C. 

  -+- Get 1,000 miles of free Supercharging 
  -+- Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

ptechnology.com:

ketty C

iggered

r in

registration

s
r

blood.

r lungs

you

I very much doubt they'll be allowed to hook anything living up to a ventil ator hacked together by amateurs, no matter how well-meaning they are

seems like an exercise in feeling like they are "doing something"

Reply to
Lasse Langwadt Christensen

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.