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

Timer1 Interrupt Issue

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



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

Timer1 Interrupt Issue
PostPosted: Thu Mar 05, 2009 6:09 pm     Reply with quote

Hi,
I am learning how to use Timer1 interrupt. The below is my code. I found out whatever an input value for set_timer1() is, I always get an around 570ms interrupt. Could anybody point out what I did wrong. The processor is PIC16F689 and the external system clock is 3686400 cystal.

Code:

#include <16F689.h>
#include <stdio.h>
#include <stdlib.h>

#use delay(clock=3686400, crystal)
#use rs232(baud=115200, xmit=PIN_B7, rcv=PIN_B5)
#fuses XT, NOWDT, PUT, MCLR, NOPROTECT, NOCPD, NOBROWNOUT, NOIESO, NOFCMEN

#define input_value  0xA000

volatile unsigned int8 value=0;

#INT_TIMER1
void TIMER1_ISR(void)
{
  output_bit(PIN_C3, value);
  value = ~value;
}

void main()
{
  set_timer1([b]input_value[/b]);
  setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
  enable_interrupts(INT_TIMER1);
  enable_interrupts(global);
 
  while(1);
}


Thanks!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 05, 2009 6:50 pm     Reply with quote

You never reload the timer in the ISR. Therefore, the timer finishes
counting from your initial load value in main(), it rolls over to 0. All
future interrupts will be based upon the full count, which 65536.

There is no "auto reload" capability in Timer1. You have to do it manually
with a line of code in the ISR.
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Thu Mar 05, 2009 7:31 pm     Reply with quote

Thanks!!! it works to add set_timer_1() in isr.
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