SJ2013
Newbie level 3
- Joined
- Aug 22, 2013
- Messages
- 3
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Activity points
- 19
Hello all,
I am trying to generate timer0 based interrupt at a rate of 360Hz (2.777ms). This is the CODE I am using. But when I monitor Pin_b1, the ON time is 2.20ms, shouldnt it be 2.777ms?
I am trying to generate timer0 based interrupt at a rate of 360Hz (2.777ms). This is the CODE I am using. But when I monitor Pin_b1, the ON time is 2.20ms, shouldnt it be 2.777ms?
Code:
#include <18F4680.h>
#fuses HS, NOPROTECT, PUT, BROWNOUT, NOWDT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#INT_TIMER0
void timer_irq()
{
set_timer0(58591); //360Hz = 20*10^6/(4*(65536-n)*2)
output_toggle(pin_b1);
}
void main()
{
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(TRUE)
{
//TODO: User Code
}
}
Last edited: