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

measure pulse width use timer1

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



Joined: 08 Oct 2010
Posts: 10

View user's profile Send private message

measure pulse width use timer1
PostPosted: Fri Oct 08, 2010 7:13 pm     Reply with quote

Hi. I want to measure pulse width use timer1, but I have a problem.
Pulse at pin CCP1, CCP2 then result be shown in LCD. But the result is 0.
Code as below:
Code:

#include <16F877.h>
#use delay(clock=10000000)
#fuses HS,NOWDT
#include <lcd.c>
  #define LCD_ENABLE_PIN  PIN_D0                                   
    #define LCD_RS_PIN      PIN_D1                                   
     #define LCD_RW_PIN      PIN_D2                                   
     #define LCD_DATA4       PIN_D4                                   
     #define LCD_DATA5       PIN_D5                                   
     #define LCD_DATA6       PIN_D6                                   
     #define LCD_DATA7       PIN_D7


int overflow_count;
unsigned int32 start_time, end_time;
int32 pulse_ticks;

#int_TIMER1
void TIMER1_isr()
{
   ++overflow_count; //increment whenever an overflow occurs
}

#int_CCP2
void CCP2_isr()
{
   end_time = CCP_1;   //read captured timer ticks
   start_time = CCP_2;   //read captured timer ticks
   //check for pulse time (in ticks) accounting for anyoverflow that may have occurred
   pulse_ticks = (0x10000 * overflow_count) - start_time + end_time;
     overflow_count = 0;  //clear overflow counts

}

void main() {
   setup_ccp1(CCP_CAPTURE_FE);
    setup_ccp2(CCP_CAPTURE_RE);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);//set timer1 to run at system clock/4
   enable_interrupts(INT_TIMER1);  //unmask Timer1 overflow interrupt
   enable_interrupts(INT_CCP2);    //unmask capture event interrupt
   enable_interrupts(global);      //enable all unmasked interrupts
   //set_timer1(0);
   while(1){
    LCD_init();
  printf(lcd_putc,"\rdo rong: %u", pulse_ticks);
    //as usual, the main() function does nothing
   }
}
   

thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 8:05 pm     Reply with quote

Try using this CCS example program. The input signal must be connected to both pins C1 and C2.
Quote:

c:\program files\picc\examples\ex_ccpmp.c


If that doesn't work, then try the Pulse program in this thread.
Use the first program, which is for 16F PICs.
http://www.ccsinfo.com/forum/viewtopic.php?t=41877
agreement



Joined: 08 Oct 2010
Posts: 10

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 8:29 pm     Reply with quote

thanks, but i have tryed the example but it still not work.:(
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 8:44 pm     Reply with quote

Describe the input signal. What is the frequency ? What device makes
the signal ? What's the manufacturer and part number ? What is the
expected duration of the pulses (high level time duration) ? What are the
high and low level output voltages of the signal from the device (Voh and Vol) ?
agreement



Joined: 08 Oct 2010
Posts: 10

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 2:56 am     Reply with quote

PCM programmer wrote:
Describe the input signal. What is the frequency ? What device makes
the signal ? What's the manufacturer and part number ? What is the
expected duration of the pulses (high level time duration) ? What are the
high and low level output voltages of the signal from the device (Voh and Vol) ?

I simulate it by Proteus. Pulse is provided by generator pulse. i have tryed with many frequency but the result still not change. i have attached the schematic file in: http://www.mediafire.com/?hgbm580t1k8aedt

thanks so much!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 1:27 pm     Reply with quote

You may have a Proteus bug, or a configuration problem.
I don't have Proteus, so I can't do anything more on your problem.
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