Autor Tema: Problema con un tacometro  (Leído 1553 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado darck_khronos

  • PIC18
  • ****
  • Mensajes: 493
Problema con un tacometro
« en: 25 de Abril de 2010, 19:44:05 »
Haciendo uso de un código que un colega aporto, y realizando algunas modificaciones para adaptarlo a mis necesidades al procesar las interrupciones despues de unos cuantos segundos se queda pasmado, a demás de que al grabarlo dentro del micro la lcd solo se mantiene con sus cuadros de inicializacion.

y parte del problema se presenta cuando hay variacion tanto de del tacometro, ya que si la velocidad se mantiene constante y varia el pwm trabaja bien, pero cuando hago una variacion de velocidad y mando nuevos datos hacia el PWM ya no hace nada

Código: C
  1. #include <18f2550.h>
  2. #FUSES NOWDT,PUT,MCLR,NOBROWNOUT,NOLVP,NOPROTECT,NODEBUG,NOFCMEN,NOIESO,XT
  3. #include <MATH.h>
  4. #define COMENZAR  0
  5. #define CONTANDO  1
  6. #define TERMINO   2
  7. #define VECES 1
  8. #use delay(clock=4000000)
  9. #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
  10. //------------ Pines del LCD ---------------------//
  11. #define LCD_E     PIN_C0
  12. #define LCD_CK    PIN_C4  
  13. #define LCD_DAT   PIN_C5
  14. //--------------------------------------------------//
  15. #include "lcd3.c"
  16. #use standard_io (b)
  17.  
  18. char cEstado;
  19. int32 int32Cont;
  20. float fRpm, vel;
  21. long int dato;
  22.  
  23.  
  24. //INTERRUPCION POR RB3 CCP1//
  25.  
  26. #INT_CCP1
  27.  
  28. void CCP1__isr(void) {
  29.  
  30.     if (cEstado == CONTANDO) {       // Segundo Pulso
  31.         int32Cont += CCP_1;           // Toma el valor de captura
  32.         cEstado = TERMINO;           // Evito que vuelva a procesarse durante esta interrupcion
  33.     }
  34.  
  35.     if (cEstado == COMENZAR)  {      // Primer Pulso
  36.         set_timer1(0);               // Restaura el timer1 en este pulso
  37.         cEstado = CONTANDO;
  38.         int32Cont = 0;
  39.  
  40.     }
  41. }
  42.  
  43. //velocidad//
  44.  
  45. float velocidad(void){
  46.  
  47.     char cCnt;
  48.     int32 int32Suma;
  49.     long tiempo;
  50.  
  51.     cEstado = TERMINO;
  52.     while (TRUE) {
  53.       int32Suma = 0;
  54.       int32Cont = 0;
  55.       for (cCnt = 0; cCnt < VECES; cCnt++) {       // Acumula VECES lecturas
  56.         cEstado = COMENZAR;                        // Permite comenzar a la interrupcion
  57.         while (cEstado != TERMINO) {               // Espera hasta que se activa la interrupcion
  58.           tiempo =  get_timer1();
  59.           if (tiempo > 60000) {                    // Controla si el contador excedio el tiempo. Valor Original = 60000
  60.             set_timer1(0);                         // Restaura el timer1 para seguir sumando el tiempo de este pulso
  61.             int32Cont += tiempo;                   // Acumula para velocidades de viento bajas
  62.  
  63.           }                                        // Fin if
  64.         }                                          // Fin if
  65.         int32Suma += int32Cont;                    // Acumula los tiempos
  66.       }                                            // fin for
  67.  
  68.       int32Suma /= VECES;                          // Saca el promedio de las VECES que se tomo la medicion
  69.  
  70.       fRpm = 1 / ( float ) int32Suma / 20 * 2.5;    // Periodo en uS
  71.       fRpm *= 1000000;                             // Periodo en segundos
  72.       fRpm *= 60;                                 // Periodo en minutos
  73.  
  74.       dato = fRpm;
  75.      
  76.       vel= (((dato)/60)*(2*pi*15.90))/10;
  77.   return dato;
  78.     }
  79.  
  80. }
  81.  
  82. void main()
  83. {
  84.    float pwm;
  85.    int s;
  86.    lcd_init();
  87.    setup_ccp2(CCP_PWM);
  88.    setup_timer_2(T2_DIV_BY_4, 255, 1);
  89.    set_pwm2_duty(0);
  90.    delay_ms (50);
  91.    setup_timer_1 (T1_INTERNAL | T1_DIV_BY_8 );
  92.    setup_ccp1 (CCP_CAPTURE_FE);
  93.    delay_ms (50);
  94.    enable_interrupts (INT_CCP1);
  95.    enable_interrupts (GLOBAL);
  96.    for(;;) {
  97.       if(kbhit()){
  98.             pwm=getc();
  99.             s=getc();
  100.             pwm=(pwm/255)*100;
  101.             lcd_gotoxy(1,1);
  102.             printf(lcd_putc,"Velocidad %f",pwm);
  103.             set_pwm2_duty(s);
  104. //                  }
  105. //       else {                  
  106.          velocidad();
  107.          dato = (long int)fRpm;    
  108.          delay_ms(2);
  109.          lcd_gotoxy(1,2);                     //retardo para apreciarse todos los caracteres
  110.          printf(lcd_putc,"RPM: %lu RPM ",dato);       //muestra por pantalla el mensaje
  111.          putchar(dato);
  112.              }
  113.       }
  114.    }

Dejo adjuntado mi Labview y mi Proteus
« Última modificación: 25 de Abril de 2010, 19:47:13 por darck_khronos »


 

anything