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

FUSES for PIC18F4550 to run at 32kHz , 1 MHz or 4 MHz ?

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



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

FUSES for PIC18F4550 to run at 32kHz , 1 MHz or 4 MHz ?
PostPosted: Mon May 27, 2013 8:15 am     Reply with quote

Hello i am running PWM with PIC18F4550 with 20MHz crystal at 48MHz speed .

Code:
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN

#use delay(clock=48000000)


The problem is that at 48MHz i can slow down the PWM to rougly if i calculate exact 2900 Hz. And i need it to be much much slower 100-500Hz.

Thats why i want to run the pic using either the internal 32kHz OSC ( i have a 20MHz crystal hooked up to my circuit board but with the right fuses it shouldnt be a problem , right ? ) , either 1 mhz or 4 Mhz using the 20MHz crystal .

Can you help me with the fuses for running at 32kHz/1MHz/4MHz ? Getting the fuses on 16F877A was much much easier for me but i am getting confused on 18F4550.

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Mon May 27, 2013 8:47 am     Reply with quote

The minimum clock you can run USB at is typically 8MHz.
So do you want USB?.
If so, you cannot clock the CPU this slow. If not, why use the 4550?.....

You can use the CPUDIV divider to drop the speed a lot.
So without changing anything else:
CPUDIV1 - clock 48MHz
CPUDIV2 - clock 32Mhz
CPUDIV3 - clock 24MHz
CPUDIV4 - clock 16MHz

Then if you use the HS fuse, instead of HSPLL
CPUDIV1 - clock 20MHz
CPUDIV2 - clock 10MHz
CPUDIV3 - clock 6.66Mhz
CPUDIV4 - clock 5Mhz

Then if you select the INTRC fuse, instead of HS/HSPLL, the _CPU_ will switch to using the INTRC oscillator block. You still need the crystal attached to run USB, and the PLL5 fuse to set this up.
You can then use CLOCK=8MHz, or CLOCK=4MHz to select these frequencies from the INTRC source _but_, I know USB runs OK at 8MHz, however at 4MHz, there were timing issued. Going below here, and there is no point in using the 4550.

Now, seriously, if the PWM needs to be this slow, just look at doing a software PWM using a timer interrupt. The whole 'point' of the hardware unit, is to give _high speeds_ beyond what simple software approaches can manage....

With care, 6.66MHz would possibly work, and this would allow the PWM, to go down to about 407Hz.

Best Wishes
tcruise7771



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

PostPosted: Mon May 27, 2013 9:09 am     Reply with quote

Thank you Ttelmah i saw other post of you explaining the OSC options for 4550 , and using thanks to you i got the pic running at 5MHz and slowed down the PWC cycle to ~305Hz. I am using those fuses
Code:

#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV4,VREGEN     //5Mhz


I am using 18F4550 because i have 3 PCS of the 4550 and one of 16F877A . My project has a multiple circuits and i use 2 of the 4550 and one 16F877A , so i have only one 18F4550 avalable . I plan to wrewrite the code for the 16F877A to 18F4550 and have the 16F877A for PWM but right now it seems more easy for me to use the 18F4550 for PWM .

I do not use the USB in the PWM circuitboard so i dont care for the USB speed . It is a long explanation of why i need to use hardware PWM at range 100-500 Hz and i dont want to flood the thread.

Thought 305Hz PWM is slow enough for my project , Is there a way to run the 18F4550 at 32kHz internal osc speed ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Mon May 27, 2013 12:29 pm     Reply with quote

Yes, just select INTEC, and set the clock to 31000. The compiler will program the internal oscillator to give this.
Remember there are two 32kish rates. 31250, and 31000. The former comes from the HFintosc, the second from the LF. The former is about +/-10% accurate, the latter about +/-16%.

Best Wishes
tcruise7771



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

PostPosted: Tue May 28, 2013 2:33 am     Reply with quote

Thanks Ttelmah , if i select INTEC what other fuses i would need to select to tell to use the first +/-10% , HF ? Does that 10% is constant during the PIC running time, or it changes like every second ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Tue May 28, 2013 3:21 am     Reply with quote

Just the clock rate.
Select 31000, or 31250.

You can always verify what the compiler does, by simply loading the file into MPLAB, running it's simulator, and letting the code run to the first instruction in the main. Then look at what the oscillator bits are set to.

You can use 'setup_oscillator' to physically ensure the right mode is selected after boot. You also have an option with this, to 'tweak' the timing, but obviously this then needs to be tuned for each chip.
So:

setup_oscillator(OSC_INTRC|OSC_31250,23);

sets the 'osctune' to 23.

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