Sign In

Trouble In Displaying Speed In Tachometer


Hardware: Pic18f45k50 Running At 20 Mhz Software: MicroC Programming

we are building a tachometer wherein the hardware interfacing is proper but the software coding is the issue we are unable to display the readings speed in rpm properly. Random values are appearing on screen. We took the reference design from the below mentioned site and modified to our micro controller : Please help us in resolving the issue asap



unsigned long RPM_Value;

// Define LCD module connections.
 sbit LCD_RS at RB5_bit;
 sbit LCD_EN at RB4_bit;
 sbit LCD_D4 at RA0_bit;
 sbit LCD_D5 at RA1_bit;
 sbit LCD_D6 at RA2_bit;
 sbit LCD_D7 at RA3_bit;
 sbit LCD_RS_Direction at TRISB5_bit;
 sbit LCD_EN_Direction at TRISB4_bit;
 sbit LCD_D4_Direction at TRISA0_bit;
 sbit LCD_D5_Direction at TRISA1_bit;
 sbit LCD_D6_Direction at TRISA2_bit;
 sbit LCD_D7_Direction at TRISA3_bit;
// End LCD module connection definition
 sbit IR_Tx at RA5_bit;

// Define Messages
 char message1[] = "Tachometer";
 char *RPM = "00000 RPM";
 void Display_RPM(unsigned long num)
  RPM[0] = num/10000 + 48;
  RPM[1] = (num/1000)%10 + 48;
  RPM[2] = (num/100)%10 + 48;
  RPM[3] = (num/10)%10 + 48;
  RPM[4] = num%10 + 48;

 void main()
  //CMCON = 0x07;   // Disable comparators
  ADCON1 = 0x0F;  // Disable Analog functions
  TRISC = 0x00;
  TRISB = 0x00;
  PORTA = 0x00;
  //OSCCON = 0X7A;
  TRISA = 0b00010000;
  T0CON = 0b00111001; // TMR0 as 16-bit counter
  Lcd_Init();        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);             // CLEAR display
  Lcd_Cmd(_LCD_CURSOR_OFF);        // Cursor off
             // Write message1 in 1st row
  do {

   T0CON.TMR0ON = 1;      //ENABLE TIMER
   TMR0L = 0;
   TMR0H = 0;
   IR_Tx = 1;

   Delay_ms(1000); // Wait for 1 sec
   IR_Tx = 0;
   T0CON.TMR0ON = 0;    // Stop the timer
   /*RPM_Value = (TMR0H <<8) + TMR0L;
    RPM_Value = RPM_Value* 60;*/
   RPM_Value = (256*TMR0H + TMR0L)*60;
    } while(1);             // Infinite Loop

Post a reply to MANASA

Think you can help MANASA ? Then post your thoughts that might help MANASA. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.