View previous topic :: View next topic |
Author |
Message |
mle
Joined: 12 Sep 2003 Posts: 10
|
using delay_ms with 40MHz osc |
Posted: Wed May 05, 2004 10:10 am |
|
|
Hello,
I'm using a 40MHz crystal with the PIC18f6520. I am using the processor to read from a dallas 1-wire temperature sensor (DS18S20). I seem to have communication problems when I use the 40MHz crystal, but if I put in a 4MHz crystal the program works fine. The 1-wire communication is time sensitive and I use delay_us() to get the right timing.
Does anyone know of a problem with delay_us() at very high processor speeds? Or does anyone see what else could be the problem?
mle |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed May 05, 2004 10:47 am |
|
|
If you want to run the PIC at 40MHZ you will need to use a 10MHZ crystal and use the HS/PLL option in the oscillator configuration. Pull up the data sheet and read up on the oscillator section on how to do it.
Ronald |
|
|
prwatCCS
Joined: 10 Dec 2003 Posts: 70 Location: West Sussex, UK
|
|
Posted: Wed May 05, 2004 10:56 am |
|
|
I was all set to use a PIC18F6720 at 40Mhz - some early info from Microchip suggested it was good to 40Mhz, but then I believe it changed and now they only qualify to 25Mhz. So maybe the 18F6520 is the same.
I am now using the 18F6621 which IS ok for use at 40Mhz.
Check the latest data and errata sheets !!
Of course the comments regarding 40Mhz crystals stand - use 10Mhz xtal and HS/PLL mode. I have used a 40Mhz TTL oscillator source with 18F452 successfully, but not yet with the 18F6xxx devices.
regards _________________ Peter Willis
Development Director
Howard Eaton Lighting Ltd UK |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed May 05, 2004 2:25 pm |
|
|
My bad! After looking closer, at the data sheet, the PIC CAN be driven up to 40MHZ.
If your application is time sensitive, remember that interrupts are not figured into the delay_us() function. So, if you have interrupts happening the delay will be extended while the interrupt is serviced.
Ronald |
|
|
prwatCCS
Joined: 10 Dec 2003 Posts: 70 Location: West Sussex, UK
|
|
Posted: Wed May 05, 2004 4:45 pm |
|
|
Have you checked that you have the correct setup ??
For my PIC18F6621 at 40Mhz I use
#define CLOCK_FREQUENCY 40000000
#define FOSC 40
#use delay(clock=CLOCK_FREQUENCY)
Those zeros can be easily mistyped !! _________________ Peter Willis
Development Director
Howard Eaton Lighting Ltd UK |
|
|
Ttelmah Guest
|
|
Posted: Thu May 06, 2004 2:01 am |
|
|
prwatCCS wrote: | Have you checked that you have the correct setup ??
For my PIC18F6621 at 40Mhz I use
#define CLOCK_FREQUENCY 40000000
#define FOSC 40
#use delay(clock=CLOCK_FREQUENCY)
Those zeros can be easily mistyped !! |
Beware also the fuses. 40MHz 'clocking', is _only_ supported using EC, or ECIO. For the crystal modes, the PLL has to be used.
Best Wishes |
|
|
|