unsigned long RPM_Value;
// Define LCD module connections.
sbit LCD_RS at RB3_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB3_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
sbit IR_Tx at RD2_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() {
ANSEL0 = 0x00;
ANSEL1 = 0x00;
TRISD = 0x00;
PORTC = 0x00;
TRISC = 0b00001000;
T0CON = 0b01101000; // 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
while(1)
{
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);
RPM_Value = 0;
}; // Infinite Loop
}
unsigned long RPM_Value;
// Define LCD module connections.
sbit LCD_RS at RB3_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB3_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
sbit IR_Tx at RD2_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() {
int i = 0;
ANSEL0 = 0x00;
ANSEL1 = 0x00;
TRISD = 0x00;
PORTC = 0x00;
TRISC = 0b00001000;
T0CON = 0b01101000; // 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
while(1)
{
[B]for(i = 0 ; i < 20 ; i++)
{
T0CON.TMR0ON = 1;
TMR0L = 0;
TMR0H = 0;
Delay_ms(1000); // Wait for 1 sec
T0CON.TMR0ON = 0; // Stop the timer
RPM_Value += (256*TMR0H + TMR0L)*60;
}
RPM_Value = RPM_Value /20;
Display_RPM(RPM_Value);
RPM_Value = 0;[/B]
}; // Infinite Loop
}
is there any way to get 1 to 60 rpm in my code please give me some trick of code.
but i would to get more accuracy like 1 rpm.
.. At high speed ... 60rpm
with a so big resolution, i think no need to average the measure.
unsigned long RPM_Value;
// Define LCD module connections.
sbit LCD_RS at RB3_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB3_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
// sbit IR_Tx at RD2_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);
}
unsigned int ov_cnt, temp;
unsigned long period;
void interrupt()
{
if(PIR1.TMR1IF)
{
PIR1.TMR1IF = 0;
ov_cnt ++;
}
}
void main()
{
unsigned int temp1;
ov_cnt = 0;
ANSEL0 = 0x00;
ANSEL1 = 0x00;
TRISD = 0x00;
PORTC = 0x00;
TRISC = 0b00000100;
INTCON.GIE = 0;
RCON.IPEN = 1;
PIR1.TMR1IF = 0;
IPR1.TMR1IP = 1;
T1CON = 0x81;
CCP1CON = 0x05;
PIE1.CCP1IE = 0;
PIR1.CCP1IF = 0;
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
while(1)
{
while (!(PIR1.CCP1IF));
temp = CCPR1;
PIR1.CCP1IF = 0;
PIR1.TMR1IF = 0;
INTCON |= 0xC0;
PIE1.TMR1IE = 1;
while (!(PIR1.CCP1IF));
CCP1CON = 0x00;
temp1 = CCPR1;
if (temp1 < temp)
{
ov_cnt--;
}
period = ov_cnt * 65536 + temp1 - temp;
RPM_Value = period ;
Display_RPM(RPM_Value);
ov_cnt = 0;
temp1 = 0 ;
temp = 0;
}; // Infinite Loop
}
No result at all? or no meaningful result?didn't give me result
nick703;1456918M so i can use 60 / Period to calculate RPM right?[/QUOTE said:No , what is the raw value do you get at 60 RPM ?
example : you get a raw value period of 1.000 at 60 RPM => K calibration is 60.000
speed= K/ Raw value => 60.000/1.000 => 60 RPM
at 6 RMP
Raw value will be 10.000
speed= K /Raw value (10.000) => 60.000 / 10.000 => 6 RPM
you must use long int or float for calculus..
unsigned long RPM_Value;
// Define LCD module connections.
sbit LCD_RS at RB3_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB3_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
// sbit IR_Tx at RD2_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);
}
unsigned int ov_cnt, temp;
unsigned long period;
void interrupt()
{
if(PIR1.TMR1IF)
{
PIR1.TMR1IF = 0;
ov_cnt ++;
}
}
void main()
{
unsigned int temp1;
ov_cnt = 0;
ANSEL0 = 0x00;
ANSEL1 = 0x00;
TRISD = 0x00;
PORTC = 0x00;
TRISC = 0b00000100;
INTCON.GIE = 0;
RCON.IPEN = 1;
PIR1.TMR1IF = 0;
IPR1.TMR1IP = 1;
T1CON = 0xC1;
CCP1CON = 0x05;
PIE1.CCP1IE = 0;
PIR1.CCP1IF = 0;
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
while(1)
{
while (!(PIR1.CCP1IF));
temp = CCPR1;
PIR1.CCP1IF = 0;
PIR1.TMR1IF = 0;
INTCON |= 0xC0;
PIE1.TMR1IE = 1;
while (!(PIR1.CCP1IF));
CCP1CON = 0x00;
temp1 = CCPR1;
if (temp1 < temp)
{
ov_cnt--;
}
period = ov_cnt * 65536 + temp1 - temp;
RPM_Value = period ; // this is micro second value
RPM_Value = 60000000 / RPM_Value; // this value multiplied by 60
RPM_Value = RPM_Value * 2; // and whole period * 2
Display_RPM(RPM_Value);
ov_cnt = 0;
temp1 = 0 ;
temp = 0;
}; // Infinite Loop
}
ok now below program is giving me a result of 1 rpm to 1800 rpm but in this code when i have achieve 1 rpm LCD take a time 1 min refresh to data print. so is there same problem in my post # 1 . my goal is achieve 1 rpm to 99999 rpm. and update data on LCD 1 sec.
In short, you would need to develop a time machine, jump forward to the future, measure the period, jump back to the present and update the LCD. Such a technique would enable less than one second LCD updates for all measurements under 60 RPM. :lol:
BigDog
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?