|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 23, 2007 5:54 pm |
|
|
I ran your program (shown below) on a PicDem2-Plus and I got this:
Quote: |
61622
63899
63899
63899
63899
63899
63900
63900
63900
63899
|
Code: | #include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void main(void)
{
int16 k;
int8 i;
for(i = 0; i < 10; i++)
{
setup_timer_1(T1_DISABLED);
set_timer1(32768);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
delay_ms(950);
setup_timer_1(T1_DISABLED);
k = get_timer1();
printf("%lu\n\r", k);
}
} |
|
|
|
Imanjl
Joined: 15 Nov 2004 Posts: 42
|
|
Posted: Sat Feb 24, 2007 2:59 am |
|
|
rnielsen wrote: | If you need accurate timing then you will need to allow the timer to roll over, causing an interrupt, and have that flag whatever you want done. |
I wrote a new program without using get_timer1(); at this time when timer overflows(1s) it generates an interrupt .but still 1 second isnt accurate . This program generates 1 second in about 850-950mS .
Code: | #int_TIMER1
TIMER1_isr(){
set_timer1(32768);
count++;}
void main(void)
{int16 k;
int8 i;
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
set_timer1(32766);
loop:
...
...
printf("\ntimer1=%lu\n\r",count);
...
goto loop ;} |
hi pcm programmer ,ur result shows that the program works fine on Picdem2 cause (63900-32768)*30.5us=949ms .Maybe there is something wrong with my hardware according to microchip refrence manual,32.768 need two 33pf capacitors I use 30pf for c1 and c2 but I dont think it affects the result so much ,whats the Picdem2 caps value for timer1 ?
Besides the pic is on the bread board :
Quote: | Design Tips
2. You should ensure the your layout uses good PCB layout techniques so that noise does not couple onto the Timer1 oscillator lines. |
|
|
|
|
|
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
|