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

Slow clock on PIC18F2620

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



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

Slow clock on PIC18F2620
PostPosted: Thu Feb 17, 2005 12:45 pm     Reply with quote

After upgrading to the latest CCS compiler and ICD-U40 firmware, we seem to be having a problem with 2620's. We've loaded a Wizard-generated program (plus some LED blinker code) into the PIC and are observing a clock rate of about 246KHz on CLKOUT, regardless of the value we use for #use delay.

Can anyone help us figure out whether this is a CCS problem or not?

--
Jeff S.

Code:
//////////// main.c
#include "main.h"

void main() {
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   while (TRUE) {
      output_toggle(PIN_A0);
   }
}

///////////////// main.h
#include <18F2620.h>
#device adc=8
#use delay(clock=8000000)
#fuses NOWDT,WDT128,INTRC, NOPROTECT, NOIESO, NOBROWNOUT, BORV21, NOPUT, NOCPD, STVREN, DEBUG, LVP, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, NOPBADEN, LPT1OSC, MCLR
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Feb 17, 2005 1:07 pm     Reply with quote

I examined the lst's produced by this code, and aside from the instructions generated for setup_comparator(), there is absolutely no difference in the .lst's when I change the #use delay() directive. I'm not savvy enough to know whether this is normal.

--
Jeff S.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Feb 17, 2005 1:51 pm     Reply with quote

#use delay does not generate code, it is simply a directive that informs the compiler how fast it should expect to processor running so it genenerates the proper delay cycles when you use delay_us(), delay_ms(), and serial comm. instructions.
It is not quite clear for me what 'change' did you expect of changing the #use delay value. It does not sets the clock speed.
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Feb 17, 2005 1:54 pm     Reply with quote

libor wrote:
#use delay does not generate code, it is simply a directive that informs the compiler how fast it should expect to processor running so it genenerates the proper delay cycles when you use delay_us(), delay_ms(), and serial comm. instructions.
It is not quite clear for me what 'change' did you expect of changing the #use delay value. It does not sets the clock speed.


According to readme.txt,

"A new function SETUP_OSCILLATOR controls and returns the state of the
internal RC oscillator on some parts. See the devices .h file for
valid options for a particular device. Note that is INTRC or INTRC_IO
is specified in #fuses and a #USE DELAY is used for a valid speed option,
then the compiler will do this setup automatically at the start of main()."

So I would expect to see some kind of assembly change, because I satisfy the two conditions mentioned there. We have always used #use delay() to govern the internal oscillator speed of our PICs in the past.

--
Jeff S.
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Feb 17, 2005 4:10 pm     Reply with quote

CCS Support suggested that I switch the #use delay() and #fuses lines, so that #use delay() would be aware that I was using INTRC. Did that, and the problem was solved. I also told them the Project Wizard was responsible for generating the odd code.

--
Jeff S.
jcjneudo



Joined: 21 Feb 2005
Posts: 4

View user's profile Send private message

32MHz operation with 18F4620
PostPosted: Tue Feb 22, 2005 9:25 am     Reply with quote

Having the "#use delay" after the "#fuses" seems to work, at least for 8MHz. Unfortunately, it does not seem to do the right thing for 32MHz operation--there does not seem to be any way to enable the PLL with the internal oscillator (at least using library functions).

Any work-arounds?

(I'm using PCWH v 3.212)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 22, 2005 12:22 pm     Reply with quote

Quote:
there does not seem to be any way to enable the PLL with the
internal oscillator


Study the 18F8620 data sheet, in the Oscillator section.

"The PLL can only be enabled when the oscillator configuration
bits are programmed for HS mode.
If they are programmed
for any other mode, the PLL is not enabled and the system clock
will come directly from OSC1."

Link to the data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39609b.pdf
jcjneudo



Joined: 21 Feb 2005
Posts: 4

View user's profile Send private message

32MHz with INTOSC on 18F4620
PostPosted: Wed Feb 23, 2005 7:32 am     Reply with quote

Umm, the data sheet "PCM PROGRAMMER" posted is for the PIC18F6520/8520/6620/8620/6720/8720. Perhaps the limitation is valid for those chips. But for the PIC18F4620 (see DS39626B), the PLL can be connected to the internal oscillator in software. If the primary oscillator is the internal oscillator (INTOSC), the PLL can be enabled through use of PLLEN in OSCTUNE<6> (see section 2.6.4).

I was finally able to get this working by using the following code, but it would be better if CCS handled it as per the documentation (ie, if you set fuses and delay, the oscillator will be set up automatically before main is called):

Code:

#fuses INTRC_IO,NOIESO,NOFCMEN,WDT1,NOWDT,BROWNOUT,NOPUT,NOPROTECT,CCP2C1,NOLVP,NOXINST,NOMCLR
#use delay (clock=32000000)
.
.
.

  SETUP_OSCILLATOR(OSC_8MHz,0);
  OSCTUNE = 0b01000000;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 8:35 am     Reply with quote

OK, but it's understandable that I missed your PIC type, because
this thread was about 18F2620 problems, and you tacked your
problem onto it. I missed seeing the small title on your post.
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