View previous topic :: View next topic |
Author |
Message |
archcvd
Joined: 17 Jan 2008 Posts: 3 Location: Edmonton, Canada
|
Porting a program designed for 4MHz to 20MHz |
Posted: Thu Jan 17, 2008 12:11 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 12:23 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 12:25 pm |
|
|
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: 1907
|
|
Posted: Thu Jan 17, 2008 12:28 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 12:28 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 12:38 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 1:13 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 1:59 pm |
|
|
Fantastic. Thank you for all the suggestion folks. I will keep you posted as soon as I can. |
|
|
|