Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

32 Mhz clock pulse outut from pic24f16ka102

Status
Not open for further replies.

skbohra

Newbie level 6
Newbie level 6
Joined
Oct 28, 2012
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,366
32 Mhz clock pulse output from pic24f16ka102

I am simply trying to get clock pulse output at CLKO(RA3) from pic24f16ka102 and according to the datasheet, following code should work, but I am not getting any pulse near 32Mhz, I am only getting random pulse with max frequency of some hundred Khz

Code:
#include "p24Fxxxx.h"

_FWDT	(FWDTEN_OFF);
_FOSCSEL(FNOSC_FRCPLL);
_FOSC(FCKSM_CSECMD & POSCFREQ_MS & OSCIOFNC_ON & POSCMOD_NONE)

int main(void)
{

// Use Internal 8 MHz Clock
OSCCON = 0x0000;
CLKDIV = 0x0000;
return 0;
}
 
Last edited:

I may be wrong, but I am not sure you can use CLKO in FRCPLL mode:

OSCIOFNC:
1 = CLKO output signal active on the OSCO pin; primary oscillator must be disabled or configured for
the External Clock mode (EC) for the CLKO to be active (POSCMD<1:0> = 11 or 00)

You might be able to use REFO instead, although it would be on a different pin

Keith.
 

I may be wrong, but I am not sure you can use CLKO in FRCPLL mode:



You might be able to use REFO instead, although it would be on a different pin

Keith.


I have tried without PLL mode but still I am not able to get any values more than couple of hundred KHz, my main objective is to generate a square wave of frequency in 500KHz to 1MHz, I have tried the Output compare module as well but the maximum frequency I get is 62KHz, following is the code for square wave using Output Compare module

Code:
#include "p24Fxxxx.h"

_FWDT	(FWDTEN_OFF);
_FOSCSEL(FNOSC_FRCPLL);
_FOSC(FCKSM_CSECMD & POSCFREQ_MS & OSCIOFNC_OFF & POSCMOD_NONE)

int main(void)
{

// Use Internal 8 MHz Clock
OSCCON = 0x0000;
CLKDIV = 0x0000;
REFOCON = 0x8000;

 T2CON = 0x00; //Stops the Timer2 and reset control reg.
    TMR2 = 0x00; //Clear contents of the timer register4
    T2CONbits.TCKPS = 0b10; // 1:64 prescale
    T2CONbits.TCS = 0;      // internal clock source
    IPC1bits.T2IP = 0x01; //Setup Timer1 interrupt for desired priority
    IEC0bits.T2IE = 1; //enable interrupts for timer2
    T2CONbits.TON = 1;

    OC1CONbits.OCTSEL = 0; //use timer 2
    OC1CONbits.OCM = 0b101; //single output pulse generation mode
    OC1CONbits.OCSIDL = 0; //continue in idle mode
    IEC0bits.OC1IE = 0;
    OC1RS=2;
    OC1R=1; // first match
    PR2 = 3;
    
while(1){
    
}
return 0;
}

void __attribute__((__interrupt__)) _OC1Interrupt( void )
{

/* Interrupt Service Routine code goes here */
IFS0bits.OC1IF = 0; // Clear OC1 interrupt flag
//OC1CONbits.OCM = 0b100; //single output pulse generation mode
//T2CON = 0x00;
}
 

I have tried without PLL mode but still I am not able to get any values more than couple of hundred KHz, my main objective is to generate a square wave of frequency in 500KHz to 1MHz, I have tried the Output compare module as well but the maximum frequency I get is 62KHz, following is the code for square wave using Output Compare module

It is not the PLL that causes the problem - it needs to be EC mode.

You should be able to generate 500kHz to 1MHz with no problem as long as you have a reasonable clock speed. I normally use the 24H and 24E and can generate 35MHz from TIMER1/OC1 with the 24E.

Your code uses 1:64 prescale so with 8MHz clock you are therefore running at 125kHz. Try 1:1 for the prescaler. If you want it to free-run you shouldn't need to use the interrupt.

Keith
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top