maniac_xox
Newbie
I am using a PIC18F452 microcontroller in MPLAB X, everything is working great when I work on examples that require smaller or no preload at all, I do not understand why that is the case, is there a limit to the TMR0L?
Hello please help asap,
my specific case I have:
4MHz crystal -----> 1 / (4MHz / 4) = 1MHz timer
I Need to make interrupts happen after 4 seconds
1MHz * 4s = 4,000,000 counts
Therefore i decided to use a 16-bit with a 1:64 Prescaler setting.
4,000,000 / 64 = 62,500 counts
The difference would therefore be: 65,536 - 62,500 = 3,036 as preload
the problem arises when I use a breakpoint and stopwatch in MPLAB X IDE to know if the program stops at that specific time ( 4 seconds ) when I initialise the timer function, but the interrupt just never happens.
Any solution to this? it does not work in PROTEUS either, i have tried before understanding the reason being the preloading, after testing it out with different examples.
APPENDIX (code is in c language):
Hello please help asap,
my specific case I have:
4MHz crystal -----> 1 / (4MHz / 4) = 1MHz timer
I Need to make interrupts happen after 4 seconds
1MHz * 4s = 4,000,000 counts
Therefore i decided to use a 16-bit with a 1:64 Prescaler setting.
4,000,000 / 64 = 62,500 counts
The difference would therefore be: 65,536 - 62,500 = 3,036 as preload
the problem arises when I use a breakpoint and stopwatch in MPLAB X IDE to know if the program stops at that specific time ( 4 seconds ) when I initialise the timer function, but the interrupt just never happens.
Any solution to this? it does not work in PROTEUS either, i have tried before understanding the reason being the preloading, after testing it out with different examples.
APPENDIX (code is in c language):
Code:
#include "LED.h"
#include "Timer.h"
#include "Button.h"
#define _XTAL_FREQ 4MHZ
void InitialiseTimer(void) // 4 seconds TIMER
{
T0CONbits.TMR0ON = 1; //timer enabled
T0CONbits.T08BIT = 0; // 16-bit set
T0CONbits.T0CS = 0; // internal clock
T0CONbits.T0SE = 1; // high to low transition
T0CONbits.PSA = 0; // 1:64 prescale enabled (101)
T0CONbits.T0PS2 = 1;
T0CONbits.T0PS1 = 0;
T0CONbits.T0PS0 = 1;
}
void main(void)
{
InitialiseLED(); // this is from another header file
InitialiseTimer();
while(1) // loop to check every run stops at the same time ( 4 seconds)
{
if(TimerOverflow())
{
LEDToggle(LED1);
}
}
}
Last edited by a moderator: