|
|
View previous topic :: View next topic |
Author |
Message |
C Turner
Joined: 10 Nov 2003 Posts: 40 Location: Utah
|
Trying to get the 4620's PLL to work with the internal clock |
Posted: Wed Apr 29, 2009 6:59 pm |
|
|
Ok, I've pulled out my hair for long enough.
I've searched the forms and can find nothing obvious, but I've not been able to figure out why I can't get the '4620 to run at 32 MHz using the internal clock. I've written "minimal" program that shows what is going on.
With the code below, I'm seeing the letter "J" at 2400 baud, about once-per-second. This is, in fact, exactly what I would expect if the clock is running at 8 MHz instead of 32 MHz.
If I add a little bit more to the program to display register values, I see the OSCCON contains 76H (which includes the IOFS bit) and that OSCTUNE contains 40H - both values that I would expect if I've programmed things correctly. If I look at an already-programmed part and read the fuse setting, I see that the appropriate byte contains 08H, just as is shown on the listing.
Nothing related jumped out as I skimmed over the errata for the 4620. What am I missing?
CT
P.S. I originally used "setup_oscillator(OSC_32_MHZ | OSC_INTRC)" but I got the same results, so I decided to set the registers directly.
Code: |
CCS PCH C Compiler, Version 3.249, 32532 29-Apr-09 18:35
Filename: C:\Program Files\PICC\projects\acp_preprocessor\test1a.lst
ROM used: 126 bytes (0%)
Largest free fragment is 65410
RAM used: 5 (0%) at main() level
6 (0%) worst case
Stack: 1 locations
*
00000: GOTO 0036
....................
.................... #include <18f4620.h>
.................... //////// Standard Header file for the PIC18F4620 device ////////////////
.................... #device PIC18F4620
.................... #list
....................
.................... //
.................... #fuses NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP,INTRC_IO,NOMCLR
.................... #use delay(clock=32000000, RESTART_WDT) // calibrate delays for clock speed - delays restart WDT
00004: CLRF FEA
00006: MOVLW 06
00008: MOVWF FE9
0000A: MOVF FEF,W
0000C: BZ 0032
0000E: MOVLW 0A
00010: MOVWF 01
00012: MOVLW BF
00014: MOVWF 00
00016: CLRWDT
00018: DECFSZ 00,F
0001A: BRA 0016
0001C: DECFSZ 01,F
0001E: BRA 0012
00020: MOVLW 5E
00022: MOVWF 00
00024: DECFSZ 00,F
00026: BRA 0024
00028: NOP
0002A: NOP
0002C: CLRWDT
0002E: DECFSZ FEF,F
00030: BRA 000E
00032: GOTO 007A (RETURN)
.................... #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, RESTART_WDT, BITS=8, PARITY=N)
.................... //
.................... //
.................... #byte OSC_CON = 0xfd3
.................... #byte OSC_TUNE = 0xf9b
.................... void main(void)
.................... {
00036: CLRF FF8
00038: BCF FD0.7
0003A: CLRF FEA
0003C: CLRF FE9
0003E: MOVLW 70
00040: MOVWF FD3
00042: MOVLW 40
00044: MOVWF F9B
00046: MOVF FD3,W
00048: BCF FB8.3
0004A: MOVLW 33
0004C: MOVWF FAF
0004E: MOVLW 22
00050: MOVWF FAC
00052: MOVLW 90
00054: MOVWF FAB
00056: MOVF FC1,W
00058: ANDLW C0
0005A: IORLW 0F
0005C: MOVWF FC1
0005E: MOVLW 07
00060: MOVWF FB4
.................... OSC_CON = 0b01110010; // 8 MHz, internal oscillator
00062: MOVLW 72
00064: MOVWF FD3
.................... OSC_TUNE = 0b01000000;
00066: MOVLW 40
00068: MOVWF F9B
.................... while(TRUE) {
.................... putc('J');
0006A: MOVLW 4A
0006C: CLRWDT
0006E: BTFSS F9E.4
00070: BRA 006C
00072: MOVWF FAD
.................... delay_ms(250);
00074: MOVLW FA
00076: MOVWF 06
00078: BRA 0004
.................... }
0007A: BRA 006A
.................... }
0007C: SLEEP
Configuration Fuses:
Word 1: 0800 NOIESO INTRC_IO NOFCMEN RESERVED
Word 2: 1E1E BROWNOUT NOWDT BORV21 PUT WDT32768
Word 3: 0300 CCP2C1 PBADEN NOLPT1OSC NOMCLR RESERVED
Word 4: 0081 STVREN NODEBUG NOLVP NOXINST RESERVED
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 400F NOEBTR NOEBTRB
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 29, 2009 9:28 pm |
|
|
This program works.
Code: | #include <18F4620.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=32000000)
//====================================
void main()
{
setup_oscillator(OSC_32MHZ | OSC_PLL_ON);
while(1)
{
output_high(PIN_B0);
delay_ms(500);
output_low(PIN_B0);
delay_ms(500);
}
} |
|
|
|
C Turner
Joined: 10 Nov 2003 Posts: 40 Location: Utah
|
Trying to get the 4620's PLL to work with the internal clock |
Posted: Thu Apr 30, 2009 10:22 am |
|
|
I see the problem: You *can't* turn on OSCCON bits 0 or 1 and expect it to work. In other words, "Primary Oscillator" should be enabled, and NOT "Internal Oscillator Block."
Somehow, if you wanted to use the "Internal Oscillator Block" with the PLL, I'd have thought one might turn it on.
Stupid me!
Thanks for the help, PCM,
CT |
|
|
hobiadami
Joined: 17 Oct 2006 Posts: 35 Location: City of Concrete
|
pin change |
Posted: Thu Apr 26, 2012 3:18 pm |
|
|
can't I use the oscillator pins as I/O with this setup?
I've used the code above on real hardware just by changing the pin numbers to pin_a6 or a7 and didn't be able to blink a led connected to those pins.
I'm using 4.114 _________________ www.endtas.com |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 26, 2012 5:28 pm |
|
|
Post your small compilable test program. |
|
|
hobiadami
Joined: 17 Oct 2006 Posts: 35 Location: City of Concrete
|
code |
Posted: Fri Apr 27, 2012 12:59 am |
|
|
Thanks for the reply,
The program is absolutely same as yours. I just changed the output pin. A6 and A7, didn't change anything. Other pins are okay. Only the oscillator pins don't blink the led. I've tested with a brand new 18F4620 as well.
Code: |
#include <18F4620.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=32000000)
//====================================
void main()
{
setup_oscillator(OSC_32MHZ | OSC_PLL_ON);
while(1)
{
output_high(PIN_A6);
delay_ms(500);
output_low(PIN_A6);
delay_ms(500);
}
} |
_________________ www.endtas.com |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Fri Apr 27, 2012 4:04 am |
|
|
Change to:
Code: |
#include <18F4620.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=32000000)
//====================================
void main(void) {
setup_oscillator(OSC_32MHZ | OSC_INTRC);
while(TRUE) {
output_high(PIN_A6);
delay_ms(500);
output_low(PIN_A6);
delay_ms(500);
}
}
|
This is one of those nasty little 'compiler version' ones.
First, OSC_32_MHZ, includes the PLL_ON bit, Doesn't matter to duplicate it, but doesn't actually do anything.
However key is that on some compilers, the OSC_xxMHz settings, for the two PLL modes, don't have the select to say 'use the internal oscillator'. When the PLL is selected, the internal oscillator is not defined as the primary oscillator (oddity of the chip...), so if you use them without specifying this, they switch to 'OSC_NORMAL', which then doesn't work, and the chip stops. Hence then your pin doesn't toggle....
Best Wishes |
|
|
hobiadami
Joined: 17 Oct 2006 Posts: 35 Location: City of Concrete
|
:) |
Posted: Sat Apr 28, 2012 1:35 pm |
|
|
Thanks Thelmah, this solved it. _________________ www.endtas.com |
|
|
|
|
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
|