How to write code for flowchart

3 visualizzazioni (ultimi 30 giorni)
Mahesh Abdare
Mahesh Abdare il 22 Mag 2022
Commentato: Walter Roberson il 28 Mag 2022
I am unable to write the code for the following flowchart. The voltage need to me sampled for 40 micro second
  4 Commenti
Mohamad Nazir
Mohamad Nazir il 23 Mag 2022
Modificato: Walter Roberson il 23 Mag 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 il 23 Mag 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.

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 23 Mag 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 Commenti
Walter Roberson
Walter Roberson il 28 Mag 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.

Accedi per commentare.


shivakumar pambala
shivakumar pambala il 24 Mag 2022
Are u writing it for any specific embedded board?
  2 Commenti
Walter Roberson
Walter Roberson il 24 Mag 2022
They said that they want to simulate without hardware.

Accedi per commentare.

Community

Più risposte nel  Power Electronics Control

Categorie

Scopri di più su Polar Plots in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by