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

Set timer1 offset value

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



Joined: 03 Apr 2019
Posts: 2

View user's profile Send private message

Set timer1 offset value
PostPosted: Wed Apr 03, 2019 10:53 am     Reply with quote

Hello,
I'm having trouble setting the values of TMR1L and TMR1H in pic 16F648A.
Here is my code:
Code:


#include <programa.h>
#include "flex_lcd.c"

//DEFININDO OS BOTOES
#define BTN_ENTER PIN_B6 
#define BTN_MAIS PIN_B5 
#define BTN_MENOS PIN_B4 

#int_TIMER1
void  TIMER1_isr(void)
{
   output_toggle(PIN_B3);
}

void main()
{
 
   // t= 1*2*(65536-15536)
   setup_timer_1 (T1_INTERNAL|T1_DIV_BY_2); //131 ms overflow
   set_timer1(0x3CB0);
   enable_interrupts (int_TIMER1);
   enable_interrupts (GLOBAL);
   
   
   lcd_init (); // Always call this first.
   
   lcd_putc ("\fHello World\n");
   
   while (TRUE)
   {
    ...
   }
}


Changing the code to set the value of TMR1L and TMR1H in the interrupt, it works. But, I'd like to set the offset before the interruption
Code:


#int_TIMER1
void  TIMER1_isr(void)
{
   set_timer1(get_timer1() + 0x3CB0);
   output_toggle(PIN_B3);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 03, 2019 3:07 pm     Reply with quote

I'm not sure what you mean. Are you thinking there is a register that
allows you to set the reload value for Timer1 ? There isn't one.
You always have to manually reload it, if you want to start at a higher
value than 0x0000.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Apr 04, 2019 1:33 am     Reply with quote

On the basic PIC's (16/18), the only timer that supports a programmable
reset value, is Timer2. Al the others count from zero, to 255, or 65535.

The standard reload code in the interrupt, would be something like:
Code:

#int_TIMER1
void  TIMER1_isr(void)
{
   set_timer1(get_timer1()+0x3CB0);
   output_toggle(PIN_B3);
}


Your need to do it as an addition, otherwise any counts between the
interrupt 'event', and where you do the reset, will be lost. You will lose
a little time anyway (the addition takes time, and the prescaler gets
reset when the timer is loaded). However very small.
luizsergiorf



Joined: 03 Apr 2019
Posts: 2

View user's profile Send private message

PostPosted: Thu Apr 04, 2019 2:20 pm     Reply with quote

Hello,

Now I understand, Thank you all for help.
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