amroman2006
New Member
Hello all
-I'm trying to build some small projects to test timers and oscillator settings
- My project now is very simple , just toggeling LED status every 1s
- Issue is Timer0 is not operated correctly , sometimes LED is kept on , sometimes kept off and
sometimes LED is blinking at arbitary rate
- My Hardware is very simple, just LED connected to RB0 and Crystal 4M connected
- I'm using my Fosc from PLL , 4M connected to drive PLL , and PLLPostscalar /3 is used
- So based on that , Fosc that will be input to TMR0 is 32M (96/4)
- This is my Code :-
####################################################################################################
#include <htc.h>
// PIC 18F4550 fuse configuration:
// Config word 1 (Oscillator configuration)
__CONFIG(1, USBPLL & IESODIS & FCMDIS & HSPLL & CPUDIV2 & PLLDIV1);
// Config word 2
__CONFIG(2, VREGEN & PWRTDIS & BOREN & BORV20 & WDTDIS & WDTPS32K);
// Config word 3
__CONFIG(3, PBDIGITAL & LPT1DIS & MCLREN);
// Config word 4
__CONFIG(4, XINSTDIS & STVREN & LVPDIS & ICPORTDIS & DEBUGDIS);
// Config word 5, 6 and 7 (protection configuration)
__CONFIG(5, UNPROTECT);
__CONFIG(6, UNPROTECT);
__CONFIG(7, UNPROTECT);
int Amr;
main()
{
PORTA = 0x00;
PORTB = 0x00;
TRISB = 0x00;
IPEN = 0;
T0CON = 0b11000100;
INTCON = 0b11100000;
INTCON2 = 0b11110000;
Amr = 0;
TMR0L = 5;
while(1)
{
if (Amr == (1000) )
{
Amr = 0;
PORTB =~ PORTB ;
}
}
}
// LOW priority interrupt
void interrupt low_priority lowISR()
{
TMR0L = 5;
TMR0IF = 0;
Amr = Amr + 1;
} // end of LO interrupt
####################################################################################################
- The Result that LED is not blinking correctly as expected ,it seems Timer0 is not stable, and i don't know reason
- When I tried to change the PLLPOSTscalar to /4 ( Fosc = 24M ) and adjust variables ( Amr to 750) to
sustain 1s period , issue was completely disappear !
- so I Just need to know , does TMR0 for PIC18F4550 has Fosc limits , do i have to follow any guidlines when uc Fosc
reaches high frequency such Fosc 32M ?
- Is there's any hardware practices i should follow to eliminate issue
- Is there's any errors in my Code ?
- Thanks to help me regarding this issue
-I'm trying to build some small projects to test timers and oscillator settings
- My project now is very simple , just toggeling LED status every 1s
- Issue is Timer0 is not operated correctly , sometimes LED is kept on , sometimes kept off and
sometimes LED is blinking at arbitary rate
- My Hardware is very simple, just LED connected to RB0 and Crystal 4M connected
- I'm using my Fosc from PLL , 4M connected to drive PLL , and PLLPostscalar /3 is used
- So based on that , Fosc that will be input to TMR0 is 32M (96/4)
- This is my Code :-
####################################################################################################
#include <htc.h>
// PIC 18F4550 fuse configuration:
// Config word 1 (Oscillator configuration)
__CONFIG(1, USBPLL & IESODIS & FCMDIS & HSPLL & CPUDIV2 & PLLDIV1);
// Config word 2
__CONFIG(2, VREGEN & PWRTDIS & BOREN & BORV20 & WDTDIS & WDTPS32K);
// Config word 3
__CONFIG(3, PBDIGITAL & LPT1DIS & MCLREN);
// Config word 4
__CONFIG(4, XINSTDIS & STVREN & LVPDIS & ICPORTDIS & DEBUGDIS);
// Config word 5, 6 and 7 (protection configuration)
__CONFIG(5, UNPROTECT);
__CONFIG(6, UNPROTECT);
__CONFIG(7, UNPROTECT);
int Amr;
main()
{
PORTA = 0x00;
PORTB = 0x00;
TRISB = 0x00;
IPEN = 0;
T0CON = 0b11000100;
INTCON = 0b11100000;
INTCON2 = 0b11110000;
Amr = 0;
TMR0L = 5;
while(1)
{
if (Amr == (1000) )
{
Amr = 0;
PORTB =~ PORTB ;
}
}
}
// LOW priority interrupt
void interrupt low_priority lowISR()
{
TMR0L = 5;
TMR0IF = 0;
Amr = Amr + 1;
} // end of LO interrupt
####################################################################################################
- The Result that LED is not blinking correctly as expected ,it seems Timer0 is not stable, and i don't know reason
- When I tried to change the PLLPOSTscalar to /4 ( Fosc = 24M ) and adjust variables ( Amr to 750) to
sustain 1s period , issue was completely disappear !
- so I Just need to know , does TMR0 for PIC18F4550 has Fosc limits , do i have to follow any guidlines when uc Fosc
reaches high frequency such Fosc 32M ?
- Is there's any hardware practices i should follow to eliminate issue
- Is there's any errors in my Code ?
- Thanks to help me regarding this issue