Jorge Rodolfo Muñoz
/
Medidor_voltaje_resistencia
codigo para medir voltaje y resistencias mediante el microcontrolador Freedom KL25Z
main.cpp@0:85039ee1746a, 2014-03-05 (annotated)
- Committer:
- rodomnz
- Date:
- Wed Mar 05 05:18:47 2014 +0000
- Revision:
- 0:85039ee1746a
Medidor de Voltaje y Resistencias;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rodomnz | 0:85039ee1746a | 1 | /*Laboratorio 3: Codigo para un medidor de voltaje de 0 V a 28 V, y de resistencias, utilizando el microcontrolador |
rodomnz | 0:85039ee1746a | 2 | Freedom KL25Z, para la materia de informatica industrial TECNOLOGICO DE MONTERREY CAMPUS GUADALAJARA |
rodomnz | 0:85039ee1746a | 3 | realizada por: Jorge Rodolfo Muñoz Zuñiga A01227893 - Ismael Davila Martin A01227911 */ |
rodomnz | 0:85039ee1746a | 4 | |
rodomnz | 0:85039ee1746a | 5 | |
rodomnz | 0:85039ee1746a | 6 | #include "mbed.h" |
rodomnz | 0:85039ee1746a | 7 | //DECLARACION DE VARIABLES |
rodomnz | 0:85039ee1746a | 8 | DigitalOut myled(LED1); |
rodomnz | 0:85039ee1746a | 9 | |
rodomnz | 0:85039ee1746a | 10 | AnalogIn vout(PTB0);//entrada analogico que lee el voltaje |
rodomnz | 0:85039ee1746a | 11 | AnalogIn res_analogic(PTB1);//entrada analogica que lee el voltaje para el calculo de resistencias |
rodomnz | 0:85039ee1746a | 12 | float res[10]; |
rodomnz | 0:85039ee1746a | 13 | float voltaje[10]; |
rodomnz | 0:85039ee1746a | 14 | |
rodomnz | 0:85039ee1746a | 15 | DigitalIn boton1 (PTD4); //boton para cambiar el modo |
rodomnz | 0:85039ee1746a | 16 | int botonA; |
rodomnz | 0:85039ee1746a | 17 | DigitalIn boton2 (PTA12); //boton para promedio |
rodomnz | 0:85039ee1746a | 18 | int botonB; |
rodomnz | 0:85039ee1746a | 19 | |
rodomnz | 0:85039ee1746a | 20 | Serial pc(USBTX, USBRX); |
rodomnz | 0:85039ee1746a | 21 | |
rodomnz | 0:85039ee1746a | 22 | int tiempo; // para el uso del timer |
rodomnz | 0:85039ee1746a | 23 | Timer timer; |
rodomnz | 0:85039ee1746a | 24 | |
rodomnz | 0:85039ee1746a | 25 | float promedio1; //promedios |
rodomnz | 0:85039ee1746a | 26 | float promedio2; |
rodomnz | 0:85039ee1746a | 27 | |
rodomnz | 0:85039ee1746a | 28 | int i; //variables para el cambio de modo y el for |
rodomnz | 0:85039ee1746a | 29 | int modo; |
rodomnz | 0:85039ee1746a | 30 | |
rodomnz | 0:85039ee1746a | 31 | float corriente; |
rodomnz | 0:85039ee1746a | 32 | //CODIGO |
rodomnz | 0:85039ee1746a | 33 | int main() |
rodomnz | 0:85039ee1746a | 34 | { |
rodomnz | 0:85039ee1746a | 35 | myled = 1; |
rodomnz | 0:85039ee1746a | 36 | wait(1); |
rodomnz | 0:85039ee1746a | 37 | myled = 0; |
rodomnz | 0:85039ee1746a | 38 | wait(1); |
rodomnz | 0:85039ee1746a | 39 | modo = 0; |
rodomnz | 0:85039ee1746a | 40 | // comienzo del codigo para medidor de voltaje |
rodomnz | 0:85039ee1746a | 41 | |
rodomnz | 0:85039ee1746a | 42 | timer.start(); |
rodomnz | 0:85039ee1746a | 43 | |
rodomnz | 0:85039ee1746a | 44 | while(true) |
rodomnz | 0:85039ee1746a | 45 | { |
rodomnz | 0:85039ee1746a | 46 | |
rodomnz | 0:85039ee1746a | 47 | while(modo==0) //modo voltaje |
rodomnz | 0:85039ee1746a | 48 | { |
rodomnz | 0:85039ee1746a | 49 | tiempo=timer.read_ms(); |
rodomnz | 0:85039ee1746a | 50 | if((tiempo%500==0)&&(tiempo<=5000)) |
rodomnz | 0:85039ee1746a | 51 | { |
rodomnz | 0:85039ee1746a | 52 | voltaje[(tiempo/500)-1]=(vout*28);//agregando los valores leidos al arreglo voltaje |
rodomnz | 0:85039ee1746a | 53 | } |
rodomnz | 0:85039ee1746a | 54 | |
rodomnz | 0:85039ee1746a | 55 | if(tiempo>5000) |
rodomnz | 0:85039ee1746a | 56 | { |
rodomnz | 0:85039ee1746a | 57 | timer.reset(); |
rodomnz | 0:85039ee1746a | 58 | } |
rodomnz | 0:85039ee1746a | 59 | botonB=boton2; |
rodomnz | 0:85039ee1746a | 60 | if(botonB==1)//calculo de promedio de valores leidos |
rodomnz | 0:85039ee1746a | 61 | { |
rodomnz | 0:85039ee1746a | 62 | for(i=0;i<=9;i++) |
rodomnz | 0:85039ee1746a | 63 | { |
rodomnz | 0:85039ee1746a | 64 | promedio1=promedio1+voltaje[i]; |
rodomnz | 0:85039ee1746a | 65 | } |
rodomnz | 0:85039ee1746a | 66 | pc.printf("valor del promedio del voltaje es: %f, \n ", promedio1/10); |
rodomnz | 0:85039ee1746a | 67 | pc.printf("valor de la suma de voltaje es: %f, \n \n ", promedio1); |
rodomnz | 0:85039ee1746a | 68 | timer.reset(); |
rodomnz | 0:85039ee1746a | 69 | promedio1 =0; |
rodomnz | 0:85039ee1746a | 70 | } |
rodomnz | 0:85039ee1746a | 71 | |
rodomnz | 0:85039ee1746a | 72 | botonA = boton1;//condicion para cambiar de modo |
rodomnz | 0:85039ee1746a | 73 | if (botonA==1) |
rodomnz | 0:85039ee1746a | 74 | { |
rodomnz | 0:85039ee1746a | 75 | modo = 1; |
rodomnz | 0:85039ee1746a | 76 | } |
rodomnz | 0:85039ee1746a | 77 | |
rodomnz | 0:85039ee1746a | 78 | } |
rodomnz | 0:85039ee1746a | 79 | |
rodomnz | 0:85039ee1746a | 80 | //fin del cofigo de medidor de voltaje |
rodomnz | 0:85039ee1746a | 81 | //inicio de codigo de medidor de resistencia |
rodomnz | 0:85039ee1746a | 82 | while (modo ==1) |
rodomnz | 0:85039ee1746a | 83 | { |
rodomnz | 0:85039ee1746a | 84 | corriente = 0.003; |
rodomnz | 0:85039ee1746a | 85 | tiempo=timer.read_ms(); |
rodomnz | 0:85039ee1746a | 86 | if((tiempo%500==0)&&(tiempo<=5000)) |
rodomnz | 0:85039ee1746a | 87 | { |
rodomnz | 0:85039ee1746a | 88 | res[(tiempo/500)-1]=(3.3-(res_analogic*3.3))/.003;//arreglo de resistencias |
rodomnz | 0:85039ee1746a | 89 | } |
rodomnz | 0:85039ee1746a | 90 | if(tiempo>5000) |
rodomnz | 0:85039ee1746a | 91 | { |
rodomnz | 0:85039ee1746a | 92 | timer.reset(); |
rodomnz | 0:85039ee1746a | 93 | } |
rodomnz | 0:85039ee1746a | 94 | botonB=boton2;//calculo del promedio de las resistencias |
rodomnz | 0:85039ee1746a | 95 | if(botonB==1) |
rodomnz | 0:85039ee1746a | 96 | { |
rodomnz | 0:85039ee1746a | 97 | for(i=0;i<=9;i++) |
rodomnz | 0:85039ee1746a | 98 | { |
rodomnz | 0:85039ee1746a | 99 | promedio2=promedio2+res[i]; |
rodomnz | 0:85039ee1746a | 100 | } |
rodomnz | 0:85039ee1746a | 101 | pc.printf("valor del promedio de resistencia es: %f, \n ", promedio2/10); |
rodomnz | 0:85039ee1746a | 102 | pc.printf("valor de la suma de resistencia es: %f, \n \n ", promedio2); |
rodomnz | 0:85039ee1746a | 103 | timer.reset(); |
rodomnz | 0:85039ee1746a | 104 | promedio2 =0; |
rodomnz | 0:85039ee1746a | 105 | } |
rodomnz | 0:85039ee1746a | 106 | botonA = boton2;//condicion para cambiar de modo |
rodomnz | 0:85039ee1746a | 107 | if (botonA==1) |
rodomnz | 0:85039ee1746a | 108 | { |
rodomnz | 0:85039ee1746a | 109 | modo = 0; |
rodomnz | 0:85039ee1746a | 110 | } |
rodomnz | 0:85039ee1746a | 111 | } |
rodomnz | 0:85039ee1746a | 112 | |
rodomnz | 0:85039ee1746a | 113 | |
rodomnz | 0:85039ee1746a | 114 | } |
rodomnz | 0:85039ee1746a | 115 | |
rodomnz | 0:85039ee1746a | 116 | } |
rodomnz | 0:85039ee1746a | 117 |