Embedded Matlab function for Microcontroller modelling with PWM

Hello!
I am modelling a solar tracking system in simulink, and i want to include an embedded matlab function with 'if' statements to represent a microcontroller. The inputs will be 2 values of voltage representing the LDR values, and within the matlab function i will compare the input values and create an output which will commmand a motor to rotate clockwise or counterclockwise. I have built the motor model in simulink, which will recieve an input voltage(coming from the microcontroller) and will output an angle of rotation. My question is what should be the output of the microcontroller? I think maybe the microcontroller could output a duty cycle of a PWM which will correspond to a voltage(maybe use a look up table) but i am not sure. I also want to include a PI controller but i am not sure were should be connected and what the error input should be. I want to model this operation as simple as possible because i am a beginner at electronics, and also the simulation time is very long,(10*3600s) so a complex system will make my simulation slow. Any response will be very helpful.
Thank you

댓글 수: 8

*just to add that the aim of the microcontroller function is to move the motor until the diference between the two LDR voltage values becomes zero every time.
Hi Eleni.T,
The correct answer to this question really depends on your final design. What paramters are being controlled and what topology is driving the motor? (Type of the motor and Drive. Parameters: Position/Speed of the motor. Control algorithm: Speed Control/Torque and Direction Control, Current Limiting Circuit). If a general answer helps, then assume that you wanna control a dc motor position:
If you wanna increase the model accuracy and get closer to the real problem then:
The real world problem needs a very accurate system with more complexity.
You may find the "Using the Worm and Gear Constraint Block - Solar Tracker" Simulink Model helpful.
Best
Mohsen
Hello Mohsen,
Thank you very much for your response!
My design includes DC motors. The transfer function you wrote for Wr(s)/d(s) is very useful. Is it correct to convert it [W(s)=s*Θ(s)] so that i get the transfer function between the angle theta Θ and the duty cycle: Θ(s)/d(s)=[previous plant]/s ? Then i can input the angle path of the sun as the reference input and control the position of the motor. I would like to ask if there is a difference between the Va in the first picture with the Vs in the second? Is the Vs the constant dc supply voltage, and the Va the actual voltage needed for the motor? or is it the same thing? I am a bit confused about electric circuits.
However, in the case i do not know the reference position or the reference speed, and the only info i have is the 2 voltage values of the light sensors, and i want to rotate the motors until the difference between the two values becomes zero, what would be a possible solution?
Thank you for your time
**i got that Vs=Va*d
So if i want to calculate the power consumption of the motor that is P=Va*Ia OR Vs*Ia ?
Thank you again
Yes, your first assumption about the speed and position is correct, and you can move forward with that.
The second question, they are diffrent, Va is armature voltage and Vs is the dc voltage source connected to the input of the dc/dc converter: Va=d.Vs and is=d.Va, basically for the ideal cnverter with no lose P=Va.Ia or P=Vs.Is.
About the last question, I don't know what exactly we are talking about, these two voltages I mean. If (IF) one of them is a reference voltage and the other one is a measured voltage coming from a sensor, then yes we can create the position reference from their error:
However, if you get two measured voltages and by changing the position you can minimize (or make zero) the difference between these voltages, then you can use a method smilar to Perturb and Observe:
I have no past experience in this particular subject (2 voltage values of the light sensors), but I'm trying to give you some ideas.
Hope these solutions resolve your issue.
Good Luck
Mohsen
DeltaV=V2-V1;
also in the * DeltaTheta calculator, you could say (elseif DeltaV(k)=DeltaV(k-1) then DeltaTheta=0).
Thank you so much for the response, you 've been very helpful!
Yes my case is the last one you mentioned, and a Perturb&Observe algorithm would be a good solution i guess! As I have found in literature, the light sensors are represented with the following diagram (4 sensors for north-south,east-west sensing).
But as i dont know much about electronics in order to choose values for all the resistors etc, I think the perturb&observe algorithm will have the same results so i will try it! I have the two voltage values calculated as shown below and from that point i will continue with the P&O. If i am not mistaken it isalso cheaper to implement compared to the above circuit.
Thank you for the ideas.
I am happy I could help.
Good Luck.

댓글을 달려면 로그인하십시오.

 채택된 답변

Mohsen Aleenejad
Mohsen Aleenejad 2020년 7월 30일

0 개 추천

Hi Eleni.T,
The correct answer to this question really depends on your final design. What paramters are being controlled and what topology is driving the motor? (Type of the motor and Drive. Parameters: Position/Speed of the motor. Control algorithm: Speed Control/Torque and Direction Control, Current Limiting Circuit). If a general answer helps, then assume that you wanna control a dc motor position:
If you wanna increase the model accuracy and get closer to the real problem then:
The real world problem needs a very accurate system with more complexity.

추가 답변 (0개)

커뮤니티

더 많은 답변 보기:  Power Electronics Community

질문:

2020년 6월 25일

답변:

2020년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by