PDA

View Full Version : pic18f25k22 clock



connortop
- 13th September 2016, 08:23
Hello,

i am new to programming and am using a pic18f25k22 im trying to set it up to use an external 8mHz oscillator but from looking at the datasheet i am confused about how i do this any help would be appreciated

thanks connor

towlerg
- 13th September 2016, 17:18
What do you want the resultant PIC internal clock to be?

Scampy
- 13th September 2016, 18:28
Page 33 of the datasheet shows you how to connect an external resonator or crystal to RA6 and RA7. 22pf or 33pf ceramic capacitors are typical values used.

However as Towlerg stated, this is not the only thing to consider as the PIC has various modes of oscillation, which effectively can multiply the resonator / crystal frequency by factors up to four fold ( eg using an 8Mhz crystal and an HS_PLL setting it can run at 32 Mhz). If you can provide more information as to exactly what speed you want to run the PIC at then I'm sure you'll get more help and guidance.

connortop
- 14th September 2016, 08:08
thanks for your reply i have an 8mHz crystal attached to RA6 and RA7 with a .22pF cap both sides. i think ive found the code within mplab ide where it auto generates the code but im now struggling to find out how to set the i/o ports to outputs and just get the pic working in general.... STRESSFUL!!!!

towlerg
- 14th September 2016, 15:09
Generally to set a port to output you write a 0 to the relevant TRISx (where x is the port letter). Even better from the manual -
5.48 OUTPUT
OUTPUT Pin
Make the specified Pin an output. Pin may be a constant, 0 - 15, or a variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g. PORTA.0).
OUTPUT 0 ' Make Pin0 an output
OUTPUT PORTA.0 ' Make PORTA, pin 0 an output
Alternatively, the pin may be set to an using direct register access:
TRISB.0 = 0 ' Set PORTB, pin 0 to an output
All of the pins on a port may be set to outputs by setting the entire TRIS register at once:
TRISB = %00000000 ' Set all of PORTB to outputs

Scampy
- 14th September 2016, 17:42
thanks for your reply i have an 8mHz crystal attached to RA6 and RA7 with a .22pF cap both sides. i think ive found the code within mplab ide where it auto generates the code but im now struggling to find out how to set the i/o ports to outputs and just get the pic working in general.... STRESSFUL!!!!

Post up your code as you have it and I'm sure we'll get you sorted