|
|
View previous topic :: View next topic |
Author |
Message |
boulder
Joined: 15 Mar 2008 Posts: 53
|
Timer1 Interrupt Issue |
Posted: Thu Mar 05, 2009 6:09 pm |
|
|
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
|
|
Posted: Thu Mar 05, 2009 6:50 pm |
|
|
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
|
|
Posted: Thu Mar 05, 2009 7:31 pm |
|
|
Thanks!!! it works to add set_timer_1() in isr. |
|
|
|
|
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
|