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

CLKOUT on PIC 18f26k20

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



Joined: 27 Aug 2012
Posts: 4

View user's profile Send private message

CLKOUT on PIC 18f26k20
PostPosted: Fri Jun 14, 2013 4:29 am     Reply with quote

hi i am new in programming. i have one problem. i need clock output. as i read in the datasheet of pic18f26k20, it can provide clock output at pin CLKOUT. since i need to minimize components use, i use internal oscillator. what i read from datasheet if i use INTOSC, i can get Fosc/4 at pin A6.

this is my program.
Code:

#include <18F26K20.H>
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOMCLR
#use delay(clock=64000000,internal)

void main()
{
   while(1)
   {
      output_high(pin_b0);
      delay_ms(1000);
      output_low(pin_b0);
      delay_ms(1000);     
   }
}


when i turn on the PIC and connect pin A6, i not get the clock output. is there any fuses that i have miss? i use CCS C Compiler V4.128 and pickit 2 v2.61.

thanks and sorry for my bad english.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Jun 14, 2013 8:04 am     Reply with quote

you need to check the header file and select
the proper fuse.

i think
INTRC
is not correct for this part -to get clock out
ALSO without HSPLL selected - trying to set
use_delay of 64mhz maybe in conflict with the limited number of
#fuses you have now.
faqrul



Joined: 27 Aug 2012
Posts: 4

View user's profile Send private message

PostPosted: Fri Jun 14, 2013 9:00 am     Reply with quote

thanks for reply. i were checked the header. i think for select oscillator only this choices LP,XT,HS,RC,EC,EC_IO,H4,RC_IO,INTRC_IO,INTRC. i have check for datasheet for oscillator. they give ten of choices,

1. LP Low-Power Crystal
2. XT Crystal/Resonator
3. HS High-Speed Crystal/Resonator
4. HSPLL High-Speed Crystal/Resonator with PLL enabled
5. RC External Resistor/Capacitor with FOSC/4 output on RA6
6. RCIO External Resistor/Capacitor with I/O on RA6
7. INTOSC Internal Oscillator with FOSC/4 output on RA6 and I/O on RA7
8. INTOSCIO Internal Oscillator with I/O on RA6 and RA7
9. EC External Clock with FOSC/4 output
10. ECIO External Clock with I/O on RA6

so i think i should use INTRC. just now i was change the clock to 8MHz but i got same result. do u have suggestion which #fuses i need use?

thank you very much
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Jun 14, 2013 10:45 am     Reply with quote

look at the .LST file generated on successful compile.

at the end is a list of the actual fuse words that will be programmed to the chip

then see how what you want is represented by comparing the generated fuse words with the datasheet for your part.

here is an example for a different pic than yours ( 18f4620) in a project compile i did a few minutes ago.

it is an 18f family member and gives you a sense of what you are looking for:

Quote:

Configuration Fuses:
Word 1: 0800 INTRC_IO NOFCMEN NOIESO
Word 2: 1E16 PUT BROWNOUT BORV27 NOWDT WDT32768
Word 3: 0100 CCP2C1 NOPBADEN NOLPT1OSC NOMCLR
Word 4: 0081 STVREN NOLVP NOXINST NODEBUG
Word 5: C00F NOPROTECT NOCPB NOCPD
Word 6: E00F NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 400F NOEBTR NOEBTRB
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Jun 14, 2013 11:25 am     Reply with quote

What you are trying, should work.

However you may well need to use a 'setup_oscillator' line after booting to get it to do what you want. Key is that in INTRC mode, the PLL, is _not_ configurable through the fuses. Some versions of the compiler, are 'smart', and will try to set things up, but on most you have to tell them what you want.
So:
Code:

#include <18F26K20.H>
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOMCLR
#use delay(clock=64000000)

void main()
{
   setup_oscillator(OSC_64MHZ|OSC_INTRC);
   while(1)
   {
      output_high(pin_b0);
      delay_ms(1000);
      output_low(pin_b0);
      delay_ms(1000);     
   }
}

That does correctly set the fuses to run off the internal oscillator at boot, with osc/4 to A6, and then selects 16MHz with PLL.
What I'm not sure about (since it is not in the data sheet's drawings of the oscillator), is whether it will output 16MHz, or 4MHz. Since the core Fosc before the PLL, is 16Mhz.
The fact the connections used for this is not shown in the data sheet is a little 'worrying', but the text implies it should work. For instance, in MPLAB, the fuse combination says:

"Internal oscillator block, CLKOUT function on RA6, port function on RA7".

Best Wishes
faqrul



Joined: 27 Aug 2012
Posts: 4

View user's profile Send private message

PostPosted: Sat Jun 15, 2013 2:01 pm     Reply with quote

I just follow Ttelmah and its work.. Very Happy but the clock can't set 64MHz. If i set 64MHz, the delay is not correct (i refer to pin b0 since it has delay). The delay will be almost 3 second. Clock out at pin A6 i got 4MHz. When i set clock at 16MHz, the delay work fine. but it ok. I just use 16MHz for clock.

Thank you very much asmboy and Ttelmah for helping me. Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Jun 15, 2013 3:26 pm     Reply with quote

May be a compiler version problem. I'll have to check if 4.128, correctly sets the PLL. Sounds as if it doesn't. That would then give 16MHz when 64Mhz is selected. 4:1.
Try:
Code:

#include <18F26K20.H>
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOMCLR
#use delay(clock=64000000)
#byte OSCCON=getenv("SFR:OSCCON")
#bit PLLEN=getenv("BIT:PLLEN")
#define CLK_16 0x72

void main()
{
   //then instead of setup oscillator
   OSCCON=CLK_16;
   PLLEN=TRUE;
   while(1)
   {
      output_high(pin_b0);
      delay_ms(1000);
      output_low(pin_b0);
      delay_ms(1000);     
   }
}


I Haven't got 4.128, but using a couple of versions before, this does correctly setup the oscillator registers for 64Mhz operation.

Best Wishes
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