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

Internal OCS and 18f1220 not working as expected

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



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

Internal OCS and 18f1220 not working as expected
PostPosted: Wed May 23, 2007 11:43 am     Reply with quote

I have been playing around with my fuses all day long but can't seem to get my internal oscillator to run at 8Mhz. I have deduced that it is running around 31/32kHz by a 500Ms delay flashing an led and using that number (32kHz) in my #USE delay().

.h file
Code:
#include <18F1220.h>
#device ICD=TRUE
#device adc=8
#use delay(clock=8000000)
//#use rs232(baud=9600,parity=N,xmit=PIN_B1,rcv=PIN_B4,bits=9)
#fuses NOWDT,WDT128,INTRC, NOFCMEN, NOBROWNOUT, BORV20, NOPUT, NOCPD, NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTC, NOIESO, NOEBTR, NOEBTRB, NOMCLR, NOPROTECT, NOCPB, NOWRTB

.c file
Code:
void main()
{

   setup_adc_ports(VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   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);

while(1){
      output_high(PIN_B0);
      delay_ms(500);
      //putc('U');
      output_low(PIN_B0);
      output_low(PIN_B1);
      output_low(PIN_B2);
      delay_ms(500);
}
}

When I set up using a 10MHz xtal, the debug window shows mcu running at 10MHz. When set up at shown above I get mcu running at 0.03MHz.

Somehow I am getting the wrong setting for the internal osc, I suspect something to do with this statement from the data sheet:
Quote:
The other clock source is the internal RC oscillator
(INTRC), which provides a 31 kHz output. The INTRC
oscillator is enabled by selecting the internal oscillator
block as the system clock source, or when any of the
following are enabled:
• Power-up Timer
• Fail-Safe Clock Monitor
• Watchdog Timer
• Two-Speed Start-up

I am also having trouble getting MPLAB to work so I can look at the regitsers. I forgot how to look at the OSCCON register in CCS.

Any ideas?
amcfall



Joined: 20 Oct 2005
Posts: 44

View user's profile Send private message

PostPosted: Wed May 23, 2007 12:13 pm     Reply with quote

Try putting your use delay after #fuses.

Avery
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Wed May 23, 2007 12:16 pm     Reply with quote

Will do, but it was the wizard that set it up this way.
[no change]
Guest








PostPosted: Wed May 23, 2007 12:48 pm     Reply with quote

use setup_oscillator() to change clock to 8mhz as soon as possible in your startup code.
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Wed May 23, 2007 12:55 pm     Reply with quote

Done. still runs slow and shows mcu running at 0.03 MHz.

Got mplab working, OSCCON shows a value of 00000100, it is putting the thing at 31kHz. Now how to write to that register?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2007 1:04 pm     Reply with quote

What's your compiler version ?
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Wed May 23, 2007 1:07 pm     Reply with quote

My versionis 3.188.
Once I figured out how to use #byte osccon = 0xfd3 to see the osccon register and set that in my code, now the thing runs correctly. It starts out as 0.03 MHz but after it goes through the fuse code it changes to 8MHz.
Wierd....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2007 1:50 pm     Reply with quote

Here's the compiler startup code for vs. 3.188, compiled with your
program for the 18F1220. It sets the OSCCON register to 0x70, which
should work. I wonder if your programmer is correctly programming
the oscillator config bits. What is your programmer ?
Code:

................... void main()   
.................... {   
002E:  CLRF   FF8
0030:  BCF    FD0.7
0032:  CLRF   FEA
0034:  CLRF   FE9
0036:  BCF    FC2.7
0038:  BCF    FC2.6
003A:  MOVLW  FF
003C:  MOVWF  FC1
003E:  MOVLW  70
0040:  MOVWF  FD3   // Set OSCCON = 0x70
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Wed May 23, 2007 2:09 pm     Reply with quote

After posting that it worked it stopped working. Not sure what I changed. It may have had to do with compiling in mplab???
I forced OSCCON to be 0x70 and now it says it runs at 7.95 MHz. I had it saying 8 MHz Just not sure why.

I am using the ICD-U40 ICD.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2007 2:15 pm     Reply with quote

Your program is too complicated for a test program. Try the program
shown below. Assuming that your PIC is running at +5v, this should work.
It will toggle an LED on pin B0. (The LED should have a series resistor.
Use a value from 220 to 470 ohms).
Code:

#include <18F1220.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)

void main()
{

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }
}
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Wed May 23, 2007 2:28 pm     Reply with quote

This code also works and puts me at 7.95 MHz. I will poke through the fuses one ata time and see where the problem was. Is it possible to now use the 4x multiplier to get ~ 32MHz from the internal clock?
Ttelmah
Guest







PostPosted: Wed May 23, 2007 2:44 pm     Reply with quote

Not on this chip. Some others, do allow the PLL to be used with the internal oscillator (The 18F1330 for example), but on the 1220, the PLL is only available when using the external oscillator.

Best Wishes
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Thu May 24, 2007 3:38 pm     Reply with quote

Thanks much for your help. I have found that the debugger will give me slightly different mcu speed reading when connected in different circuits. i.e. my demo board shows it runs at 8MHz, where my actual circuit shows 7.95 MHz. This explains some of my previous confusion. 18F1330 samples are on order, thanks for pointing that chip out. I like the idea of running at 32MHz with no xtal. Now if I can just get these 1-wire chips talking to each other I will be the hero...
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