Matlab - Problema con Timer

 
Vista:
sin imagen de perfil

Problema con Timer

Publicado por TimerFcn (18 intervenciones) el 17/02/2016 22:23:30
Hola muy buenas estoy usando un Timer para adquirir datos desde Arduino el problema que tengo es que una vez que se pone en marcha el Timer y una vez esta termina los datos adquiridos y guardados en la función Untitled6 se borran o no se guardan aquì os dejo el código.

Lo que hago es que se repita Untitled6 durante 100 veces y así adquiro 100 muestras, lo que serían 50 satos de la temperatura y 50 de la humedad.
Este es la función Timer:
1
2
3
t = timer('TimerFcn',@Untitled6,'TasksToExecute',100,'ExecutionMode','FixedRate','Period',5);
 
start(t)

Y este es la función Untitled6:
Podría adquirir mas datos es decir mas de 2 muestras.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function Untitled6(obj,event)
clc;
clear all;
delete(instrfind({'Port'},{'COM7'}));
s1=serial('COM7','BaudRate',9600)
fopen(s1)
%%
  muestras=2;
  temperatura=[];
  humedad=[];
  y=[];
 global time;
% %  global a;
% %  global b;
 global tt;
 global th;
%%  
  A=[5,7,9,7];
  B=kron(A,ones(1,muestras/4));
  i=1;
  tic
while i<=length(B)
 
         fprintf(s1,'%d',B(i));
         y(i) =fscanf(s1,'%d');
       pause (0.5)
       i=i+1;
    time(i)=toc;
end
fclose(s1);
%%
temperatura(1)= y(1)/100;
humedad(1)=y(2)/100;
tt(1)= time(1);
th(1)= time(2);
for i=3:length(y)
        if mod(i,2)~=0
        temperatura = [temperatura y(i)/100];
        tt= [tt time(i)];
    else if mod(i,2)==0
       humedad= [humedad y(i)/100];
       th= [th time(i)];
        end
    end
end
% % a=tt(2:muestras/2)-tt(1:(muestras/2)-1);
% % b=th(2:muestras/2)-tt(1:(muestras/2)-1);
delete(instrfind({'Port'},{'COM7'}))

Muchas Gracias de antemano.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder