4 MHz oscillator with pic18f2550 - Page 1
Forum section: electronics / beginners

author: daliah
author_rank: Newbie
timestamp: May 04, 2011, 04:17:55 pm
content: Hi, I'm new in hardware stuff and I am using PIC microcontrollers.I found an article where a 20 MHz crystal clock is used with pic18f2550.I need to build the circuit as soon as possible, but i didn't find such a clock in the nearest store!!I already have a 4 MHz crystal clock. Is it ok if I use it with pic18f2550??Thank you.

author: armandas
author_rank: Frequent Contributor
timestamp: May 04, 2011, 04:32:55 pm
content: Quote from: daliah on May 04, 2011, 04:17:55 pmIt should fine as long as you set the configuration bits right. You might also have to use different load capacitors, although that should not be too critical.

author: francisjoe45
author_rank: Newbie
timestamp: May 04, 2011, 04:34:47 pm
content: Check the datasheet, but I think it would work, you just have to remember to connect both pins in series with 33uF capacitors to the ground. Good luck!

author: daliah
author_rank: Newbie
timestamp: May 04, 2011, 04:59:59 pm
content: Ok, thank you

author: Zad
author_rank: Super Contributor
timestamp: May 05, 2011, 01:23:40 am
content: If you don't need precise frequency control and don't need USB, the PIC18F2550 has a built-in 8MHz oscillator that you can use.Page 27 in the data sheethttp://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf

author: daliah
author_rank: Newbie
timestamp: May 05, 2011, 02:52:05 pm
content: I do need USB, what min frequency can I use with it??

author: dimlow
author_rank: Frequent Contributor
timestamp: May 05, 2011, 03:10:20 pm
content: Not 33uF No.... 27pF but it will work without in most cases4Mhz for USB BTW you have to set the pll to get 48Mhz from 4Mhzif you have just started then i would forget about USB for a few months

author: daliah
author_rank: Newbie
timestamp: May 06, 2011, 05:58:28 am
content: well dimlow I'm using 15 pF."if you have just started then i would forget about USB for a few months"...what do you mean by this???

author: dimlow
author_rank: Frequent Contributor
timestamp: May 06, 2011, 06:26:23 am
content: what i mean is concentrate on learning what the pic can do for you and how you can use all its features first. Play , experiment. Dont just jump into USB, because you will get bitten. it can get very complex. The USB stack is not something that is easy to program. Even if using one of the built in stacks the come with you compiler ( I dont know what compiler your using you using) it can be still be quite complex.If you jump right into USB before starting with the simpler aspects of the chip i think you would give up quite quickly and the experience of micro controllers will not be so enjoyable..

author: scrat
author_rank: Frequent Contributor
timestamp: May 06, 2011, 10:15:10 am
content: If you really need USB in a short time (and the application to be developed is simple), I think the stack provided by Microchip is quite easy to use, in my experience it was one of the first things I dealt with about PICs. However, I agree with dimlow it's good to play/experiment a little with some other features before, although not strictly necessary. It depends much on your knowledge about programming and electronics.You can use oscillator at 4MHz x 1 to 6, 10 or 12 (see figure 2-1 of the datasheet). For USB you need a stable and enough accurate oscillator (i.e. a quartz based one), so you can't use the internal (R-C) one.

author: daliah
author_rank: Newbie
timestamp: May 06, 2011, 11:37:17 am
content: Thank you for your advice, I really appreciate it. You're 100 right, but the problem is that I need the USB right now because I have to deliver my project in less than a month. The good thing is that I found some coding that will help me.I had the other option to work with serial comminication, but I don't have the serial port in my laptop, so I thought that it's easier to work with USB rather than converting from serial to USB because this might cause me problems.Isn't it right??

author: scrat
author_rank: Frequent Contributor
timestamp: May 06, 2011, 12:22:33 pm
content: There are many simple serial to USB converters, devices or ICs to be embedded in the design.If you plan to go with the MCU's USB peripheral, Microchip USB framework is a simple set including useful examples. In this case, since you don't need very high bitrates (as serial connection was an option) my advice is to try with the serial emulation.Depending on which are the application and specs, one can help you choose between the various options.

author: metalphreak
author_rank: Frequent Contributor
timestamp: May 07, 2011, 11:46:21 am
content: You need to set the oscillator clock setting to NODIV aka Direct Input. The PIC uses a 4Mhz signal to generate all the clocks it needs. If you use an 8/12/16/20/24/40/48 Mhz crystal it needs to divide it by 2/3/4/5/6/10/12 to get 4mhz.If you are using something like WinPic800 to flash the .hex file onto the device, you can change settings there to whatever configuration you need.

author: Zad
author_rank: Super Contributor
timestamp: May 07, 2011, 05:18:24 pm
content: If you need USB quickly and with a minimum of overhead, I would suggest using one of FTDI's modules, the FT232 for example.http://uk.farnell.com/ftdi/um232r/evaluation-kit-usb-uart-ttl-ft232rl/dp/1146036

author: Teknotronix
author_rank: Regular Contributor
timestamp: May 09, 2011, 12:37:18 am
content: Hi,I too use the 4Mhz crystal option on my USB projects with the PIC18F4458 (Same family as yours). I choose this setup over the 20Mhz you see in all the examples because, when running in XT mode, I read somewhere it results in lower dynamic currents due to less gain with the feedback inverter (can't find source of info). You will need 27pf caps or somewhere in that region, however consider that the higher the value, the longer the startup time.Here are the config bits I use in my projects. You might need to change a few for your requirements:#pragma config PLLDIV = 1#pragma config CPUDIV = OSC1_PLL2#pragma config USBDIV = 2#pragma config FOSC = XTPLL_XT#pragma config FCMEN = OFF#pragma config IESO = OFF#pragma config PWRT = OFF#pragma config BOR = ON#pragma config BORV = 3#pragma config VREGEN = ON#pragma config WDT = OFF#pragma config WDTPS = 32768#pragma config MCLRE = ON#pragma config LPT1OSC = OFF#pragma config PBADEN = OFF// #pragma config CCP2MX = ON#pragma config STVREN = ON#pragma config LVP = OFF// #pragma config ICPRT = OFF#pragma config XINST = OFF#pragma config CP0 = OFF#pragma config CP1 = OFF// #pragma config CP2 = OFF// #pragma config CP3 = OFF#pragma config CPB = OFF// #pragma config CPD = OFF#pragma config WRT0 = OFF#pragma config WRT1 = OFF// #pragma config WRT2 = OFF// #pragma config WRT3 = OFF#pragma config WRTB = OFF#pragma config WRTC = OFF// #pragma config WRTD = OFF#pragma config EBTR0 = OFF#pragma config EBTR1 = OFF// #pragma config EBTR2 = OFF// #pragma config EBTR3 = OFF#pragma config EBTRB = OFF#pragma config DEBUG = OFF