I tried the below code expecting a Timer rollover every 200us with:
fosc/4 = 1MHz = 1us
prescaler = 256
TMR0 = 256 - 200 = 56
but I'm getting 21.8us and even changing the prescaler to 2 it remains 21.8us. The code is wrong but I can't see where.
Anyone see what could be the problem?
fosc/4 = 1MHz = 1us
prescaler = 256
TMR0 = 256 - 200 = 56
but I'm getting 21.8us and even changing the prescaler to 2 it remains 21.8us. The code is wrong but I can't see where.
Anyone see what could be the problem?
Code:
#include <stdio.h>
#include <pic16f1503.h>
#include <stdlib.h>
#include <xc.h>
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = ON // Clock Out Enable (CLKOUT function is enabled on the CLKOUT pin)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = ON
void delay(void);
void main()
{
OSCCONbits.SCS = 0b10;
OSCCONbits.IRCF = 0b1101;
TRISCbits.TRISC3 = 0;
OPTION_REGbits.TMR0CS = 0;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS = 0b000;
while(1)
{
//LATCbits.LATC3 = 0;
LATCbits.LATC3 = !LATCbits.LATC3;
delay();
}
}
void delay()
{
TMR0 = 56;
INTCONbits.T0IE = 1;
while (INTCONbits.T0IF == 0)
{
;
}
}