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.

PIC pulse counter code help

Status
Not open for further replies.

dope40

Member level 4
Joined
Oct 3, 2011
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bulgaria
Activity points
1,777
Hi , i need help with the code for my rev counter , since i just started working with PIC's i don't quite know what to write. What i need my PIC to do is :

1. Count the number of incoming pulses in 1/10 second ( number of rev in 1/10 sec.)
2. Multiply that number by 600 (so i can get the number of rev/min)
3. Display it on 16x2 lcd ( Rev/min : xxxxxx )

If someone can give me any clue , it would be great.
 

Let us take one step at a time..


1. First, you will probably need to configure some sort of counter... What model of PIC are you using?
Once you configure the counter you say something like
Code:
//where x is the count that equals 1/10 seconds
//"pin" is pin on which the incoming signal is
//"already_counted" is a variable used to make sure a high pulse is only counted once
//"count" is the count that you are keeping
while (count < x)
{
       if (pin == 1 && already_counted == 0)
      {
         count = count + 1;
         already_counted = 1;
      }
      if (pin == 0 && already_counted == 1) 
      {
            already_counted = 0;
      }
      if (pin == 0 && already_counted == 0) {}
      if (pin == 1 && already_counted == 1) {}
      else
      {
      }
}

2. Now that you have that number you simply say...
Code:
//where "final_value" is the integer in which you will be storing your results.
final_value = 600 * count;

3. The last question is a bit more complex. How you go about displaying data on an LCD depends on a few things..
a. What protocol does the LCD use to communicate? SPI, UART, I2C, etc.
b. Does the LCD require a "library" so to speak, or can you simply send it commands or characters to display.
c. What is the size of the LCD, how many character blocks and lines does it have? (So you can know where to display things).
Once you answer these question we might be able to offer a bit more assistance. Also, if you post your code we would be more than happy to help you.

Regards,
Willis
 

many microcontrollers have an "interrupt on change" detection facility where changes in level of a digital IO pin cause an interrupt
**broken link removed**
using a timer you can then count interrupts over a period, e.g. 0.1 of a second
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top