Hey guys, I looked over the data sheet and I found some sample code for what I believe is the proper configuration to have the microcontroller oscillate at 48MHz.
Hardware set up:
I have a 20MHz crystal oscillator connected across pin 14 (OC1) and 13 (OC2). Then, I have two ceramic 22pF capacitors going from each pin to ground.
**broken link removed**
The configuration using MPLAB C18 (for programming in C)
Basically my question are as follows:
__________
1. Are the connections right?
2. Are the components (crystal and capacitor) correct?
3. If I have delays set for 1MHz FOSC, will I now have to adjust for 48MHz?
4. Do I need to further configure pins 14 (RA6/OC1) and pin 13 (RC0)?
The main reason for all of this is that I would like to increase the range of delays I can apply, since devices such as the DS18B20 temperature controller requires 1uS delays. Additionally, I may look into USB communication (I found a tutorial), and I would like to have this feature working. Any help in this matter is greatly appreciated. Thank you.
EDIT:
I have an LED connected and I am able to get it to blink when I use the following configuration:
But, nothing happens (not even a flicker) when I run this code:
Hardware set up:
I have a 20MHz crystal oscillator connected across pin 14 (OC1) and 13 (OC2). Then, I have two ceramic 22pF capacitors going from each pin to ground.
**broken link removed**
The configuration using MPLAB C18 (for programming in C)
Code:
#pragma config PLLDIV = 5 // 20Mhz external oscillator
#pragma config CPUDIV = OSC1_PLL2 //determines frequency division
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
Basically my question are as follows:
__________
1. Are the connections right?
2. Are the components (crystal and capacitor) correct?
3. If I have delays set for 1MHz FOSC, will I now have to adjust for 48MHz?
4. Do I need to further configure pins 14 (RA6/OC1) and pin 13 (RC0)?
The main reason for all of this is that I would like to increase the range of delays I can apply, since devices such as the DS18B20 temperature controller requires 1uS delays. Additionally, I may look into USB communication (I found a tutorial), and I would like to have this feature working. Any help in this matter is greatly appreciated. Thank you.
EDIT:
I have an LED connected and I am able to get it to blink when I use the following configuration:
Code:
#pragma config WDT=OFF, LVP=OFF, DEBUG=ON, MCLRE = ON
//Internal oscillator, port function on RA6, EC used by USB
#pragma config FOSC = INTOSCIO_EC //1MHz oscillation
But, nothing happens (not even a flicker) when I run this code:
Code:
//turns watch dog timer off, turn low voltage programming off
#pragma config WDT=OFF, LVP=OFF, DEBUG=ON, MCLRE = ON
//oscillator configurations see pg. 25 /430 of pic18f4550 data sheet
#pragma config PLLDIV = 5 // 20Mhz external oscillator
#pragma config CPUDIV = OSC1_PLL2 //determines frequency division
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#include <p18f4550.h>
#include <delays.h>
//Power LED (PortA)
#define LEDPin LATAbits.LATA0 //Define LEDPin as PORT A Pin 1
void main()
{
while(!OSCCONbits.IOFS); //wait for osc stable
ADCON1 = 0x0F; //make RA0 digital
//data direction registers all 0's mean that all pins are set to output
//all 1's means that all of the pins are set to operate as inputs
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
while(1)
{
LEDPin = ~LEDPin;//Toggle LED Pin
//Delay 250K cycles (1 second at 1MHz since each instruction takes 4 cycles) should blink faster now
Delay10KTCYx(25);
}//end main while loop
}
Last edited: