|
|
View previous topic :: View next topic |
Author |
Message |
saroch
Joined: 06 Oct 2004 Posts: 8
|
problems with Capture mode |
Posted: Fri Oct 22, 2004 10:02 am |
|
|
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
|
|
Posted: Fri Oct 22, 2004 12:54 pm |
|
|
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);
} |
|
|
|
|
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
|