|
|
View previous topic :: View next topic |
Author |
Message |
elellilrah
Joined: 29 Aug 2007 Posts: 14
|
setup_oscillator() on PIC16F688 not working |
Posted: Fri Jan 30, 2009 2:47 pm |
|
|
I'm trying to get the PIC16F688 to run at 8MHz without success. Using compiler rev 4.085 I've tried the following:
Code: | #include <16F688.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES MCLR //Master Clear pin enabled
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#use delay(clock=8000000)
void main()
{
setup_oscillator(OSC_8MHZ);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(1)
{
}
} |
The list code is:
Code: | .................... void main()
.................... {
0004: CLRF 04
0005: BCF 03.7
0006: MOVLW 1F
0007: ANDWF 03,F
0008: MOVLW 71
0009: BSF 03.5
000A: MOVWF 0F
000B: MOVF 0F,W
000C: BCF 03.5
000D: BCF 1F.6
000E: MOVLW 00
000F: BSF 03.5
0010: MOVWF 11
0011: BCF 03.5
0012: CLRF 1A
0013: MOVLW 07
0014: MOVWF 19
.................... setup_oscillator(OSC_8MHZ);
0015: MOVLW 71
0016: BSF 03.5
0017: MOVWF 0F
0018: MOVF 0F,W
.................... setup_adc_ports(NO_ANALOGS|VSS_VDD);
0019: BCF 03.5
... |
When I look at the OSC2 pin (pin 2, 16-pin QFN PIC16F688), I only get 2MHz clocking out.
I've tried the following constants with the following results:
OSC_8MHZ - 2 MHz on OSC2
OSC_4MHZ - 1 MHz on OSC2
OSC_2MHZ - 500 kHz on OSC2
OSC_1MHZ - 250 kHz on OSC 2
I've been trying to do some timing measurements and getting numbers 4x lower than I should, causing me to look into this. The numbers above completely explain why I have wrong timing measurements, but now I need to get the PIC running at the right speed. Any suggestions? Thanks!
I'm using the ICD-U40 to program the PIC16F688 chip, running @ 4V. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 30, 2009 3:00 pm |
|
|
Quote: |
When I look at the OSC2 pin (pin 2, 16-pin QFN PIC16F688), I only get
2MHz clocking out. |
See this section of the 16F688 data sheet:
Quote: |
3.5.1 INTOSC AND INTOSCIO MODES
In INTOSC mode, OSC1/CLKIN is available for general
purpose I/O. OSC2/CLKOUT outputs the selected
internal oscillator frequency divided by 4. |
|
|
|
elellilrah
Joined: 29 Aug 2007 Posts: 14
|
All clear, now |
Posted: Fri Jan 30, 2009 5:04 pm |
|
|
PCM programmer wrote: | Quote: |
When I look at the OSC2 pin (pin 2, 16-pin QFN PIC16F688), I only get
2MHz clocking out. |
See this section of the 16F688 data sheet:
Quote: |
3.5.1 INTOSC AND INTOSCIO MODES
In INTOSC mode, OSC1/CLKIN is available for general
purpose I/O. OSC2/CLKOUT outputs the selected
internal oscillator frequency divided by 4. |
|
Thanks, PCM...it's right there, in front of me, if I knew where to look. Ah, data sheet details.
And, that suggestion lead me to timer1 having it's primary clock divided by 4 as well, hence why I got such low numbers.
Now I've got to figure out how to count higher than 255 with counter0. Thanks! |
|
|
|
|
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
|