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.

[General] How to add rpm to my counter ?

Status
Not open for further replies.

ana_cont

Junior Member level 2
Junior Member level 2
Joined
Jun 15, 2020
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
11
Activity points
128
hi 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;

                 }



}
}
 
Last edited by a moderator:

i have no idea
but if you want a useful response, please provide the part number of the PIC,
a schematic of the circuit it is part of, and a description of what ever is rotating
and how the information goes to the PIC

also, anything wlse that would be useful to understand the question and the purpose
of the circuit

getting things to work porperly is not just a question of software
 

I 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.
 

Hi
hi 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;

                 }



}
}
hi thank you i will send schematic of pic16f887 and use two digital external clock pulse for count and pulse 2 for meassure rpm
 

this code about control angles by use count pitches of gear 360 tooth and also there another gear meassure from it the speed rpm gear of 120 teeth itry this code above which it give me the angles and good out put as you see but rpm faile to be added imake sw for angles sw2 =rpm this fiale how??? to do this thank you very much
 

C-like:
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
 
Last edited by a moderator:

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
 

Hi, all matter about camshaft and crank shaft please helpme
 

how to encode camshaft to get back to after shutdown to same position by using c program codes example and hall effect sensor thank you
 

how to caculate rpm and also configure tmr0,tmr1 ,cnt,clr ,start,stop,enable,interrupt,reset etc in mikro c please give me example code sources
--- Updated ---

is this right unsigned int_rpm; rps=1*r;
rpm=n*60/1r pulses;
where n is pulse of frequency
 
Last edited:

I 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.
please give me very simple code example
--- Updated ---

how to use two timer to get counter pulse and speed priod in mikro c just example tank you
--- Updated ---

HI
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. yes this is right jsut give me example simple code
 
Last edited:

Hi,

All depends on your requirements.
And I miss them.
We don't know
* what PMM range you think about.
* And how the RPM signal comes to your PIC.
* how often you want to measure/calculate the RPM.
* and what you want to do with this RPM data.

And I don't see any effort if you. I guess there are more than 100.000 RPM measurement projects in the internet. Ideas, schematics, descriptions, code ... even videos.
Why don't you tell us which document you read, which internet sites you visited?
Why don't you draw a simple picture?

Klaus
 

hi ineed rpm for engine from 0 up to 3000 this is my range if any one have example use one of the timers to generate interrupts and use those to control the counting periods. yes this is right jsut give me example simple code . microcntroller pic16f877a have tmr0,tmr1,tmr2 thank you
 

Hi,

excuse me - I don´t want you to take this as rude:
But there are million examples in the internet. Are you too lazy to just do a search and go trough a couple of them?
Is it asking too much for an almost complete description from your side or a simple pencil_and_paper sketch?

A forum is not meant that others do an internet search for you nor that others write code for you...

Show us what you have done the past 6 months.

Klaus
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top