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 16F877A for rotation counter programme. i need it badly.

Status
Not open for further replies.

Adrian HZW

Newbie level 4
Joined
Jan 17, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
PIC 16F877A

Hi,
I have a problem where i don't how to write a program for my rotation counter.
My system is a rotation counter, It count decrementally. does anyone here can help me on the programming part?

Thank you.
 

You question is very vague. Are you simply using the PIC for counting something?

Keith
 

Keith,

No, im not simply using PIC, i only provided with PIC16F877A for create rotation counter project. and the sensor i used is magnetic sensor.

Adrian
 

If you are simply counting then you can use one of the timer modules which can count from an external pin. If you want to measure pulse rate then the capture mode may be more appropriate. Do you have a schematic? You will need to ensure you have a clean input signal to prevent miscounting.

Keith
 

Is your magnetic sensor a hall effect sensor or reed switch type? If the sensor gives pulse outputs then feed that pulse to RB0/INT pin and use PORTB interrupt to get the values of rotations. If one pulse is given for every rotation then interrupt occurs for every rotation, so, no. of interrupts is the no. of rotations.
 

hi jayan,

my magnetic sensor will generate 1 output signal when it detects metal passing by.
and my condition which i would like to declare is

// define
#define sensor D1
#define Led G D2
#define Led Y D3
#define Led R D4
#define Push Button D0

is this correct? and im using PIC C compiler s/w.


-adrian-
 

If the sensor gives you a pulse, you can use the CCP module for a precise value.
Made a frequencimeter with the CCP module in this post.
Modified to give the RPM.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Using 20MHz clock
#include <16F877.h>
#use delay(clock=20M)
 
boolean a;
int32 rise, rise2, value;
float freq, period, rpm;
 
#int_ccp1
void isr2()
{
  rise=CCP_1; 
} 
 
#int_ccp2
void isr()
{
  rise2 = CCP_2;
  value = rise2 - rise;
  a=1;
} 
void main()
{
   #priority ccp2,ccp1
   setup_ccp1(CCP_CAPTURE_RE); // Configure CCP1 to capture rise
   setup_ccp2(CCP_CAPTURE_RE); // Configure CCP2 to capture rise
   setup_ccp2(CCP_CAPTURE_DIV_4);
   setup_timer_1(T1_INTERNAL); // Start timer 1
   enable_interrupts(INT_CCP2); // Setup interrupt on falling edge
  enable_interrupts(INT_CCP1); // Setup interrupt on falling edge
  enable_interrupts(GLOBAL);
  a=0;
  while(TRUE) 
  {
    if(a==1)
    {
      period=value/5; //Doesn't need to divide if 4MHz
      if(period<1000)
      {
        freq=1000000/period;
        freq=freq/1000;
        rpm=freq*60;
      }
      else
      {
        freq=1000000/period;
      }
 
      a=0;
    } 
  }
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top