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 CCS Technical Support

How to get PIC24 running 32Mhz *solution found*

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



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

How to get PIC24 running 32Mhz *solution found*
PostPosted: Wed Jul 02, 2014 2:55 pm     Reply with quote

Hi,
What do I need to add/change to get the pic running on 32Mhz? Code below runs on 16 Mhz. I see pulses of 250ns on my scope.
The pic 24 uses 2 clock tics per instruction, so on 32Mhz the instruction time should be 62.5ns. The pulse uses 2 assembler instructions. So I should measure 125ns pulses instead of 250ns.

I also tried the #use delay(clock=32000000).. neither

and indeed changing the number to 16000000 gives also 250ns pulses...

Code:

#include <24FJ128GC006.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled

#device ICSP=1

#define dClockSpeed 32000000

void main()
{
   setup_oscillator(OSC_Internal,dClockSpeed);
 
   while(TRUE)
   {
      output_high(pin_E5);
      output_low(pin_E5);
      output_high(pin_E5);
      output_low(pin_E5);
      output_high(pin_E5);
      output_low(pin_E5);
      output_high(pin_E5);
      output_low(pin_E5);
   }

}

_________________
Regards, Edwin. PCWHD v5.114


Last edited by Torello on Wed Jul 23, 2014 2:23 pm; edited 1 time in total
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Wed Jul 02, 2014 3:53 pm     Reply with quote

Just a guess. I don't know this device.
Does setup_oscillator(x) do everything needed or is there also a fuse that has to be set?
Since the two clock speeds give the same result it almost seems like it is defaulting to a clock source/speed. Perhaps not the one you intended?
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Wed Jul 02, 2014 5:02 pm     Reply with quote

Most PIC24's rely on the #fuses and #use delay() statements to be correct. You are missing both (you didn't specify any oscillator fuses at all) in the code you provided. You don't typically need setup_oscillator() unless you are changing stuff at run time.

I've never used a USB enabled PIC and I don't have that particular one to test against, but if I was gonna take a first stab at it with what I am used to on other PIC24 chips, I would try:

Code:

#case
#include <24FJ128GC006.h>

#device ICSP=1

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#fuses NOPR
#fuses FRC_PLL
#fuses NOCKSNOFSM    //Clock Switching is disabled, fail Safe clock monitor is disabled
#fuses NOIESO        //Internal External Switch Over mode disabled
#fuses PLL2          //Divide By 2(8MHz oscillator input)

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

void main()
{
   
 
   while(TRUE)
   {
      output_high(PIN_E5);
      output_low(PIN_E5);
      output_high(PIN_E5);
      output_low(PIN_E5);
      output_high(PIN_E5);
      output_low(PIN_E5);
      output_high(PIN_E5);
      output_low(PIN_E5);
   }

}


It probably isn't enough to use USB, but you didn't specify you needed that.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Thu Jul 03, 2014 1:32 am     Reply with quote

Thanks for your help. No, I don't need USB.
I'm just looking what it will take to migrate my 16K lines PIC18 code to this new processor using CCS.

If build-in functions in Pic24 are (very) different in comparison to the Pic18 , I need to find solid info about that. Otherwise I'll get lost in a swamp, and it will take me ages.
Build in help seems to be too short.

I'll give your example a try.
_________________
Regards, Edwin. PCWHD v5.114
Ttelmah



Joined: 11 Mar 2010
Posts: 19563

View user's profile Send private message

PostPosted: Thu Jul 03, 2014 2:12 am     Reply with quote

Most things are the same.

Big differences are with the maths types.
This is where being 'explicit', and using types like uint8_t, rather then generically 'int', makes it much easier to shift code. Use a text editor, and it's search and replace, and change the types used throughout the code, to be definitive. Be particularly careful about signed, versus unsigned.

So long as your code only used generic functions (rather than doing things like direct port IO for example), 99% should copy and run. The bits that cause problems are the changes to the physical hardware (so 16 bits as a port size, different timers, etc. etc..).

If you look at a lot of the CCS examples, they are written to merrily compile for PIC16/PIC18/PIC24 interchangeably. If you look at something like ex_extee.c, the same core code is being used for all the chip versions, with just the header changing.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Sat Jul 05, 2014 10:17 am     Reply with quote

Well still can't get the Pic24 running on 32Mhz with use of the CCS supplied functions. tried many combinations of *use delay(..) or setup_oscillator(). It ends up to an max of 16Mhz.

The built in Pic24 wizard generates only:
#device ICSP=1
#use delay(internal=32MHz)

And compiled and loaded in my chip also runs 16Mhz

Seems no other options left then figuring out what the datasheet says about the oscillator circuitry and manually load all the configuration registers correctly.
_________________
Regards, Edwin. PCWHD v5.114
Ttelmah



Joined: 11 Mar 2010
Posts: 19563

View user's profile Send private message

PostPosted: Sat Jul 05, 2014 10:45 am     Reply with quote

Critical question. What compiler version?.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Sun Jul 06, 2014 5:48 am     Reply with quote

The latest: PCWHD 5.026
_________________
Regards, Edwin. PCWHD v5.114
temtronic



Joined: 01 Jul 2010
Posts: 9254
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 06, 2014 6:37 am     Reply with quote

OK, I don't use that PIC but...

any chance this line...
#device ICSP=1

forces a set of default fuses ?
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

How to get PIC24 running 32Mhz *solution found*
PostPosted: Wed Jul 23, 2014 2:23 pm     Reply with quote

Finally found a work-arround. Still think there is something messed up with #use delay() for the Pic24FJ128GC006.

Any way, got it working by using the 2 #Fuses; FRC_PLL and PLL1. And then the #use delay(clock=32Mhz). The option clock does not alter previous #fuses settings.

Code:

#include <24FJ128GC006.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled

#device ICSP=1

#fuses FRC_PLL                 
#fuses PLL1
#use delay(clock=32Mhz)         //Don't use Internal=32Mhz !!

void main()
{
   while(TRUE)
   {
      output_high(pin_E5);
      output_low(pin_E5);
      output_high(pin_E5);
      output_low(pin_E5);
      output_high(pin_E5);
      output_low(pin_E5);
      output_high(pin_E5);
      output_low(pin_E5);
   }
}

_________________
Regards, Edwin. PCWHD v5.114
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