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

pll config | pic18f4550 | picc pcb 4.11

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



Joined: 17 Nov 2012
Posts: 23

View user's profile Send private message

pll config | pic18f4550 | picc pcb 4.11
PostPosted: Mon Dec 17, 2012 4:34 am     Reply with quote

Hello,
I'm tring to run my microcontroller at 32Mhz without using external quartz.
I tried this code but the delay was not respected even my servo didn't move.

Code:
#include <18f4550.h>

#FUSES NOWDT
#FUSES WDT128
#FUSES PLL1
#FUSES CPUDIV1
#FUSES NOUSBDIV
#FUSES INTRC_IO
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES BORV27
#FUSES NOVREGEN
#FUSES NOPBADEN
#FUSES NOLPT1OSC
#FUSES NOMCLR
#FUSES NOLVP
#FUSES NOXINST

#use delay(clock=32000000)
 

#use rs232 (BAUD=9600, xmit=PIN_C6, rcv=PIN_C7)
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
//intenal regiter
#byte porta = 0xF80
#byte portb = 0xF81
#byte portc = 0xF82
#byte portd = 0xF83
#byte porte = 0xF84
#byte trisa = 0xF92
#byte trisb = 0xF93
#byte trisc = 0xF94
#byte trisd = 0xF95
#byte trise = 0xF96

//commande moteur
#bit sense_1=portb.3 //ccp1
#bit sense_2=portb.2 //ccp2
//externs
#bit epi=portc.0
#bit servo1=porte.1
#bit servo2=porte.0
#bit epic=porte.2

int16 cycle=0;
int8 angle1=32;
int8 angle2=50;

//commande servomo-moteur
#INT_TIMER0 //each 0.102us
   void servo()//31 => 1ms ; 62 => 2ms ; 5° by step
   {
      cycle++;
      if (cycle == 625) {servo1=1;servo2=1;cycle=0;}
      if (cycle == angle1) servo1=0;
      if (cycle == angle2) servo2=0;
   }
   

void main (){
         //76543210
   trisa=0b11111111;                //1:in  ;  0:out
         //76543210
   trisb=0b11110011;
         //76543210
   trisc=0b10111001;
         //76543210
   trisd=0b11111111;
         //76543210
   trise=0b11111000;
   //pp
   
   setup_oscillator(OSC_32MHZ|OSC_INTRC|OSC_PLL_ON);
   //
   setup_timer_0(T0_INTERNAL|T0_DIV_1|T0_8_BIT);
   set_timer0(0);
   ENABLE_INTERRUPTS(INT_TIMER0);
   //

   ENABLE_INTERRUPTS(GLOBAL);

   
   
   while(1){
      sense_1=1;delay_ms(1000);sense_1=0;delay_ms(1000);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19541

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 5:42 am     Reply with quote

You can't.
On the 4550, there is not a PLL available with the internal clock. Maximum internal clock rate is 8MHz.

Look at figure 2-1 in the data sheet. Start at the internal oscillator. Note how it feeds - 8MHz to prescaler, then to mux, then to the oscillator selection. No route to the PLL.

Seriously, you can't run USB on these chips without an external oscillator, so why use a USB enabled chip?. A pointless waste of pins.

Best Wishes
louwi_138



Joined: 17 Nov 2012
Posts: 23

View user's profile Send private message

PostPosted: Thu Dec 20, 2012 8:19 pm     Reply with quote

Ttelmah wrote:
You can't.
On the 4550, there is not a PLL available with the internal clock. Maximum internal clock rate is 8MHz.

Look at figure 2-1 in the data sheet. Start at the internal oscillator. Note how it feeds - 8MHz to prescaler, then to mux, then to the oscillator selection. No route to the PLL.

Seriously, you can't run USB on these chips without an external oscillator, so why use a USB enabled chip?. A pointless waste of pins.

Best Wishes


What should I write in my code to run the PLL at 48 Mhz from a quartz 20MHz ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19541

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 2:11 am     Reply with quote

HSPLL - use the PLL to feed the CPU
PLL5 - divide incoming clock by 5 to give the 4MHz for PLL
CPUDIV1 - divide the PLL output by two to give 48MHz
PUT - should really always be used with the crystal
USBDIV - feed USB from PLL/2
#use delay(clock=48M)

The key is understanding that the CPUDIV numbers are for when the CPU divider is used off an incoming clock not the PLL. So you have
CPUDIV1, CPUDIV2, CPUDIV3 and CPUDIV4, which give /1, /2, /3, & /4 from the normal clock, and /2, /3, /4 & /6 when used off the PLL!...

It is a pity that CCS didn't instead call the fuses:
CPUDIV00 CPUDIV01 CPUDIV10 & CPUDIV11 which would then be the binary values fed to the fuses, to avoid this potential confusion.....

Best Wishes
louwi_138



Joined: 17 Nov 2012
Posts: 23

View user's profile Send private message

PostPosted: Sat Dec 29, 2012 3:08 am     Reply with quote

Ttelmah wrote:
HSPLL - use the PLL to feed the CPU
PLL5 - divide incoming clock by 5 to give the 4MHz for PLL
CPUDIV1 - divide the PLL output by two to give 48MHz
PUT - should really always be used with the crystal
USBDIV - feed USB from PLL/2
#use delay(clock=48M)

The key is understanding that the CPUDIV numbers are for when the CPU divider is used off an incoming clock not the PLL. So you have
CPUDIV1, CPUDIV2, CPUDIV3 and CPUDIV4, which give /1, /2, /3, & /4 from the normal clock, and /2, /3, /4 & /6 when used off the PLL!...

It is a pity that CCS didn't instead call the fuses:
CPUDIV00 CPUDIV01 CPUDIV10 & CPUDIV11 which would then be the binary values fed to the fuses, to avoid this potential confusion.....

Best Wishes


thank you, but I don't wana to run USB I just need speed to run my prgram faster.

I tested this confugiration:
Code:

#include <18f4550.h>

#FUSES CPUDIV1
#FUSES PLL5
#FUSES HSPLL
#FUSES PUT
#FUSES NOMCLR
#FUSES USBDIV

#use delay(clock=48M)
 

but It run at speed : 20Mhz
Ttelmah



Joined: 11 Mar 2010
Posts: 19541

View user's profile Send private message

PostPosted: Sat Dec 29, 2012 4:02 am     Reply with quote

What CCS version (4.11, is _not_ a CCS version number - they are all 3 digits after the DP)?.
If HSPLL is selected, the chip ought to run off the PLL. It'd only run at 20MHz, if HS was selected, not HSPLL.
If you have 4.011, this is before CCS V4, started actually working, so 'anything is possible'.....

Best Wishes
louwi_138



Joined: 17 Nov 2012
Posts: 23

View user's profile Send private message

PostPosted: Sun Dec 30, 2012 2:51 am     Reply with quote

Ttelmah wrote:
What CCS version (4.11, is _not_ a CCS version number - they are all 3 digits after the DP)?.
If HSPLL is selected, the chip ought to run off the PLL. It'd only run at 20MHz, if HS was selected, not HSPLL.
If you have 4.011, this is before CCS V4, started actually working, so 'anything is possible'.....

Best Wishes


My ccs version is 4.110
Ttelmah



Joined: 11 Mar 2010
Posts: 19541

View user's profile Send private message

PostPosted: Sun Dec 30, 2012 4:21 am     Reply with quote

Have just put this:
Code:

#include <18f4550.h>

#FUSES CPUDIV1
#FUSES PLL5
#FUSES HSPLL
#FUSES PUT
#FUSES NOMCLR
#FUSES USBDIV
#FUSES NOIESO

#use delay(clock=48M)

void main(void) {
   setup_adc_ports(NO_ANALOGS);
   setup_comparator(NC_NC_NC_NC);
   do {
      output_high(PIN_A0);
      delay_ms(1);
      output_low(PIN_A0);
      delay_ms(1);
   } while (TRUE);
}

Using both 4.107, and 4.112 (the nearest I have to 4.110), and on both it correctly gives a 500Hz square wave, using a 20MHz crystal.
It's running at 48MHz.

Unless there is some specific problem with 4.110 (which I don't remember anyone posting about at the time), something else is wrong on your system.
How are you programming this?. Remember if you are using a bootloader, most won't change the fuses (they can't, since doing so will prevent them from running, since their timings are set for the fuses written when they were programmed).
If not using a bootloader, are you sure your programmer is reading the fuses from the source file (this can be switched off on most programmers)?.

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