Matlab closed loop Autotuner PID with embedded coder
3 views (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
Arkadiy Turevskiy
on 30 Mar 2020
Edited: Arkadiy Turevskiy
on 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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!