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.

RPM fluctuating on PIC18 (PIC18F458)

Status
Not open for further replies.

shapa2011

Newbie level 3
Joined
Apr 30, 2012
Messages
3
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,314
Hello and Salam (if you're ******)

Base on frequency meter code by Rajendra Bhatt of embedded-lab.com, I made a tachometer reading using PIC18F458 timer0 (configured to 8 bit and read from RA4 pin) but before making the actual circuit, I had it simulated using Proteus. Here's the code



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
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
 
// Define Messages
char msg2[] = "RPM=";
char *rpm = "0000";
int RPM1;
int RPM2;
long Calc_RPM;
 
// Display RPM
void Display_RPM(unsigned long rpm2write) {
  rpm[0] = (rpm2write/1000)%10 + 48;
  rpm[1] = (rpm2write/100)%10 + 48;
  rpm[2] = (rpm2write/10)%10 + 48;
  rpm[3] = rpm2write%10 + 48;
Lcd_Out(1, 5, rpm);
}
// Main Program
void main() {
 CMCON = 0x07;    // Disable Comparators
 ADCON0 = 0x00;   // All AN to Digital Input
 ADCON1 = 0x00;
 TRISC = 0x00;     // PORTC O/P
 TRISA = 0b01010000; // RA4/T0CKI input, RA6 is input for Ext OSC
 
   T0CON = 0b01111000; // Prescaler (1:1)
//                 0-------   TMR0ON off
//                 -1------   T08BIT is set for 8 bit counter
//                 --1-----   T0CS is set T0CKI pin
//                 ---1----   TOSE set increment hi-low
//                 ----1---   PSA Prescaler not assigned
//                 -----000
 
// Initialize LCD display
 Lcd_Init();                 // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR);        // CLEAR display
 Lcd_Cmd(_LCD_CURSOR_OFF);   // Cursor off
 Lcd_Out(2,1,msg2);
 
do {
  T0CON.TMR0ON = 1; // On the timer
  TMR0L=0;
  Delay_ms(1000);  // Delay 1 Sec
 //-- RPM Calculation = (60 x Frequency)/PPR --//
  Calc_RPM = (60*TMR0L)/4;
  Display_RPM(Calc_RPM);
  } while(1);  // Infinite loop
}




basically what I did is calculating the RPM using formula RPM = (60 x f )/ Pulse per revolution, where the pulse per revolution is set to
4 PPR in my case. It then displayed to LCD display using Display_RPM function. below is the simulation circuit using Proteus.

tachometer.jpg

as you can see in the picture, the rpm number seem to be fluctuating, it actually jump from 450 to 465 when simulated. I just wonder why is that happened and is it a way around it?.

Thank you so much in advance for any help from you guys.
 
Last edited by a moderator:

thanks for the correction alexan_e ...

anybody had any thought ? appreciate for any help, thank you
 
hello


so ,it means that change in TMR0L could be from 30 up to 30.6666
not possible ,because its' a byte ( 0 to 255)
and you are working with integer ,not floating point, so rounded value.

Resoltution is to poor by using this methode.
Try to measure the periode , time between each pulse , using timer0 in 16 bits mode.
and convert to RPM with a formula using floating point.

or much better, using capture mode CCP1 with Timer 1 and RC2 input.
 
Thank you so much for the tips paulfjujo...

I actually tried using 16 bit timer, but no quite sure how to calculate RPM using floating point, could you shed some light ?
 

hello

Have a look on my web page
**broken link removed**
you will get 2 examples
one in mikroC with 16F877
one in C18 with 18F262
2 ranges of measure .. 4.8Hz up to 25000Hz
tested with a Quartz generator

but it's could be fine, if you know what is your range of RPM (aproxmaively)
to apply the best solution Frequency counting or periode couting.
.
if you have the frequency in Hz , easy to transforme in RPM !
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top