Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Timer0 issue with PIC18F4550 @ Fosc=32M

Status
Not open for further replies.

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
 
Do you have the two capacitors that are required for the crystal?

Mike.

Hello Mike , Thanks for reply

Actually i put crystal connected directly to PIC , I don't use any capacitors

So , Are capacitors important when Fosc reach 32M , as I used not to connect them when operating at lower Fosc

Can u please advise me which capacitors values i should use ?

Thanks
 
Look at Figure 2-2 of your datasheet. They give you a recommended circuit for a crystal that shows the capacitors.
 
Hello Ian Rogers & Rusttree

Thank u for reply

I will try your suggestion and will get back to you to tell results

Thanks in advance :)
 
Solved !

Hello all

I found the issue , I have added 200n Cap between supply rails and Timer0 operation was stable , issue is solved finally !

Thank u everybody for advices and hints , have a nice day !
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top