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.

PIC18F47J53 Speed

Status
Not open for further replies.

AtomSoft

Well-Known Member
OK i have a setup like:

Code:
#pragma config PLLDIV = 2           //Divide by 2 (8 MHz oscillator input)
#pragma config CPUDIV = OSC1        //No CPU system clock divide
#pragma config OSC = INTOSCPLL      //Internal Oscillator mode, RA7:6 PORT FUNCTION
#pragma config IESO = OFF           //Two-Speed Start-up disabled

........

unsigned int pll_startup_counter = 600;
OSCCON = 0;
/* Setup the Internal OSC for 8 MHz*/
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
        
/* Wait until OSC is running and stable*/
while((OSCCON & 0x0C) != 0x0C);
        
OSCTUNEbits.INTSRC = 1;
OSCTUNEbits.PLLEN = 1;  //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module
while(pll_startup_counter--);

Whats my final speed? I think 48MHz but im getting gibberish from the UART... and i know i set that up correctly...

Code:
void config_uart(void){

    unsigned char config=0,spbrg=0,baudconfig=0;

    /* ---PPS Configuration--- */
    PPSUnLock();
    iPPSInput(IN_FN_PPS_RX2DT2,IN_PIN_PPS_RP20);            //Configre RP20 as RX Pin
    iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_TX2CK2);         //Configre RP17 as TX Pin
    PPSLock();

    
    TRISDbits.TRISD3 = 1; //RX
    TRISCbits.TRISC6 = 0; //TX

    Close2USART();  //turn off usart if was previously on

    /* -----configure USART ----- */
    config = USART_TX_INT_OFF | USART_RX_INT_OFF | USART_ASYNCH_MODE | USART_EIGHT_BIT | USART_CONT_RX | USART_BRGH_LOW;
    /* -----SPBRG needs to be changed depending upon oscillator frequency------- */
    spbrg = 77;                    //At 48Mhz of oscillator frequency & baud rate of 9600.

    Open2USART(config, spbrg);        //API configures USART for desired parameters

    baudconfig =  BAUD_8_BIT_RATE | BAUD_AUTO_OFF;
    baud2USART (baudconfig);
}

So either its the UART or the SPEED(FOSC) ... but i would like to know what speed is this supposed to run on.. Im also using USB on this with PLL active...
 
Looking at the oscillator diagram, it looks like it should be 48MHz. You shouldn't need to change OSCCON as the 8MHz is taken before the divide.

One thing I'm wondering about is that I've read somewhere that the internal oscillator isn't accurate enough for high speed USB.

Found it, from the data sheet,

The 8 MHz INTOSC included in all PIC18F47J53 family
devices is extremely accurate. When the 8 MHz
INTOSC is used with the 96 MHz PLL, it may be used
to derive the USB module clock. The high accuracy of
the INTOSC will allow the application to meet
low-speed USB signal rate specifications.

Mike.
 
Hey Mike, USB isnt the issue. That actually works fine. Its uart im having a issue with. I used

48mhz / 9600bps = 5000 / 64 = 78.125 - 1 = 77...

Actual = 77 + 1 = 78 x 64 = 4992
fosc / actual = 9615bps which is well in range... So why does this fail to send correct uart?
 
Your calculation look correct but I've no idea how the libraries work. Try writing the register direct and see if that works.

Mike.
 
How do i know what to tune it to? I have it set to 000000 = Center frequency; oscillator module is running at the calibrated frequency

Pommie: Ill try that today :)
 
Pommie you rock! I tried:
Code:
    SPBRG2 = 77;

    TXSTA2bits.BRGH = 0;
    TXSTA2bits.TX9 = 0;
    TXSTA2bits.SYNC = 0;
    RCSTA2bits.RX9 = 0;

    RCSTA2bits.CREN = 1;
    RCSTA2bits.SPEN = 1;
    TXSTA2bits.TXEN = 1;

    BAUDCON2bits.BRG16 = 0;

//....

while(!TXSTA2bits.TRMT);
            TXREG2 = 'J';

It works!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top