View previous topic :: View next topic |
Author |
Message |
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
[SOLVED] PIC24 clock (Oscillator) |
Posted: Mon Jan 04, 2010 12:16 am |
|
|
Ok, I finally got the dsPIC33 clocks worked out, now I am playing with a PIC24, and I am back to square one.
When timed on my scope, I get 25us for the sample below.
When I tried with #use delay(clock=40M, oscillator=10M) I got 50us
Help, I know its right in front of me, and I tried going through the datasheets and trying a few different things before posting, but I just cant spot it.
Code: |
#include <24FJ256GA106.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES CKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES PR //Primary Oscillator
//#FUSES PR_PLL //Primary Oscillator with PLL
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES WPEND_LOW
#FUSES NOWPCFG
#FUSES NOWPDIS
#FUSES WPFP0
//#FUSES RESERVED //Used to set the reserved FUSE bits
//#use delay(clock=40000000)
#use delay(clock=20M, oscillator=20M)
while(1)
{
output_high(PIN_F5);
delay_us(10);
output_low(PIN_F5);
delay_us(100);
}
|
_________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects
Last edited by mbradley on Mon Jan 25, 2010 4:11 pm; edited 1 time in total |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jan 04, 2010 1:27 am |
|
|
The connected oscillator can be either 20 or 40 MHz (or another different frequency), so at least one of both tested configurations is incorrect.
When you specify both frequencies with #use delay(), the compiler can choose the clock divider settings automaticly. But it doesn't override explicite #fuse settings.
I suggest to read the datasheet to understand the possible PLL configurations.
P.S.: I didn't realize, that you use a PIC24FxxGA106. It has a maximal CPU clock frequency of 32 MHz. The PLL can be used
only with a 8 MHz clock input, otherwise, the HS input clock is directly fed to the core. In other words, both of your above
configuration don't work for this chip.
Last edited by FvM on Mon Jan 04, 2010 1:37 am; edited 1 time in total |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Mon Jan 04, 2010 1:29 am |
|
|
Would you be able to give me the correct settings for running this at 20MHz?
I have a 5MHz and a 20MHz crystal in front of me, so I believe I can use or not use the PLL?
Do I understand correctly, I should not use the #FUSE as related to PLL and HS? _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jan 04, 2010 1:42 am |
|
|
You can either use HS and PR with 20 MHz crystal or XT and PR_PLL with 5 MHz. Both settings should give 20 MHz core clock.
I'm using the chip without a PLL. |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Mon Jan 04, 2010 1:52 am |
|
|
I understand, but for some reason its not working, however, what I have just learned is its running at 8MHz, at least I think.
The pulse width on my scope is 25us, well if take this 25 and divide it by the 10 I have programed, I get a factor of 2.5
now if I take the programmed delay of 20mhz, and divide by 2.5, I get 8mhz, this is the internal oscillator speed.
Do I have to switch over someplace? did I mess up? _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Mon Jan 04, 2010 2:04 am |
|
|
I feel so dumb right now... here is what I have, and the scope shows a 25us pulse, not 10us:
Code: |
#include <24FJ256GA106.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOOSCIO //OSC2 is clock output
//#FUSES CKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
//#FUSES PR //Primary Oscillator
#FUSES PR_PLL //Primary Oscillator with PLL
#FUSES XT //XTAL
//#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES WPEND_LOW
#FUSES NOWPCFG
#FUSES NOWPDIS
#FUSES WPFP0
#use delay(clock=20000000)
while(1)
{
output_high(PIN_F5);
delay_us(10);
output_low(PIN_F5);
delay_us(100);
}
|
_________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jan 04, 2010 2:48 am |
|
|
I didn't yet use the PLL with this chip and I'm not aware of any specific problems. I wonder if the oscillator is working at all in your design?
I'm not clear about the actual meaning of the IESO fuse. You may want to disable it for test. |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Mon Jan 04, 2010 9:43 pm |
|
|
Ok, I did this:
Code: |
//#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOOSCIO //OSC2 is clock output
//#FUSES CKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES PR //Primary Oscillator
//#FUSES PR_PLL //Primary Oscillator with PLL
//#FUSES XT //XTAL
#FUSES HS
#use delay(clock=8000000)
|
And the PW is correct, however, I can pull the crystal while running, and it stays good. Oh, the xtal is 20mhz. So as you suggested, it might not be oscillating, did it fail over?
My next step, replace the xtal with an external function generator giving me the clock to test with. _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Mon Jan 25, 2010 4:11 pm |
|
|
Solved:
And I feel very dumb, stupid in fact.....
First, I thank everyone who endured this with me and tried to help me out.
ok, the bottom line, please dont laugh, ok go ahead....I had the xtal connected to the wrong pins.
I have a 64pin tqfn soldered to a dip board for prototyping, and I miss counted the the pins when I breadboarded.
I know, a silly mistake. _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Tue Jan 26, 2010 1:21 am |
|
|
happens to all of us...
_________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|