Matlab closed loop Autotuner PID with embedded coder

6 visualizzazioni (ultimi 30 giorni)
V
V il 29 Mar 2020
Risposto: V il 31 Mar 2020
Hi,
I want to generate C code using Embedded Coder for autotune PID. Using matlab 2019b.
1. Microcontroller used: Rx23T with FPU enabled, so can using single precision floats.
2. Need to autotune of PID for oven application. Have a sensor to read temperature values every 100ms.
3. So inputs have:
a) Reference temperature: float32_t , temperature need to set
b) Current temperature: float32_t, current temperature of oven
4. Outputs need:
a) Autotune PID values
b) 0-65535 value for PWM duty cycle, this will be feed via MCU to a Solid state relay which will control on/off of heater.
5. No plant model/transfer function available, only input mentioned available
6. I hwas trying to make simulink slx file. Attached is snapshot. Some confusion i have is:
a) u+du : How it will be used here?
b) I my application closed loop or open loop autotuner suits?
c) %conv : When 100% will it tell that autotuning completes? What is there is some error? Is there any error also?
d) PID gains: Need to feed back autotune PID games to "Discrete PID controller" block, how to do that?
e) How to get output PWM value from this 0-65535?
7. Is my approach ok? or something wrong?

Risposte (2)

Arkadiy Turevskiy
Arkadiy Turevskiy il 30 Mar 2020
Modificato: Arkadiy Turevskiy il 30 Mar 2020
Hi Vindhyachal,
Here are answers to your questions:
1. u+du : How it will be used here?
Have you seen this doc page? It explains the setup. Basically, u+delta u will be the input to the plant, so in your case it will be a PWM value.
2. I my application closed loop or open loop autotuner suits?
I would recommend using closed-loop PID autotuner. It is safer, it keeps plant under closed-loop control during autotuning
3) %conv : When 100% will it tell that autotuning completes? What is there is some error? Is there any error also?
Yes, when that value is close to 100%, that means PID Autotuner has finished estimating plant dynamics, and pid gains can be computed
4) PID gains: Need to feed back autotune PID games to "Discrete PID controller" block, how to do that?
You can feed them back to PID Controller block, or save them to memory. The documentation explains this. Please see hereand hereand here.
5) How to get output PWM value from this 0-65535?
The question for you would be: how do you get PWM value when you are not doing autotuning, but just controlling your plant with a PID controller. You probably have some logic in your code/model that takes output of PID controller and converts it to a signal that goes to PWM with the right range. You would use the same logic when you are doing PID autotuning. PID Autotuner adds a small signal (delta u) on top of an output of a PID controller.
6) . Is my approach ok? or something wrong?
Nothing really wrong with your approach. Something to be aware of is that PID Autotuner can take quite a bit of computational resources on the processor, so you will need to see if you encounter an overrun when you generate code and try to deploy it to your processor.
Arkadiy

V
V il 31 Mar 2020
Hi Arkadiy,
Thanks for replying. I have updated as attached.
  1. Took reference from here:
https://in.mathworks.com/help/slcontrol/ug/tune-pid-controller-in-real-time-using-closed-loop-pid-autotuner-block.html , here PID outout is limited to 0 to 1, which is then used to get duty cycle. If this is ok, then can multiply this number by 65535 to get timer values.
2. When I made this, there is ZOH appears on add/subtract block, why it appears?
3. In PID block, N input is still not clear to me,can you please point to some help/app note on this?
4. Have made all inputs:
a) ref_temperature, current_temperature : single float
b) start_stop : uint8_t
c) all outputs are also single float
since mCU have FPU in it.
5. Am i going in right direction? or any better method to do that

Prodotti


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by