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

PIC16F877A int_timer1

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



Joined: 06 Nov 2021
Posts: 88

View user's profile Send private message

PIC16F877A int_timer1
PostPosted: Mon Nov 29, 2021 4:36 pm     Reply with quote

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: 288

View user's profile Send private message

PostPosted: Mon Nov 29, 2021 4:59 pm     Reply with quote

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: 88

View user's profile Send private message

PostPosted: Tue Nov 30, 2021 3:26 am     Reply with quote

Actually, I measured set_timer1's value "4" before it's been set "63036"
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 30, 2021 4:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 30, 2021 5:53 am     Reply with quote

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
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