int a;
int b ;
int pulse=0;
int pulse2=0 ;
unsigned long rpm_value;
char text[15];
void main() {
TRISD.F0 = 1;
TRISD.F1= 1;
TRISA=0X00;
PORTA=0;
TRISC=0X00;
PORTC=0;
#define SW PORTD.RD0 // RD7 pin is pulse input pin
#define SW2 PORTD.RD1 //RD1PIN IS PULSE
while(1){
if(SW==1){
while(SW==1);
pulse++;
}
if(pulse>=721) pulse = 0;
if(RD0_bit==1) pulse ++;
if(pulse== pulse <=128){
portc.f5=0;
}
if (pulse>= 129 && pulse <=180){
porta.f2=1;
}
if (pulse>=181&& pulse <=308){
porta.f2=0;
portc.f3=0;
portc.f4=0 ;
}
if (pulse>=309 && pulse <=360){
porta.f2=0;
portc.f3=1 ;
portc.f4=0;
portc.f5=0;
}if (pulse>=361 && pulse <=488){
porta.f2=0;
portc.f3=0 ;
portc.f4=0;
portc.f5=0;
}
if (pulse>=489 && pulse <=540){
porta.f2=0;
portc.f3=0 ;
portc.f4=1;
portc.f5=0;
}
if (pulse>=541 && pulse <=668){
porta.f2=0;
portc.f3=0 ;
portc.f4=0;
portc.f5=0;
}
if (pulse>=669 && pulse <=720){
porta.f2=0;
portc.f3=0;
portc.f4=0;
portc.f5=1;
}
if(SW2==1){
while(SW2==1);
pulse2++;
}
if(RD1_bit==1) pulse2 ++;
if(pulse2>=60) pulse2=1*60; {
rpm=pulse2;
}
hi thank you i will send schematic of pic16f887 and use two digital external clock pulse for count and pulse 2 for meassure rpmhi inee some one to help me to add rpm to my counter how please....
Code:int a; int b ; int pulse=0; int pulse2=0 ; unsigned long rpm_value; char text[15]; void main() { TRISD.F0 = 1; TRISD.F1= 1; TRISA=0X00; PORTA=0; TRISC=0X00; PORTC=0; #define SW PORTD.RD0 // RD7 pin is pulse input pin #define SW2 PORTD.RD1 //RD1PIN IS PULSE while(1){ if(SW==1){ while(SW==1); pulse++; } if(pulse>=721) pulse = 0; if(RD0_bit==1) pulse ++; if(pulse== pulse <=128){ portc.f5=0; } if (pulse>= 129 && pulse <=180){ porta.f2=1; } if (pulse>=181&& pulse <=308){ porta.f2=0; portc.f3=0; portc.f4=0 ; } if (pulse>=309 && pulse <=360){ porta.f2=0; portc.f3=1 ; portc.f4=0; portc.f5=0; }if (pulse>=361 && pulse <=488){ porta.f2=0; portc.f3=0 ; portc.f4=0; portc.f5=0; } if (pulse>=489 && pulse <=540){ porta.f2=0; portc.f3=0 ; portc.f4=1; portc.f5=0; } if (pulse>=541 && pulse <=668){ porta.f2=0; portc.f3=0 ; portc.f4=0; portc.f5=0; } if (pulse>=669 && pulse <=720){ porta.f2=0; portc.f3=0; portc.f4=0; portc.f5=1; } if(SW2==1){ while(SW2==1); pulse2++; } if(RD1_bit==1) pulse2 ++; if(pulse2>=60) pulse2=1*60; { rpm=pulse2; }
}
}
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
//end lcd module connections
#define SW PORTD.RD7 // RD7 pin is pulse input pin
int pulse=0;
char text[15];
void main() {
TRISD.F0 = 1;
TRISA=0X00;
PORTA=0; // RD0 pin is input
Lcd_Init(); // Initialize the Lcd module
Lcd_Cmd(_LCD_CLEAR); // Clear Lcd display
Lcd_Cmd(_LCD_CURSOR_OFF); // Lcd Cursor off
Lcd_Out(1,1,"RPM: ");
Lcd_Out(2,5,"Circuit");
delay_ms(2); // 2 second delay
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,3,"adil elsadiq");
Lcd_Out(2,1,"MINA TECHNOLOGY");
delay_ms(2);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"RPM ");
# DEFINE RPM;
#DEFINE RPM LIB;
RPM=RPS*60;
rps=360*60
please give me very simple code exampleI agree, your objective isn't clear and your comments are almost non-existent.
If you are simply counting instruction cycles while the 'SW' inputs are active, the count will be almost entirely determined by the clock speed. Also note that the code for checking the pulse length is blocking execution of the rest of the program.
If you are trying to measure pulses per second to convert it to RPM, a much better way is to use one of the timers to generate interrupts and use those to control the counting periods.
As you seem to be using a PIC with at least four ports, it should also have timers and interrupt capabilities.
Brian.
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?