Documente Academic
Documente Profesional
Documente Cultură
1.
Introducci
on
2.
La velocidad y resolucion de las mediciones son limitadas por las caractersticas del ADC embebido en la tarjeta de adquisicion de datos, en este
caso la tarjeta Arduino UNO. Las principales caractersticas del convertidor
analogico-digital se muestran en la Tabla 1.
1
3.
Configuraci
on del sistema
dispositivos a muy alta frecuencia (cientos de kHz). En la Tabla 2 se el funcionamiento general del Script de MATLAB. De manera similar en la Tabla
3 se presenta la descripcion del algoritmo implementado en el Arduino.
4.
5.
Conclusiones
Apendice A
Script de MatLab
numero muestras=input ( n
u mero de muestras : ) ;
ales : )
s i g n a l s=input ( n
u mero de s e n
p o r t=input ( PORT: )
close a l l ;
clc ;
y1=zeros ( 1 , 1 0 0 0 0 ) ; %Vector donde s e guardar
an l o s dato s
y2=zeros ( 1 , 1 0 0 0 0 ) ; %Vector donde s e guardar
an l o s dato s
y3=zeros ( 1 , 1 0 0 0 0 ) ; %Vector donde s e guardar
an l o s dato s
c o n t a d o r=zeros ( 1 , 1 0 0 0 0 ) ;
%I n i c i a l i z o e l p u e r t o s e r i a l
delete ( i n s t r f i n d ( { Port } ,{ COM7 }) ) ;
p u e r t o s e r i a l=s e r i a l ( COM7 ) ;
p u e r t o s e r i a l . BaudRate =9600 ;
warning ( o f f , MATLAB: s e r i a l : f s c a n f : u n s u c c e s s f u l R e a d ) ;
%A b r i r p u e r t o s e r i a l
7
fopen ( p u e r t o s e r i a l ) ;
%c o n t a d o r d e m u e s t r a s
c o n t a d o r m u e s t r a s =1;
%ventana para l a g r
afica
f i g u r e ( Name , S e r i a l t e s t )
t i t l e ( MATLAB+ARDUINO ) ;
xlabel ( N
umero de muestras ) ;
ylabel ( V o l t a j e (V) ) ;
grid on ;
hold on ;
// Bucle while para que tome y d i b u j e l a s muestras qu e
queremos
while c o n t a d o r m u e s t r a s <=numero muestras
ylim ( [ 0 2 . 1 ] ) ;
xlim ( [ c o n t a d o r m u e s t r a s 2 c o n t a d o r m u e s t r a s +1]) ;
s i g n a l 1=f s c a n f ( p u e r t o s e r i a l , %d ) ;
y1 ( c o n t a d o r m u e s t r a s )= ( s i g n a l 1 ( 1 ) ) 5 / 1 0 2 4 ;
s i g n a l 2=f s c a n f ( p u e r t o s e r i a l , %d ) ;
y2 ( c o n t a d o r m u e s t r a s ) =( s i g n a l 2 ( 1 ) ) 5 / 1 0 2 4 ;
s i g n a l 3=f s c a n f ( p u e r t o s e r i a l , %d ) ;
y3 ( c o n t a d o r m u e s t r a s ) =( s i g n a l 3 ( 1 ) ) 1 . 8 / 1 0 2 4 ;
c o n t a d o r ( c o n t a d o r m u e s t r a s )=c o n t a d o r m u e s t r a s ;
c o n t=f s c a n f ( p u e r t o s e r i a l , %d ) ;
switch s i g n a l s
case 1
plot ( c o n t a d o r m u e s t r a s , y1 ( c o n t a d o r m u e s t r a s ) , b
, LineWidth , 4 ) ;
legend ( V r e f )
case 2
plot ( c o n t a d o r m u e s t r a s , y1 ( c o n t a d o r m u e s t r a s ) ,
b , LineWidth , 4 ) ;
plot ( c o n t a d o r m u e s t r a s , y2 ( c o n t a d o r m u e s t r a s ) , x
r , LineWidth , 4 ) ;
legend ( V r e f , Vout )
case 3
8
plot ( c o n t a d o r m u e s t r a s
b , LineWidth , 4 ) ;
plot ( c o n t a d o r m u e s t r a s
r , LineWidth , 4 ) ;
plot ( c o n t a d o r m u e s t r a s
g , LineWidth , 4 ) ;
legend ( V r e f , Vout ,
otherwise
plot ( c o n t a d o r m u e s t r a s
b , LineWidth , 4 ) ;
legend ( V r e f )
, y1 ( c o n t a d o r m u e s t r a s ) ,
, y2 ( c o n t a d o r m u e s t r a s ) , x
, y3 ( c o n t a d o r m u e s t r a s ) , o
Signo )
, y1 ( c o n t a d o r m u e s t r a s ) ,
end
f p r i n t f ( c o n t a d o r= %d\n , c o n t )
drawnow ;
c o n t a d o r m u e s t r a s=c o n t a d o r m u e s t r a s +1;
end
%C i e r r o l a c o n e x i
o n con e l p u e r t o s e r i a l y e l i m i n o l a s
variables
fclose ( p u e r t o s e r i a l ) ;
delete ( p u e r t o s e r i a l ) ;
figure ;
switch s i g n a l s
case 1
plot ( c o n t a d o r ( 1 : c o n t a d o r
c o n t a d o r m u e s t r a s 1) ,
hold on ;
legend ( V r e f )
case 2
plot ( c o n t a d o r ( 1 : c o n t a d o r
c o n t a d o r m u e s t r a s 1) ,
hold on ;
plot ( c o n t a d o r ( 1 : c o n t a d o r
c o n t a d o r m u e s t r a s 1) ,
hold on ;
legend ( V r e f , Vout )
9
m u e s t r a s 1) , y1 ( 1 :
b , LineWidth , 4 ) ;
m u e s t r a s 1) , y1 ( 1 :
b , LineWidth , 4 ) ;
m u e s t r a s 1) , y2 ( 1 :
xr , LineWidth , 4 ) ;
case 3
plot ( c o n t a d o r ( 1 : c o n t a d o r m u e s t r a s 1) , y1 ( 1 :
c o n t a d o r m u e s t r a s 1) , b , LineWidth , 4 )
hold on ;
plot ( c o n t a d o r ( 1 : c o n t a d o r m u e s t r a s 1) , y2 ( 1 :
c o n t a d o r m u e s t r a s 1) , xr , LineWidth , 4 )
hold on ;
plot ( c o n t a d o r ( 1 : c o n t a d o r m u e s t r a s 1) , y3 ( 1 :
c o n t a d o r m u e s t r a s 1) , og , LineWidth , 4 )
hold on ;
legend ( V r e f , Vout , Signo )
otherwise
plot ( c o n t a d o r ( 1 : c o n t a d o r m u e s t r a s 1) , y1 ( 1 :
c o n t a d o r m u e s t r a s 1) , b , LineWidth , 4 )
hold on ;
legend ( V r e f )
end
%
guarda d a t o s en t x t
f i d=fopen ( data . t x t , w ) ;
signal1
signal2
f p r i n t f ( f i d , n . dat a
signal3 ) ;
f p r i n t f ( f i d , \n ) ;
for k = 1 : 1 : numer o muestras
c c o n t a d o r=mat2str ( c o n t a d o r ( k ) ) ;
c s i g n a l 1=mat2str ( f l o o r ( y1 ( k ) 1 0 0 0 0 0 ) /100000 )
;
c s i g n a l 2=mat2str ( f l o o r ( y2 ( k ) 1 0 0 0 0 0 ) /100000 )
;
c s i g n a l 3=mat2str ( f l o o r ( y3 ( k ) 1 0 0 0 0 0 ) /100000 )
;
c s i g n a l s=s t r c a t ( c c o n t a d o r , \ t , \ t ,
c signal1 , \t , \t , c signal2 , \t , \t ,
c signal3 ) ;
fprintf ( fid , c s i g n a l s ) ;
f p r i n t f ( f i d , \n ) ;
end
fclose ( f i d ) ;
10
Apendice B
Algoritmo en Arduino
int
int
int
int
int
int
int
s i g n a l p i n 1=A0 ; // Analog 0
s i g n a l p i n 2=A1 ; // Analog 1
s i g n a l p i n 3=A2 ; // Analog 2
outPin1= 7 ;
outPin2= 6 ;
outPin3= 5 ;
outPin4= 4 ;
int i n P i n 1= 3 ;
int s i g n a l 1 =0;
int s i g n a l 2 =0;
int s i g n a l 3 =0;
int s i g n o 1 ;
int s i g n o 2 ;
int co n t =0;
int i ;
void s e t u p ( )
{
S e r i a l . begin (9600) ;
pinMode ( outPin1 , OUTPUT) ;
pinMode ( outPin2 , OUTPUT) ;
pinMode ( outPin3 , OUTPUT) ;
pinMode ( outPin4 , OUTPUT) ;
pinMode ( inPin1 , INPUT) ;
}
11
void l o o p ( ) {
d i g i t a l W r i t e ( outPin1 , LOW) ; // c o n t a d o r en c e r o s
d i g i t a l W r i t e ( outPin2 , LOW) ;
d i g i t a l W r i t e ( outPin3 , LOW) ;
delay (500) ;
s i g n o 1=d i g i t a l R e a d ( i n P i n 1 ) ;
s i g n o 2=s i g n o 1 ;
d i g i t a l W r i t e ( outPin4 , s i g n o 1 ) ;
//e n v i o de d a t o s
s i g n a l 1=analogRead ( s i g n a l p i n 1 ) ;
Serial . println ( signal1 ) ;
delay (50) ;
s i g n a l 2=analogRead ( s i g n a l p i n 2 ) ;
Serial . println ( signal2 ) ;
delay (50) ;
s i g n a l 3=analogRead ( s i g n a l p i n 3 ) ;
Serial . println ( signal3 ) ;
delay (50) ;
S e r i a l . p r i n t l n ( cont ) ;
delay (50) ;
//c o n t a d o r f r e c a p r o x= 1 Hz
while ( s i g n o 1==s i g n o 2 )
{
s i g n o 2=d i g i t a l R e a d ( i n P i n 1 ) ;
s i g n a l 1=analogRead ( s i g n a l p i n 1 ) ;
Serial . println ( signal1 ) ;
delay (50) ;
s i g n a l 2=analogRead ( s i g n a l p i n 2 ) ;
Serial . println ( signal2 ) ;
delay (50) ;
s i g n a l 3=analogRead ( s i g n a l p i n 3 ) ;
Serial . println ( signal3 ) ;
delay (50) ;
S e r i a l . p r i n t l n ( cont ) ;
12
delay (50) ;
i f ( i ==10)
{
co n t=c o n t +1;
i =0;
}
i=i +1;
i f ( cont >=7)
{
co n t =7;
}
//c o n t b i n a r i o
switch ( c o n t ) {
case 1 :
d i g i t a l W r i t e ( outPin1 , HIGH) ;
d i g i t a l W r i t e ( outPin2 , LOW) ;
d i g i t a l W r i t e ( outPin3 , LOW) ;
break ;
case 2 :
d i g i t a l W r i t e ( outPin1 , LOW) ;
d i g i t a l W r i t e ( outPin2 , HIGH) ;
d i g i t a l W r i t e ( outPin3 , LOW) ;
break ;
case 3 :
d i g i t a l W r i t e ( outPin1 , HIGH) ;
d i g i t a l W r i t e ( outPin2 , HIGH) ;
d i g i t a l W r i t e ( outPin3 , LOW) ;
break ;
case 4 :
d i g i t a l W r i t e ( outPin1 , LOW) ;
d i g i t a l W r i t e ( outPin2 , LOW) ;
d i g i t a l W r i t e ( outPin3 , HIGH) ;
break ;
13
case 5 :
d i g i t a l W r i t e ( outPin1
d i g i t a l W r i t e ( outPin2
d i g i t a l W r i t e ( outPin3
break ;
case 6 :
d i g i t a l W r i t e ( outPin1
d i g i t a l W r i t e ( outPin2
d i g i t a l W r i t e ( outPin3
break ;
case 7 :
d i g i t a l W r i t e ( outPin1
d i g i t a l W r i t e ( outPin2
d i g i t a l W r i t e ( outPin3
break ;
}
, HIGH) ;
, LOW) ;
, HIGH) ;
, LOW) ;
, HIGH) ;
, HIGH) ;
, HIGH) ;
, HIGH) ;
, HIGH) ;
while ( 1 )
{
s i g n a l 1=analogRead ( s i g n a l p i n 1 ) ;
Serial . println ( signal1 ) ;
delay (50) ;
s i g n a l 2=analogRead ( s i g n a l p i n 2 ) ;
Serial . println ( signal2 ) ;
delay (50) ;
s i g n a l 3=analogRead ( s i g n a l p i n 3 ) ;
Serial . println ( signal3 ) ;
delay (50) ;
S e r i a l . p r i n t l n ( cont ) ;
delay (50) ;
}
}
14
Referencias
15