Closed Transfer Switch Function

조회 수: 1 (최근 30일)
Alasdair Robertson
Alasdair Robertson 2017년 10월 17일
댓글: Prashant Arora 2017년 10월 20일
I am trying to programme a simple function to mimic the response of a Closed Automatic Transfer Switch. The reason I’m doing this in a function is because I can’t find appropriate Simulink blocks in order to imitate the functionality.
Basically, I have two inputs, u1 & u2 and two outputs, y1 & y2. If the input u1 is at a value higher than 20, I want the input u2 to flow out of y2. As well as this, I want u1 to still flow out of y1 for 100ms simultaneously, before shutting and becoming 0. This mimics the cross over time in a closed transfer switch where both power supplies are connected in parallel for 100ms or less. Again, I want a similar feature to occur when the input u1 becomes less than 20, but the other way round.
The errors are coming from my “while” function, where I am trying to get the output to stay at a value for 100ms before switching to 0 as I can get the simple switching between two outputs depending on the input function fine.
I've attached the model as well as the function code below. Any help or guidance in anyway is much appreciated.
Ali.
function [y1, y2] = OTS(u1, u2)
coder.extrinsic('clock')
if abs(u1) > 20
y2=u2;
t0=clock;
while etime(clock, t0) < 0.1
y1=u1;
end
y1=0;
else
y1=u1;
t0=clock;
while etime(clock, t0) < 0.1
y2=u2;
end
y2=0;
end

답변 (1개)

Prashant Arora
Prashant Arora 2017년 10월 19일
Hi Alasdair,
This error originates because the following command returns a mxArray instead of double. You should pass it's output to a double variable before using it.
etime(clock,t0)
To resolve the error, you should modify the while loop as shown below:
while trigger
tElapsed = 0; % Initialize tElapsed to take double values
tElapsed = etime(clock, t0); %Pass a mxArray to cast it to double first
if tElapsed < 0.1
trigger = true;
y2 = u2;
else
trigger = false;
end
end
That said, I don't believe this MATLAB Function block will behave as you intended it to be. Essentially the while loop will terminate after 100 ms (not simulation time) and then the output y1 or y2 will be assigned to zero depending on value abs(u1). See the screenshot below:
Perhaps, consider passing time from Simulink to the MATLAB Function block and check it's value in a conditional statement, rather than using a while loop.
Hope this helps!
Prashant
  댓글 수: 7
Alasdair Robertson
Alasdair Robertson 2017년 10월 20일
Sorry again, just one more thing I've noticed. Why are you setting "aboveThreshold" from True to False in both cases? Which leads me on to question when will "aboveThreshold" be true?
Or is it just the way you've written it? So you're setting "aboveThreshold" from False to True by;
aboveThreshold = ~aboveThreshold;
if you understand my question? Does that make sense?
Prashant Arora
Prashant Arora 2017년 10월 20일
~aboveThreshold returns false when aboveThreshold is true and vice-versa. So it switches from false to True when signal reaches beyond threshold. and switches from True to false when signal is lower than threshold, because of the if statement conditions. It makes no difference if you change aboveThreshold = true and aboveThreshold = false in first and second assignment respectively.

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

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by