[SOLVED] Internal Oscillator selection problem

Status
Not open for further replies.

Raady Here

Full Member level 5
Joined
Jun 8, 2013
Messages
242
Helped
26
Reputation
52
Reaction score
26
Trophy points
28
Location
India
Visit site
Activity points
1,571
PIC24FJ64GA006
MPLAB 8.88

Hi,
I have encountered two problems one with oscillator selection and timer calculation
For testing I am throwing timer clock data on lcd.
I am able to use only FNOSC_FRCDIV only, if i select FNOSC_FRC or FNOSC_FRCPLL nothing is being displayed on LCD.

I am using setting for oscillator as
_CONFIG2(POSCMOD_NONE & OSCIOFNC_OFF & FCKSM_CSECMD & FNOSC_FRCDIV & IESO_ON); // Oscillator Settings


calculation for timer that I have taken are
Fosc = 8 Mhz ( after post scaler should be divided by 1)
Fcy = Fosc/2
Fprescalar = Fcy/prescalar( i used 1:8)
Ttimer= 1/Fprescalar

value in PR1 register = 10ms / Ttimer = 5000 ( __T1_TIME)

but when I am running the clock , it runs exactly when I am loading the value as 500 instead of 5000.

am I missing some thing to configure with post scalars ?


timer I configured ..
Code:
void INIT_TIMER(void)
{
 T1CON = 0; // Disable Timer1 for Clock and Reset.
 
 TMR1 = 0x0000; // Clear RTC Timer Register.
 PR1 = __T1_TIME; // Set Timer1 period register for 10ms
 T1CONbits.TCKPS = 1; // Set Timer1 Input Clock Prescale Select bits (1:8)

 IFS0bits.T1IF = 0; // Reset Timer 1 interrupt flag
 IPC0bits.T1IP = 7; // Set Timer1 interrupt priority level to 7
 IEC0bits.T1IE = 1; // Enable Interrrupt w.r.t Timer 1

 T1CONbits.TON = 1; // Enable Timer1
}


/* Timer Interrupt */
void __attribute__((__interrupt__,no_auto_psv)) _T1Interrupt(void)
{
 IFS0bits.T1IF = 0; //Clear Timer1 interrupt flag
 Flag.TimerDelay_10ms = 1;
 if(++ten_ms_cnt >= 100)
 {
  Clock();
  ten_ms_cnt = 0;
 } 
}
 
Last edited:

the timer calculation of 5000 looks correct

for a PIC24FJ64GB004 (similar device with USB) I use
Code:
        _CONFIG2(POSCMOD_HS & I2C1SEL_PRI & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_OFF)

which with an 8MHz crystal gives SYSCLK of 32MHz

and to get a 1mSec interrupt the timer initialisation is
Code:
void Timer1init()
{
    T1CON = 0x00; 			//Stops the Timer1 and reset control reg.
    TMR1 = 0x00; 			//Clear contents of the timer register
    //PR1 = 4000;				//Load the Period register with 1mSec counter 
    PR1 = SYSCLK/2/1000; //16000U;				//Load the Period register with 1mSec counter 32MHz clock
	IPC0bits.T1IP = 0x01; 	//Setup Timer1 interrupt for desired priority level
	// (This example assigns level 1 priority)
	IFS0bits.T1IF = 0; 		//Clear the Timer1 interrupt status flag
	IEC0bits.T1IE = 1; 		//Enable Timer1 interrupts
	T1CONbits.TON = 1; 		//Start Timer1 with prescaler settings at 1:1 and
							//clock source set to the internal instruction cycle
}

what does the clock() function do?

when using FNOSC_FRCPLL could you be transmitting data to the LCD too fast so it does not display correctly? I find one has to put delays after LCD writes
 
Last edited:

but in my case I require a frequency between 8 - 20 Mhz for my application. so I am not going for HS oscillator

when I am selecting FRC ( internal oscillator with and without no pll) , it doesnt display any data.
but when I am placing FRCDIV, it working fine.
I have crossed checked the values by changing the values in the register CLKDIVbits.RCDIV,
I have to place a lesser value than what it should be.
 

Clock function updates value of sec, min, hours.
in the code I have used CLKDIVnits.RCDIV = 2 ; // it is 2 Mhz
so I have to load 2500 instead I have kept 1000 to work fine.

Here is the src.
View attachment src.rar
 

after 4 days working, I came to know the processor is defective as no other module is working fine.
The same code is working fine when I have re-soldered by changing the processor.

Horace1,

In the code example you mentioned while working with USB should we use High speed oscillator or else can we use internal FRC also ?
 

the example I gave
Code:
        _CONFIG2(POSCMOD_HS & I2C1SEL_PRI & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_OFF)
uses an external 8MHz crystal

however, tried the following using the internal FRC ( Fast RC oscillator with Postscaler and PLL module (FRCPLL))
Code:
        _CONFIG2(POSCMOD_HS & I2C1SEL_PRI & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_FRCPLL  & PLL96MHZ_ON & PLLDIV_NODIV & IESO_OFF)
and the USB still works OK
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…