contactless_18f4550_tachometer



I was misunderstanding about Delay_ms() function. I was thinking everything freeze in Delay time.

The code: I coded for reading speed of dc motor in various speed and I tested only for measuring Revolution per second .

 
  #define Rx PORTA.f4
  #define Led PORTA.f3
 
unsigned long *clk,clktemp;
unsigned long int k,i,j,Rpm,Rpmh,Rpml,pwm;
unsigned char op[12],lcd[12];
char *text = "TECHOMETER";
char *text1= "Rev/s =";



void main()
     {
       OSCCON=0xff;
       T0CON.T08BIT=0; //16 bit
       T0CON.T0CS=1;     //T0CLK pin;
       T0CON.PSA=1;      //pSA not assigned
       CMCON = 0x07;   // Disable comparators
       ADCON1 = 0x0F;  // Disable Analog functions
     //  TRISC.F0=1;     ////T1 CLK IN
//       T1CON.RD16=1;   //16 bit mode
//       T1CON.T1CKPS0=0;// ps 1
//       T1CON.T1CKPS1=0;
//       T1CON.T1OSCEN=0;//T1 osc
//       T1CON.T1SYNC=0;          //sync with external clk ip
//       T1CON.TMR1CS=1;           // sync with ext clk from rc0
       TRISB=0;

       PORTB=0;
       TRISA.f0=1;
       TRISA.f3=0;         // led
       TRISA.f4=1;         //RA4 as T0CLK
       TrISC.f2=0;

      Pwm1_Init(3600);
      Pwm1_Start();
      pwm1_Change_Duty(10);
       Lcd_Cmd(Lcd_CLEAR);

      LCD_CURSOR_OFF;

      Lcd_Init(&PORTB);


     for(;;)
      {




      TMR0H=0;
      TMR0l=0;
      Rpm=0;
     
      T1CON.TMR1ON=1;    //40.71  e-6 sec
       Led=1;
       // 1 sec delay
    //  Delay_Ms(996);     //1040.71e-6
      //Delay_Us(530);     //1040.71e-6
      delay_ms(1000);
       Led=0;
      T1CON.TMR1ON=0;
     
       Rpml=TMR0l;
       Rpmh=TMR0H*256;
       Rpm=Rpml+Rpmh;



      LongToStr(Rpm,op); // Convert to string in "op"

       j=0;

       for(i=0;i<=11;i++)
       {
       if(op[i] != ' ') // If a blank
         {
         lcd[j]=op[i];
         j++;
       
       }
         }
        Lcd_Cmd(Lcd_CLEAR);
        Lcd_Out(1, 3,text);
        Lcd_Out(2,1,text1);
        Lcd_Out(2,9,lcd);

      }

     }

Comments

Popular posts from this blog

Inductance caculator

Pointer to object array