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.

[SOLVED] Setting internal oscilator with PLL on PIC 18F46K20

Status
Not open for further replies.

DrBudz

Junior Member level 3
Joined
Dec 5, 2011
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,500
I'm trying to send character via UART, but I get some other character.
There is probably an error because of the wrong INTOSC setup, which is causing wrong baud rate.
Everytime I change settings of INTOSC, I get a different charcter on UART TX.
Correct baud rate is selected in uart terminal (9600 in this case, data bits 8, parity-none, no handshaking, 1 stop bit)

PIC MCU is 18F46K20.
Configuration is set for INTOSC - RA6 and RA7 as I/O, and freq in project is set to 32MHZ.


Code:
void main() {
 OSCCON=0b01100000;              //Internal OSC 8MHz
 PLLEN_bit=1;                          //PLL enabled - osc=4x8MHz  =32MHz

  
   PORTA = 0 ;
          TRISA = 0xff ;          // set PORTA as input for ADC
          PORTB = 0 ;
          TRISB = 0xff ;          // set PORTB as input for buttons
          LATD  = 0 ;
          TRISD = 0 ;             // set PORTD as output
          SLRCON = 0;             // Set output slew rate on all ports at standard rate
          INTCON.GIE=1;           //global interrupts enabled
          INTCON.PEIE=1;                   //periferni interapti dozvoljeni
          PIE1.RCIE=1;

          TRISC=0x00;      //desperate attempt to find a possible cause

  UART1_Init(9600);               // Initialize UART module at 9600 bps
     Delay_ms(100);                  // Wait for UART module to stabilize
  while(1){
    UART1_Write('X');
    Delay_ms(1000);
     LATD=0;
    Delay_ms(1000);
  
  }
}

When I measure the delay time, it seems to be 2sec, which is OK because there is 2 delays with 1000ms.
It could mean that the OSC is working correctly and that there could be a problem with something else....

Can somebody try this code or tell me what am I doing wrong?
Thanks!
 

The code is fine.

What you did wrong is probably that, in the mikroC MCU Clock selection, you input 8MHz. Instead, input 32MHz there. Then, the problem should be fixed.

Hope this helps.
Tahmid.
 

Hi Tahmid,

In MikroC, mcu clock is set to 32MHz.
I don't have any idea where could be the bug.
Maybe the bug is in the Uart_Init function...


Thanks!

- - - Updated - - -

I get 0x10 (hex) 16(dec) 0b0001000 (bin), I don't know which charcter is that in ASCII. In terminal, it is just shown as a small rectangle.
 

What character do you get as output?

I'm getting the correct output in simulation - X.
 

Ok, I will try that code. I let you know in few minutes, does it work. Thanks
 

Change the MCU clock in mikroC to 8MHz. Then, disable PLL by removing the line
Code:
PLLEN_bit=1;

This should make the microcontroller run at 8MHz without PLL. So, check if you get the correct output now.
 

Nope, now I get 0b11111010, and the delay is not good, it is much faster now.
I think the clock speed is now 64MHz.
If you look at the datasheet for 18F46K20, OSCCON=0b01110000 setting is for 16Mhz.
If we add 4xPLL, 16MHz x4= 64MHz

- - - Updated - - -

I turned off PLL, and set OSCCON =0b01100000, set the cpu to 8Mhz, and I get the same character as for 32MHz with pll
If I put OSCCON =0b01110000, and set cpu to 8Mhz, I get 0b11111010, the same as on 64Mhz

I also tried many other combinations, and never get the 'X' character

- - - Updated - - -

This setting is good: OSCCON =0110 0000 - 8MHz Intosc, PLLEN=1 - 4x PLL, -> MCU clock =32MHZ
It is working now, I tried some different code from other project.

The problem is probably in the compiler, it is generating errors in hex file.
I made this conclusion when I tried to send longer string via uart.

Thanks for help!
 

The problem is probably in the compiler, it is generating errors in hex file.
I made this conclusion when I tried to send longer string via uart.

Thanks for help!

Possible. I've found that sometimes the compiler makes mistakes in generating the hex file. In such cases, close the project, copy and paste the code onto a new project and rebuild the new project.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top