How to write code for flowchart

I am unable to write the code for the following flowchart. The voltage need to me sampled for 40 micro second

4 comentarios

Walter Roberson
Walter Roberson el 22 de Mayo de 2022
What ADC hardware are you planning to use for this, and how do you plan to interface to it?
Mahesh Abdare
Mahesh Abdare el 22 de Mayo de 2022
I just want to simulate without hardware
Mohamad Nazir
Mohamad Nazir el 23 de Mayo de 2022
Editada: Walter Roberson el 23 de Mayo de 2022
A timer object can be used in this case to schedule the sampling with the desired frequency.
You can check out the documentation about timer object in the following link: https://www.mathworks.com/help/matlab//ref/timer.html
Walter Roberson
Walter Roberson el 23 de Mayo de 2022
You cannot use a timer for this purpose. The minimum period for a timer() object is 0.001 which is 25 times too slow for an event that occurs every 40 microseconds.
You could investigate using Stateflow; I do not know how quickly Stateflow can run.

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 23 de Mayo de 2022
period = 40e-6;
for REPEATS = 1 : 500
%box 1, 40 microsecond interrupt
last_event_time = tic;
while toc(last_event_time) < period; end %busy loop
%box 2, read input voltage
Input_Voltage = randn() * 20;
%box 3, assignments
Array_vin(sample_count) = Input_Voltage;
Alpha = Input_Voltage;
%box 4, increment
sample_count = sample_count + 1;
%box 5, test
if input_voltage >= 0 && input_voltage_previous <= 0 && sample_count > 300
%box 6, "Yes" block
Period = sample_count;
sample_count = 0;
end
%box 7, "no" box, is executed for "Yes" as well.
input_voltage_previous = input_voltage;
%and so on
end
You will find that in practice the timer could be more than 50 times too slow, but with this tic/toc approach the interval can be fast enough. You cannot use pause() for this purpose, as pause() does not accurately simulate event timing, and in practice the minimum pause is about 3 times too slow for your purposes.
You will find that in practice the array indexing is wrong. MATLAB array indices start from 1.
You will find that in practice you need to have initialized some variables that are not initialized in the flow chart.
But you did not ask for repaired logic, you asked for this flow chart to be implemented.

2 comentarios

Mahesh Abdare
Mahesh Abdare el 28 de Mayo de 2022
Showing This error
Walter Roberson
Walter Roberson el 28 de Mayo de 2022
Yes, that is a correct implementation of that aspect of the flow chart. The flowchart does not initialize sample_count, so it would have been incorrect for me to have initialized it. The flowchart has bugs, so any accurate implementation must replicate the bugs.

Iniciar sesión para comentar.

shivakumar pambala
shivakumar pambala el 24 de Mayo de 2022

0 votos

Are u writing it for any specific embedded board?

2 comentarios

Walter Roberson
Walter Roberson el 24 de Mayo de 2022
They said that they want to simulate without hardware.
shivakumar pambala
shivakumar pambala el 24 de Mayo de 2022
Ok

Iniciar sesión para comentar.

Comunidades de usuarios

Más respuestas en  Power Electronics Control

Categorías

Más información sobre Polar Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Preguntada:

el 22 de Mayo de 2022

Comentada:

el 28 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by