View previous topic :: View next topic |
Author |
Message |
Khansokhua
Joined: 06 Nov 2021 Posts: 92
|
PIC16F877A int_timer1 |
Posted: Mon Nov 29, 2021 4:36 pm |
|
|
Code: | #include <Timerlar.h>
#fuses XT
#use delay(clock=4M)
int i=0;
int j=0;
const int segment[16]= {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7C,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
#int_timer1
void timer_say()
{
set_timer1(63036);
if(i==50)
{
i=0;
output_c(segment[j]);
j++;
if(j==16)
{
j=0;
}
}
i++;
}
void main()
{
set_timer1(63036);
output_a(0x02);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
enable_interrupts(int_timer1);
enable_interrupts(GLOBAL);
while(1);
}
|
Hi
I measured 0.020032s the overflow time but I calculated for exact value 0.02 s. Which point I have been missing? I wonder why showed up this ? Respects |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Mon Nov 29, 2021 4:59 pm |
|
|
Did you account for the time it takes from when the interrupt is triggered until you execute your set_timer1 command? |
|
|
Khansokhua
Joined: 06 Nov 2021 Posts: 92
|
|
Posted: Tue Nov 30, 2021 3:26 am |
|
|
Actually, I measured set_timer1's value "4" before it's been set "63036" |
|
|
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
Posted: Tue Nov 30, 2021 4:01 am |
|
|
Take a look into the ASM file (lst). It takes a few cycles to save registers before set_timer is executed.
(I also would recommend to change the "overflow-counters" if (x==yy) into if (y>=yy) for best practise..) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 30, 2021 5:53 am |
|
|
Remove the line shown in bold below:
Quote: |
void timer_say()
{
set_timer1(63036);
if(i==50)
{
i=0;
output_c(segment[j]);
j++;
if(j==16)
{
j=0;
}
}
i++;
}
|
Replace the line in bold with this line:
Code: | set_timer1(PRELOAD + get_timer1());
|
Put this line above the #int_timer1 line:
Code: | #define PRELOAD 63036 |
|
|
|
|