CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

CCP Problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
diego
Guest







CCP Problem
PostPosted: Wed Feb 22, 2006 12:51 pm     Reply with quote

I have a problem with the compare function when trying to measure the RPM's of a motor.
The idea is to measure the period of the signal of the speed sensor.
So, when an interruption occurs, we start to count the time (by clearing TMR1),
and when the second rising edge interrupts we read the value of CCP_1.

Comparing my results against a commercial RPM meter, I found an important diference,
so I start to debug the proyect.

My results are that the value of CCP_1 variable at the time of the CCP interruption are
smaller that the real signal being measured.

To better ilustrate this, I run a simulation in MPLAB, with a signal of 60 Hz in the CCP input,
for this frecuency, the period in microseconds are ( 1 / 60 ) * 1000000 = 16666,66.

We try two options to read the period inside of the ISR:
period = get_timer1();
or
period = ccp_1;

The values at the moment of interruption are:

if period = get_timer1();
period 16667

if period = ccp_1;
period 16625

When calculate the RPM (for a 60 Hz input they are 60 * 60 = 3600), we have:

1/16667 * 60000000 = 3599.92 RPM

or with the CCP_1 value, 1/16625 * 60000000 = 3609.02 RPM


The difference is bigger when the frecuency of the input grows, at 120 Hz (7200 RPM):

if period = get_timer1();
period = 8334 => 1/8334 * 60000000 = 7199.42 RPM

if period = ccp_1;
period = 8292 => 7235.89 RPM

If you need more information (schematics, complete code, etc), please contact us.

Thank's in advance for your time.

Best Regard's
Diego Caraballo

Code:


#include <16F873A.h>
#device adc=8

#FUSES NOWDT                  //No Watch Dog Timer
#FUSES HS                     //High speed Osc (> 4mhz)
#FUSES PUT                    //Power Up Timer
#FUSES NOPROTECT              //Code not protected from reading
#FUSES NODEBUG                //No Debug mode for ICD
#FUSES noBROWNOUT               //Reset when brownout detected
#FUSES NOLVP                  //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                  //No EE protection
#FUSES NOWRT                  //Program memory not write protected

#use delay(clock=4000000)
#use rs232(baud=14400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


int32 periodo;
float rpm;
float frec;
int32 sumador = 0;
int sumador_index;
short measuring;
short ready;

#int_CCP1
CCP1_isr()
{
 if (!measuring)
  {
   measuring = true;
   set_timer1(0);
  }
 else if (measuring)
  {
   //we disable one of these:
   periodo = get_timer1();
   //periodo = ccp_1;
   ready = true;
   measuring = false;
  }

}


void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_CAPTURE_RE);
   setup_ccp2(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   enable_interrupts(INT_CCP1);
   enable_interrupts(GLOBAL);

 delay_ms(500L);

 measuring = false;
 ready = false;

 while(true)
 {
 }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 1:41 pm     Reply with quote

Normally this is done by subtracting the CCP values that you get
from two sequential interrupts while in CCP Capture mode.

Do a search of the forum for "Tachometer". There are several
articles on it:

http://www.ccsinfo.com/forum/viewtopic.php?p=2528
http://www.ccsinfo.com/forum/viewtopic.php?t=17806
http://www.ccsinfo.com/forum/viewtopic.php?t=906
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group