|
|
View previous topic :: View next topic |
Author |
Message |
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
How to (clearly) set Pre- and Post- Scalers ? |
Posted: Mon Apr 25, 2011 1:29 am |
|
|
Hi all,
I'm working on a design using a 18f4550 pic µC and and ENC28J60 ethernet controller.
The ethernet controller disposes of a 25MHz crystal and an output clock pin. So, I would like to use it as my pic's oscillator source.
I connected that pin to the "OSC1" µC pin; defined "ECPIO" fuse and now wonder how to configure PLLs.
Pic is currently receiving a 6.25MHz clock (default output frequency of the ENC28J60) which I would drive up to make USB working.
Main.h
Code: | #FUSES ECPIO
#use delay(oscillator=6250000, clock=6250000) |
Main.c
Code: | setup_timer_0(RTCC_EXT_L_TO_H); |
These three lines without "setup_oscillator" which is used to configure internal oscillator.
Off course, I read the user manual but I'm not sure to really understand how to "translate" the datasheet to C code : I know how to set pre- and post- scalers in ASM but I don't understand how does it work with CCS C.
Would you please give me a short source code and some explanations?
Using a 18f4550 with an input clock at 6.25MHz, how to set USB module on the pic?
Thanks so much for your help,
Seb _________________ - Be the change you want to see in the world (Gandhi) - |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Apr 25, 2011 8:39 am |
|
|
Not without an external PLL.
Data sheet is your friend. Has a huge table for this PIC, of _all_ allowable clock rates supporting USB. Table 2-3.
All are multiples of 4MHz (except 6MHz for low speed USB operation).
The only way you could do it, would be to have a *16/25 external PLL/divider, and then setup the PIC to run off 4MHz.
The PIC itself, won't support USB off 6.25MHz.
Best Wishes |
|
|
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
|
Posted: Tue Apr 26, 2011 1:14 am |
|
|
Hi,
Thanks for your answer, I was sure there will be a problem with my design ... so, here it is.
I had a look to PLL on digikey and farnell but did find any component which seems able to help me.
I never worked with "external pll", so I'm not sure of specs I read. _________________ - Be the change you want to see in the world (Gandhi) - |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Apr 26, 2011 2:05 am |
|
|
At the end of the day, 'why'?. Just run the PIC off it's own crystal....
There are dozens (hundreds?), of PLL chips on the market, that will allow you to multiply by a value, so *16, is very easy. A few have built in programmable dividers, so could do *16/25. However all cost more than the crystal. You could even do *16, using simple logic gates, and just using the alternate edges, and a couple of gate delays to perform frequency doubling. Repeat four times, and you have *16. Simple division then gives /25. Simple, but more expensive than the crystal....
There is no 'point' in trying to synchronise the chips. The SPI interface synchronises itself, the chips don't need any other synchronisation.
If you want to run 'in sync' for some peculiar reason, implement a 100MHz oscillator, and with a bit of logic, divide this by 4, to feed the ethernet device, and by 25, to feed the PIC.
Best Wishes |
|
|
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
|
Posted: Tue Apr 26, 2011 4:34 am |
|
|
Well, you're perfectly right. I make that choice because I have a large need of pins.
Except NC pin, they are all used even A6.
I believed that ECPIO was a good idea to prevent changing the µC. _________________ - Be the change you want to see in the world (Gandhi) - |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Apr 26, 2011 4:54 am |
|
|
So, use an external oscillator module. Some are almost as cheap as crystals, and you are again able to use the EC clock option. Personally I'd choose 8MHz. Reasons:
Lower frequencies generally use less power, and give less problems with radiated interference, _but_ I have found in the past, that the 4MHz input option, is slightly more 'fussy' on the 4550, so 8MHz, is my preferred selection. Something like X202-ND from Digikey.
Best Wishes |
|
|
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
|
Posted: Tue Apr 26, 2011 3:54 pm |
|
|
Great idea!
I didn't knew these module, thanks so much for your advice. _________________ - Be the change you want to see in the world (Gandhi) - |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|