Embedded program not working for some values of simulation time steps from digital clock..?

A digital clock connected to embedded program and its output connected to display.
sample time of digital clock 0.1 sec.
The embedded prog is
function u =check(T)
persistent g j
if isempty(g)
g=0.3
end
if isempty(j)
j=0
end
T %to display the values from digital clock in command window
if T==g
g %to display the value
j=123
end
u=j
g can be intialised with any values 0.1,0.2.....1
When T takes 0.3 it should execute j=123.. but its not doing so, similarly when g is initialsed with 0.3 or 0.6 or 0.7 its not working..but working well with 0.4, 0.5,0.9..
the simulation time kept is 1 sec

回答(1 个)

Maybe, there is a problem with the precision. Try to use a tolerence
tol=10^(-6);
if abs(T-q)<tol

13 个评论

I changed the tolerance, relative and then absolute... tried with fixed step solver with reduced step sizes.. no change for that particular value sir
I don understan sir.....
whether both the statements equivalent..
when the simulation step reaches that particular value i need to execute some statements.. lik realtime...I m thinking to run a larger program with power electronics model... in that program i want to run a set a statements only for particular no of times instead of running it at each step
so i m testing the logic with this simple embedded program and wanna use this in tat one
Ok, maybe I did'nt understand your question, can you explain clearly what is the problem?
Ok, I see now, the problem is maybe your clock. are you working with a fixed or variable step time?
the embedded program acts as controller and senses the solar panel voltage and current, at the same time it controls power electronic converter.. the converter switching frequency is about 1 kHz. so i m setting a initial step time of 0.001/10 sec(0.1 msec) in Variable step solver. So the whole simulink model runs each step time including my controller... this s undesirabl...the program should run with a time gap of approximately 6 ms so that it would work properly.....
So i thought when digital clock time equals a variable which acts as a counter with 6 msec gap, this controller should run...
first used variable only... then tried with fixed too...in fixed kept fundamental sample time as 0.1., and tried another time with o.oo1.
What do you mean by: I m setting a initial step time of 0.001/10 sec(0.1 msec) in Variable step solver. How can you set a step time in Variable step solver?
If you are using a variable step, it's not sure the time t will be equal to 0.3, try to sent the time to workspace and check if t=0.3
oh k...what about fixed solver.. any parameters need to adjusted in that...
I thought to set initial step size in solver dialog box of configuration parameters...i m not sure whether this step size would be constant... If not i would use fixed step and set fundamental sample time...
If you are working with discrete system, in solver option, change the type from variable step to fixed step and set it to the lowest value of your blocks sample time, for example 0.001.(by default it's auto)

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by