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

Porting a program designed for 4MHz to 20MHz

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



Joined: 17 Jan 2008
Posts: 3
Location: Edmonton, Canada

View user's profile Send private message

Porting a program designed for 4MHz to 20MHz
PostPosted: Thu Jan 17, 2008 12:11 pm     Reply with quote

I am fairly new at this so hopefully this is an obvious one for someone.

When porting a program that was designed with 4MHz as the speed in mind to a 20MHz platform, does one need to change more than the following value?

Code:
#use delay(clock=4000000)


I assumed that when one changes this statement to the proper clock speed all the delays get updated automatically, but I can't seem to get my project to run with the code.

The code itself seemed fairly universal save for this fact. So I am hoping this is the problem I overlooked. If not, I will post more details.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 12:23 pm     Reply with quote

You need to change the fuse from XT to HS. Otherwise, the 20 MHz
crystal won't oscillate.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 12:25 pm     Reply with quote

You also need to tell the compiler to change the Configuration Word because the MCU use
a different oscillator configuration, XT is used up to 4Mhz, to run at 20Mhz it is necesary to use HS.


Humberto

Edited:
Sorry PCM. almost the same answer, hope it will help to the poster.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 12:28 pm     Reply with quote

You also have to pay attention to timers to ensure that timer interrupts, PWM frequency/duty cycle, etc happen at the same rate as for the 4MHz case.
archcvd



Joined: 17 Jan 2008
Posts: 3
Location: Edmonton, Canada

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 12:28 pm     Reply with quote

I will use the PIC wizard to set the fuse to HS. If I am using the 16F819 am I correct in assuming that I do not need an external crystal for my project? I'm making this assumption because reading CCS C automatically sets the clock speed of the PIC to 20MHz when selecting this particular PIC from the drop down menu.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 12:38 pm     Reply with quote

The PIC wizard is not so clever as you will suppose to set such configuration
automatically for you. It is a kind of help but you should check if the generated code
is applicable or not reading the Microchip Datasheet for the corresponding MCU.

Quote:

am I correct in assuming that I do not need an external crystal for my project?

Nop. To run at such speed you must use an external crystal.


Humberto
zonemikelguest
Guest







PostPosted: Thu Jan 17, 2008 1:13 pm     Reply with quote

If your changing a already existing program from a 4mhz crystal to a 20mhz crystal setup (ONLY) just look for these lines and change them

this might be in your programfilename.h file

from
Code:
#fuses NOWDT,XT,NOPUT,NOLVP

to
Code:
#fuses NOWDT,HS,NOPUT,NOLVP


and this
Code:

#use delay(clock=4000000)

to
Code:
#use delay(clock=20000000)
archcvd



Joined: 17 Jan 2008
Posts: 3
Location: Edmonton, Canada

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 1:59 pm     Reply with quote

Fantastic. Thank you for all the suggestion folks. I will keep you posted as soon as I can.
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