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.

[PIC] UART doesnt work at higher PLL

Status
Not open for further replies.

Thota Suresh Avionics

Member level 2
Joined
Jul 15, 2013
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Activity points
345
PIC24EP512GP806,MPLAB8.8

I trying to work with PIC24 modules and for my first attempt I tried to print on uart.
I cannot print any thing , not even garbage values.

After PLL I need to get oscilator as 240Mhz
I used Fin = 20mhz oscillator
M = 46+2 = 48
N1 = 0+2 = 2
N2 = (0+1) *2 = 2
Fosc = Fin * (M/(N1+N2)) = 20000000 * (48/(2+2)) = 240M

BRGH = 0; so, U1BRG = 3124
nothing is printed in UART !

If I does the same, up to 160Mhz(fosc) i.e, M = 30 + 2 = 32
corresponding U1BRG = 2082 it is working fine. Any higher M values than 30 that it is not printing any thing in hyper terminal.

will there be any limit or where am I doing wrong ??


Code:
#include"main.h"
#include"uart.h"

_FGS(GSS_OFF & GWRP_OFF & GSSK_OFF)		
_FOSCSEL(FNOSC_PRI & IESO_OFF)
_FOSC(POSCMD_XT & OSCIOFNC_OFF & FCKSM_CSECMD)
_FWDT(WDTPRE_PR32 & PLLKEN_ON & WINDIS_OFF & FWDTEN_OFF)
_FAS(AWRP_OFF & APL_OFF & APLK_OFF);
_FICD(ICS_PGD3 & RSTPRI_PF & JTAGEN_OFF)

int main()
{

	Config_Clock();
	Config_UART();
	Init_UART();

	while(1);
	return 0;
}

void Config_Clock(void)
{
    PLLFBD                    = 46;   	// M = PLLDIV+2
    CLKDIVbits.PLLPOST   = 0;        // N2 = (PLLPOST+1)*2
    CLKDIVbits.PLLPRE 	  = 0;	// N1 = PLLPRE+2

    __builtin_write_OSCCONH( 0x03 );    	// Initiate Clock Switch to

    __builtin_write_OSCCONL( OSCCON || 0x01 );  // Start clock switching
    while( OSCCONbits.COSC != 0b011 );
    // Wait for Clock switch to occur
    while( OSCCONbits.LOCK != 1 );
}

void Config_UART(void)
{
    // PPS
    // Unlock Registers
    __builtin_write_OSCCONL(OSCCON & 0xbf);

    RPINR18bits.U1RXR = 66;				//Configure Input Functions , Assign U1RX To Pin RP30		UART1 working
    RPOR0bits.RP65R = 1;				//Configure Output Functions , Assign U1TX To Pin RP16

	__builtin_write_OSCCONL(OSCCON | 0x40);
}

void Init_UART(void)
{								
	U1BRG = 3124;//1561;				
	U1MODE = 0x8008;			// BRGH = 0;
        U1STA	= 0x0400;			//UTXEN = 1;

		
	printf("UART Ready\n");
}
 
Last edited:

Your UART is configured at some other baud rate, see the data sheets, sometimes it says Fc ( Cycle frequency) not the Fosc , so keep a check on it
 

For a start, the maximum Fosc for that chip is 120MHz, the maximum input frequency to the PLL (if after the PLLPRE division) is 8MHZ so you need a minimum division in PLLPRE of 4 (not 2), which also puts the maximum Fvco out of spec.
The first step is to get the oscillator working within the design spec so that it will be stable.
Your second oscillator setup is closer to within design spec for the chip (which is probably why it is working for you) but it is also too high. However you must get the input frequency to the PLL down to 8MHZX at the most.
This is all very clearly explained in the data sheet and in particular in Figure 9-2.
Susan
 
I have taken with values as below !
PLLFDB = 46 --> M = 48
PLLPRE = 2 --> N1 = 4
PLLPOST= 0 --> N2 = 2
Fin = 20Mhz

Fosc = 160Mhz
Fcy = 80Mhz
U1BRG = 2082(BRGH = 0)

Fref = 20M/4 = 5Mhz
Fvco = 20M * 48/4 = 120Mhz

it didnt show up any thing while putting data on hyperteminal.
 

Before going into PLL configuration details, I would check with an oscilloscope
1. if the UART is running at all
2. what's the actual TX baud rate
 

YES uart is running when I give values n1 = 2 and N2 = 2 , and M value lesser or equal to 30.
buad rate is 9600
 

I have taken with values as below !
PLLFDB = 46 --> M = 48
PLLPRE = 2 --> N1 = 4
PLLPOST= 0 --> N2 = 2
Fin = 20Mhz

Fosc = 160Mhz
This is where you went wrong: Fosc = 120MHz not 160MHz!
I can't see what BAUD rate you are trying to get to, but workign backwards from your (incorrect) Fosc of 160MHz whcih gives an Fp of 80MHz, your U1BRG value of 2082 gives a baud rate of 2400.
Working forward again with the correct Fosc gives an Fp of 60MHz, to get 2400BAUD requires U1BRG = 1561 (or 1562 - the actual calculation gives 1561.5 but the percentage difference is too small to worry about).
The reason you would have seen nothing is that the bit rate you were sending was too far out of spec for the other device to pick up and interpret correctly.
By the way, I really suggest that you use Fp in your calculations and not Fcy - Fcy can be affected by the DOZE division ratio whereas Fp is always Fosc/2.
Susan
(Edit: I see in a later post that you mention a 9600 BAUD rate - if so then your calculations are ever further out and U1BRG should be 390.)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top