Embedded program not working for some values of simulation time steps from digital clock..?
Ältere Kommentare anzeigen
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
Antworten (1)
Azzi Abdelmalek
am 20 Jan. 2013
Bearbeitet: Azzi Abdelmalek
am 20 Jan. 2013
Maybe, there is a problem with the precision. Try to use a tolerence
tol=10^(-6);
if abs(T-q)<tol
13 Kommentare
V Vaishnavi Kumar
am 20 Jan. 2013
V Vaishnavi Kumar
am 20 Jan. 2013
Azzi Abdelmalek
am 20 Jan. 2013
No, I mean use
if abs(T-q)<tol
instead of
if T==q
V Vaishnavi Kumar
am 20 Jan. 2013
Bearbeitet: V Vaishnavi Kumar
am 20 Jan. 2013
Azzi Abdelmalek
am 20 Jan. 2013
Ok, maybe I did'nt understand your question, can you explain clearly what is the problem?
Azzi Abdelmalek
am 20 Jan. 2013
Ok, I see now, the problem is maybe your clock. are you working with a fixed or variable step time?
V Vaishnavi Kumar
am 20 Jan. 2013
Bearbeitet: V Vaishnavi Kumar
am 20 Jan. 2013
V Vaishnavi Kumar
am 20 Jan. 2013
Azzi Abdelmalek
am 20 Jan. 2013
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?
Azzi Abdelmalek
am 20 Jan. 2013
Bearbeitet: Azzi Abdelmalek
am 20 Jan. 2013
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
V Vaishnavi Kumar
am 20 Jan. 2013
Azzi Abdelmalek
am 20 Jan. 2013
Bearbeitet: Azzi Abdelmalek
am 20 Jan. 2013
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)
V Vaishnavi Kumar
am 20 Jan. 2013
Kategorien
Mehr zu Deployment, Integration, and Supported Hardware finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!