View previous topic :: View next topic |
Author |
Message |
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
Internal OCS and 18f1220 not working as expected |
Posted: Wed May 23, 2007 11:43 am |
|
|
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
|
|
Posted: Wed May 23, 2007 12:13 pm |
|
|
Try putting your use delay after #fuses.
Avery |
|
|
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
|
Posted: Wed May 23, 2007 12:16 pm |
|
|
Will do, but it was the wizard that set it up this way.
[no change] |
|
|
Guest
|
|
Posted: Wed May 23, 2007 12:48 pm |
|
|
use setup_oscillator() to change clock to 8mhz as soon as possible in your startup code. |
|
|
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
|
Posted: Wed May 23, 2007 12:55 pm |
|
|
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
|
|
Posted: Wed May 23, 2007 1:04 pm |
|
|
What's your compiler version ? |
|
|
jimcbride
Joined: 05 Apr 2006 Posts: 23
|
|
Posted: Wed May 23, 2007 1:07 pm |
|
|
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
|
|
Posted: Wed May 23, 2007 1:50 pm |
|
|
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
|
|
Posted: Wed May 23, 2007 2:09 pm |
|
|
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
|
|
Posted: Wed May 23, 2007 2:15 pm |
|
|
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
|
|
Posted: Wed May 23, 2007 2:28 pm |
|
|
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
|
|
Posted: Wed May 23, 2007 2:44 pm |
|
|
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
|
|
Posted: Thu May 24, 2007 3:38 pm |
|
|
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... |
|
|
|