CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC24F32KA304 oscillator init, ext 8MHz osc with 4x PLL?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
akohlsmith



Joined: 25 Apr 2012
Posts: 26

View user's profile Send private message

PIC24F32KA304 oscillator init, ext 8MHz osc with 4x PLL?
PostPosted: Tue Aug 14, 2012 10:24 am     Reply with quote

I'm having a great deal of difficulty finding clear documentation on how to configure the oscillator with CCS 4.135.

I have a PIC24F32KA304 with an 8MHz external oscillator connected to OSCIN (Pin 30 on the package). I'd like to use the EC oscillator mode with a 4x PLL, for a Fcy of 16MHz.

The datasheet seems to indicate that this is possible, but the valid fuses declarations don't seem to exist. C:\Program Files\PICC\fuses.txt lists the following:

    EC External clock with CLKOUT
    EC_IO External clock (presumably no CLKOUT)
    E4 External osc, PLL enabled, CLKOUT
    ECPLL External osc, PLL and Fosc/4 on RA6
    ECPIO External osc, PLL and I/O on RA6
    EC_PLL4 External osc, 4x PLL
    EC_PLL8 External osc, 8x PLL
    EC_PLL16 External osc, 16x PLL
    ECL external clock with CLKOUT (PIC18), low power
    ECM same, medium power
    ECH same, high power
    ECL_IO external clock, low power
    ECM_IO, same, medium power
    ECH_IO, same high power
    ECPLL_IO, external clock with I/O on RA6


So, lots of possibilities there, not all are valid for this part.

24F32KA304.H says the following are valid for the part:

    EC
    NOOSCIO


Which suggests that I can't in fact set up the PLL with an EC oscillator option.

I use

Code:
#fuses EC,NOOSCIO,NOIESO,NOWDT


The part seems to come up, but I have 2MHz on OSCOUT although I specified NOOSCIO (and the documentation would suggest it should be 4MHz, not 2MHz). Is there something extra I need to do to configure CLKDIV?

Is there *clear* documentation on how to set this up? It's a little frustrating, especially since the manual does not actually list all the fuses and what they specifically set or what their interactions are.
akohlsmith



Joined: 25 Apr 2012
Posts: 26

View user's profile Send private message

PostPosted: Tue Aug 14, 2012 12:09 pm     Reply with quote

Just an update, my config bits do not seem to reflect the #fuses directives at all.

The top of my .c file:
Code:

#device PIC24F32KA304 ADC=10
#include <24f32ka304.h>

#fuses EC,NOOSCIO,NOIESO
#fuses NOWDT

#use delay(clock=8000000)
#use standard_io(all)
#use rs232(baud=9600, xmit=PIN_C7, rcv=PIN_C6)
#use spi(MASTER, SPI1, MODE=0, bits=8, BAUD=100000)


And my fuse bits:
[/img]
akohlsmith



Joined: 25 Apr 2012
Posts: 26

View user's profile Send private message

PostPosted: Tue Aug 14, 2012 3:51 pm     Reply with quote

I think I got it figured out. boo-urns for needing to run a program (PCW) in order to see the valid #fuses bits. That still doesn't seem to be completely documented but it's a step up from zero.

Code:
#device PIC24F32KA304 ADC=12
#device ANSI
#include <24f32ka304.h>

#fuses EC,PR_PLL,POSCFREQ_M,NOCKSFSM
#fuses OSCIO,NOIESO
#fuses NOPROTECT,NOWDT

#use delay(clock=32000000)
#use standard_io(all)
#use rs232(UART1, BAUD=9600, BITS=8, STOP=1, PARITY=N)
#use spi(MASTER, SPI1, MODE=0, BITS=8, BAUD=100000)


That seems to get the PLL installed (and the config bits seem to reflect this). I'm still not convinced that the PLL is set for x4, but there do not seem to be any #fuses lines which are valid for this part (as documented by PCW's View->Valid Fuses).
jeremiah



Joined: 20 Jul 2010
Posts: 1322

View user's profile Send private message

PostPosted: Tue Aug 14, 2012 4:33 pm     Reply with quote

Are you sure you have 4.135? I looked at the .h file for the chip and found alot more than the two you list.

I looked at the compiler manual under #fuses and it says:
Quote:

options vary depending on the device. A list of all valid options has been put at the top of each devices .h file in a comment for reference. The PCW device edit utility can modify a particular devices fuses. The PCW pull down menu VIEW | Valid fuses will show all fuses with their descriptions.


I took a look at the Valid Fuses option in the CCS IDE and gives descriptions for each fuse. I only took a look at about 10 or so fuses, but they appeared to match the data sheet for the chip.

Maybe you were using a non CCS IDE like mplab? It makes it harder to find things sometimes. Also one thing to watch out for is that even if you don't specify a fuse, the compiler will generate default ones for you. You can see what these are at the bottom of the .LST file. For the new chips, it is always good to make sure the default ones it tries to load are what you want and that the fuses listed in the Valid Fuses window are correct.
akohlsmith



Joined: 25 Apr 2012
Posts: 26

View user's profile Send private message

PostPosted: Tue Aug 14, 2012 4:37 pm     Reply with quote

I only listed the ones from the first list that existed in the header file. There are of course a LOT more in the header file, but none pertaining to the primary oscillator config.

I'm getting there. Now I'm fighting the documentation again; the manual (July 2012) says the timer setup function for timer 1 is setup_timer_1(config) yet what works appears to be setup_timer1(config, count) and not resetting the timer value in the ISR. I found this second method on the forums here.
jeremiah



Joined: 20 Jul 2010
Posts: 1322

View user's profile Send private message

PostPosted: Tue Aug 14, 2012 4:39 pm     Reply with quote

Sounds like you are using the 8bit compiler manual instead of the 16bit compiler manual. 8 bit chips tend to use setup_timer_x() while 16 bit chips use setup_timerx()

Use the one for PCD, PCWHD as those are for the 16bit parts (PIC24 and dsPIC).

EDIT:
As far as selecting clock is concerned, looks like the only two fuses I can find that you need are:

EC
PR_PLL

That will set the chip to external oscillator mode and route it through the PLL as you suspect. If I were you, I would check the FUSES in the LST file and see if they set/clear the appropriate bits for those fuses. Some of the newer chips aren't completely supported yet and still have bugs.

Alternately, you could try a quick while loop to see if the oscillator is ticking correctly:
Code:

while(TRUE){
   output_toggle(PIN_A7);  //or any pin you want
   delay_ms(500)
}


If your oscillator settings are correct, it should toggle every 500ms (a 1 second period square wave).

Also, just for kicks, try the following instead of what you say:
Code:

#use delay(osc=8000000,clock=32000000)

See if that makes a difference at all.


I tried the following code and it compiled and the LST file at least looked like it was calculating the delay correctly. I don't have hardware to test against

Code:

#case
#include <24f32ka304.h>

#fuses EC,PR_PLL,NOOSCIO,NOIESO
#fuses NOWDT

#use delay(osc=8000000,clock=32000000)

void main(){
   while(TRUE){
      output_toggle(PIN_A7);
      delay_ms(500);
   }

}


Also, if you look at the Valid Fuses description of the NOOSCIO fuse, you will see that it enables the clock output, while OSCIO enables general purpose IO for the pin instead, which makes sense, given the name.
akohlsmith



Joined: 25 Apr 2012
Posts: 26

View user's profile Send private message

PostPosted: Wed Aug 15, 2012 3:04 pm     Reply with quote

Nice. As you suspected, I had NOOSCIO and OSCIO mixed up. I'll also give that enhanced delay line a shot, as that would explain why there is no way to configure the PLL. Giving the source and output clock in the delay line would certainly be sufficient to configure the PLL.

Thank you for taking the time to help untangle me regarding this.
akohlsmith



Joined: 25 Apr 2012
Posts: 26

View user's profile Send private message

PostPosted: Wed Aug 22, 2012 11:43 am     Reply with quote

Just a followup.

24F32KA304, 8MHz oscillator connected to OSCI/CLKI (pin 30 on my particular package).

Code:

#fuses EC,PR_PLL,POSCFREQ_M,NOCKSFSM
#fuses OSCIO,NOIESO,SOSC_DIGITAL
#fuses NOPROTECT,NOWDT

#use delay(clock=32000000)


Produces a 32MHz internal clock (i.e. it correctly sets up the PLL); I have a timer set up for 1ms interrupts and I've verified with an oscilloscope that I have the timing set up as expected. It does not appear that
Code:
#use delay(osc=8000000,clock=32000000)
is a requirement, but I think it'd be a good idea to use that invocation if only for clarity.

Thanks again for the assistance.
jeremiah



Joined: 20 Jul 2010
Posts: 1322

View user's profile Send private message

PostPosted: Wed Aug 22, 2012 3:35 pm     Reply with quote

Just as a point of interest on that:

The chip you are using only has a 4xPLL so there is very little to setup. For chips that have a more configurable PLL, the line I suggested will sometimes manage the rest of the configuration (such as multipliers/dividers in the PLL) for other chips.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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