Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Pic microcontroller projecta

Pic microcontroller projecta

Quick Overview

Category
Uncategorized
Language
Total members
35
Total events
0
Total discussions
2
Total views
2K
Total albums
0

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

ana_cont

Newbie level 4
Joined
Jun 15, 2020
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
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:

wwfeldman

Advanced Member level 2
Joined
Jan 25, 2019
Messages
693
Helped
169
Reputation
338
Reaction score
167
Trophy points
43
Activity points
5,025
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
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,196
Helped
4,690
Reputation
9,395
Reaction score
4,443
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
121,205
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.
 

ana_cont

Newbie level 4
Joined
Jun 15, 2020
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
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
 

ana_cont

Newbie level 4
Joined
Jun 15, 2020
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
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
 

ana_cont

Newbie level 4
Joined
Jun 15, 2020
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
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:

ana_cont

Newbie level 4
Joined
Jun 15, 2020
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
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
 

ana_cont

Newbie level 4
Joined
Jun 15, 2020
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
Hi, all matter about camshaft and crank shaft please helpme
 

ana_cont

Newbie level 4
Joined
Jun 15, 2020
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
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
 

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top