Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Digital Tachometer using PIC18F Code

Status
Not open for further replies.

HemZ

Newbie level 4
Joined
Apr 6, 2017
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
64
Hi All,

Rigging up Digital Tachometer using PIC18F45K50 and IR Module, connected IR Module output to RA4 of Pic,

Followed https://embedded-lab.com/blog/how-t...chometer-using-ir-light-reflection-technique/

And here is the code modiified

Code:
 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 RA4_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;
  Lcd_Out(2,4,RPM);
 }
 
 void main() {
  CMCON = 0x07;   // Disable comparators
  ADCON1 = 0x0F;  // Disable Analog functions
  TRISC = 0x00;
  TRISB = 0x00;
  PORTA = 0x00;
  TRISA = 0b00010000;
  T0CON = 0x08; // TMR0 as 16-bit counter
  Lcd_Init();        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);             // CLEAR display
  Lcd_Cmd(_LCD_CURSOR_OFF);        // Cursor off
  Lcd_Out(1,4,message1);            // Write message1 in 1st row
  do {

   T0CON.TMR0ON = 1;
   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 = (256*TMR0H + TMR0L)*60;
   Display_RPM(RPM_Value);
  } while(1);             // Infinite Loop
 }


i get display on LCD, but default it displays 3000 rpm and shows no much changes. Not measuring increase or decrease of motor . Is there any correction needed in code, bit confused with different approaches for tachometer.:???:
Please guide.
 
Last edited:

hello



did you check before displaying a known value on LCD ...

Code:
RPM_Value = 12345;
Display_RPM(RPM_Value);

with (256*TMR0H + TMR0L)
you can get intermediate Overflow ..

Code:
 RPM_Value = (TMR0H <<8) + TMR0L;
 RPM_Value = RPM_Value* 60;
 

hello



did you check before displaying a known value on LCD ...

Code:
RPM_Value = 12345;
Display_RPM(RPM_Value);

No I did not check with that.

with (256*TMR0H + TMR0L)
you can get intermediate Overflow ..

Code:
 RPM_Value = (TMR0H <<8) + TMR0L;
 RPM_Value = RPM_Value* 60;

Let me try out,
Thank you. Any further improvements needed please guide me. I will update on results.
 

Hi ,

I displayed 12345 on LCD , as suggested. And then modified and included below part,

Code:

Code C - [expand]
1
2
RPM_Value = (TMR0H <<8) + TMR0L;
 RPM_Value = RPM_Value* 60;


but default it displays 03960 RPM , no change of rpm in LCD.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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 RA4_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;
  Lcd_Out(2,4,RPM);
 }
 
 void main() {
  //CMCON = 0x07;   // Disable comparators
  //ADCON1 = 0x0F;  // Disable Analog functions
  ANSELA= 0x00;
  ANSELB = 0x00;
  TRISC = 0x00;
  TRISB = 0x00;
  PORTA = 0x00;
  PORTB = 0x00;
  
  TRISA = 0b00010000;
  T0CON = 0x08; // TMR0 as 16-bit counter
  Lcd_Init();        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);             // CLEAR display
  Lcd_Cmd(_LCD_CURSOR_OFF);        // Cursor off
  Lcd_Out(1,4,message1);            // Write message1 in 1st row
  do {
 
   T0CON.TMR0ON = 1;
   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 = 12345; //(256*TMR0H + TMR0L)*60;
   Display_RPM(RPM_Value);
  } while(1);             // Infinite Loop
 }



NO changes in display. :-(
 
Last edited by a moderator:

I'm not sure if this matters, but it is worth to try declaring the variable

Code:
char *RPM = "00000 RPM";

not as a pointer for an string array, but as an array itself:

Code:
char RPM[] = "00000 RPM";
 

hello,


What signal do you apply on RA4 ?
RA4 with a pull up resitor ?
level, formfactor, frequency ?
 
hello,


What signal do you apply on RA4 ?
RA4 with a pull up resitor ?
level, formfactor, frequency ?

Connecting RA4 to output of IR tx rx Module, and no pull up resistor.
 

Hi ,

And i observe 3.6V across output pin of IR module and as well as at PIC input pin.(RA4) whenever the Rx diode is exposed or blocked from the IR light.
 

mikroC PRO PIC has Inbuilt function

Code:
IntToStr()
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top