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 CCS Technical Support

problems with Capture mode

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



Joined: 06 Oct 2004
Posts: 8

View user's profile Send private message Send e-mail MSN Messenger

problems with Capture mode
PostPosted: Fri Oct 22, 2004 10:02 am     Reply with quote

here is my code

Code:

#include <16F877.h>

#fuses HS, NOLVP, NOWDT, NOPROTECT
#use delay (clock=20000000)

#define use_portb_lcd
#include <lcd.c>

int16 time;

#INT_CCP1
void compare_isr()
{
   time = get_timer1();
   printf(lcd_putc, "\fCompare Set Int.");
   delay_ms(1000);
   printf(lcd_putc, "\nTimer1: %lu us", time);
   delay_ms(1000);
   disable_interrupts(GLOBAL);
   disable_interrupts(INT_CCP1);
}

void main()
{
   lcd_init();

   setup_ccp1(CCP_COMPARE_INT);
   setup_timer_1(T1_INTERNAL);

   enable_interrupts(INT_CCP1);
   enable_interrupts(GLOBAL);

   set_timer1(0);
   CCP_1 = 500;      // 500 = (100*10e-6) * (20e6 / 4)

   while(1);
}


and the output is

Compare Set Int.
Timer1: 538 us

but sometimes the output is

Compare Set Int.
Timer1: 37 us

or

Compare Set Int.
Timer1: 40 us

I don't why it is
the questions are
1. why are the output diffrent?
2. how do these numbers 538, 37, 40 come?
3. CCP_1 = 500; // 500 = (100*10e-6) * (20e6 / 4) means?

thank you in advance
Saroch
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 22, 2004 12:54 pm     Reply with quote

I assume this is some sort of a test program for the CCP compare mode.
There are quite a few comments to make, but I'll skip those and comment
on what is probably causing the problem:


void main()
{
lcd_init();

setup_ccp1(CCP_COMPARE_INT);
setup_timer_1(T1_INTERNAL);

enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL); // This line says "Go ! (start running) "

But in the lines below, after you've enabled interrupts,
you're still setting up parameters. These should all have
been setup before you gave the "Go" command.

set_timer1(0);
CCP_1 = 500; // 500 = (100*10e-6) * (20e6 / 4)

while(1);
}
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