Hello All
I am currently using interrupts with the pic18f2520 TMR0 timer in order to obtain delays. I am trying to obtain as large frequency as possible for the timer in order to be able to set the smallest possible delays. If my understanding is correct, if I have a 10 MHZ external clock and i set the starting val of TMR0 = 255, and PRESCALER to 1:1 I should be able to obtain clock pulses every 100 ns, thus allowing delays remotly resembling this value(<1us is close enough). However for some reason when i set the TMR =255 and scaler to 1:1 I do not see any output pulses, same case for scaler 1:2, only when i set it to around 1:4 i start to see pulses but they are at about 35-40 us and thats not even close to my desired frequency(period~1us).This is my code and maybe one of you can find what I should change in order to adjust this.
Thanks
//--------------------------------------------------------------------
Code:
unsigned cnt;
void interrupt() {
cnt++;
TMR0L = 254;
INTCON = 0x20; // Set T0IE, clear T0IF
}
void main() {
ADCON1 = 0x0F;
T0CON = 0b11000011; // prescaler 1:16
TRISB = 0;
PORTB = 0xFF;
TMR0L = 255;
INTCON = 0xA0;
cnt = 0;
do {
if (cnt == 1) {
PORTB = ~PORTB; // LEDs
cnt = 0;
} while(1);
}
I am currently using interrupts with the pic18f2520 TMR0 timer in order to obtain delays. I am trying to obtain as large frequency as possible for the timer in order to be able to set the smallest possible delays. If my understanding is correct, if I have a 10 MHZ external clock and i set the starting val of TMR0 = 255, and PRESCALER to 1:1 I should be able to obtain clock pulses every 100 ns, thus allowing delays remotly resembling this value(<1us is close enough). However for some reason when i set the TMR =255 and scaler to 1:1 I do not see any output pulses, same case for scaler 1:2, only when i set it to around 1:4 i start to see pulses but they are at about 35-40 us and thats not even close to my desired frequency(period~1us).This is my code and maybe one of you can find what I should change in order to adjust this.
Thanks
//--------------------------------------------------------------------
Code:
unsigned cnt;
void interrupt() {
cnt++;
TMR0L = 254;
INTCON = 0x20; // Set T0IE, clear T0IF
}
void main() {
ADCON1 = 0x0F;
T0CON = 0b11000011; // prescaler 1:16
TRISB = 0;
PORTB = 0xFF;
TMR0L = 255;
INTCON = 0xA0;
cnt = 0;
do {
if (cnt == 1) {
PORTB = ~PORTB; // LEDs
cnt = 0;
} while(1);
}