Autor Tema: pueden revisar esto?  (Leído 1808 veces)

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

Desconectado fastyx

  • Colaborador
  • PIC18
  • *****
  • Mensajes: 353
pueden revisar esto?
« en: 30 de Enero de 2006, 10:04:00 »
estoy tratando de medir dos señales en rc7 yrc4 de un 18f242 y sacar las rpm por lcd
// 6 ovf de 26.2 ms para cada med1 / med2 / proceso

mido_rpm ()
{
int8 qovf ;          // cantidad de overflows
int8 qovfpul ;       // cantidad de overflows entre flancos del pulso
int8 ord_med ;       // registra si no se midió (0), se hizo primera med (1), idem (2)
int1 mem_pul ;       // estado anterior del pulso
int16 w1 , w2, w3,w4;    // dos mediciones del timer1
int32 tflan1 ,tflan2 ;       // tiempo entre flancos +
float rpm1 , rpm2 ;

   // CAPTURO MED1
 led = ~led ; // debug

   for ( qovf = 0
         , timer1if = 0 , set_timer1 ( 0 ) , mem_pul = pul1 , ord_med = 0 ,
         w1 = 0 , w2 = 0
         ; qovf < 6 ; )
   {
      if ( timer1if )
      {
         qovf ++ ;  qovfpul ++ ; timer1if = 0 ;
         if ( ord_med < 2 )
         {
              qovfpul ++ ;
         }
      }
      if ( ~mem_pul && pul1 )    // flanco positivo
      {
         if ( ord_med == 0 )
         {
            ord_med = 1 ;  w1 = get_timer1 () ; qovfpul = 0 ;
         }
         else if ( ord_med == 1 )
         {
            ord_med = 2 ;  w2 = get_timer1 () ;
         }
      }
      mem_pul = pul1 ;
   }

   // CALCULO MED1
   tflan1 = qovfpul * 65536 + w2 - w1 ;    // cantidad de 0.4 us
   (float)rpm1 = 2500000.0 / (float)tflan1 ;



   // MED2
   for ( qovf = 0 , timer1if = 0 , set_timer1 ( 0 ) , mem_pul = pul2 , ord_med = 0 ,
         w3 = 0 , w4 = 0 ; qovf < 6 ; )
   {
      if ( timer1if )
      {
         qovf ++ ;  qovfpul ++ ; timer1if = 0 ;
         if ( ord_med < 2 )
         {
              qovfpul ++ ;
         }
      }
      if ( ~mem_pul && pul2 )    // flanco positivo
      {
         if ( ord_med == 0 )
         {
            ord_med = 1 ;  w3 = get_timer1 () ; qovfpul = 0 ;
         }
         else if ( ord_med == 1 )
         {
            ord_med = 2 ;  w4 = get_timer1 () ;
         }
      }
      mem_pul = pul2 ;
   }

   // CALCULO MED2
   tflan2 = qovfpul * 65536 + w4 - w3 ;
   (float)rpm2 = 2500000.0 / (float)tflan2 ;


   // PROCESO
   printf ( lcd_putc, "f%4.1f; %4.1f;    " , rpm1 , rpm2 ) ;
  //printf ( lcd_putc, "f1000; 1500;    " ) ;
}
#include "esp.h"




void main()
{
   ini ( ) ;

   while ( true )
   {
      mido_rpm () ;
      delay_ms ( 500 ) ;
   }
}




 

anything