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

18F65j50 USB

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



Joined: 09 Oct 2009
Posts: 13
Location: SF,BG

View user's profile Send private message

18F65j50 USB
PostPosted: Fri Aug 05, 2011 12:49 pm     Reply with quote

Hi guys,
I am trying to make PC <> PIC communication with 18F65j50, but I can't set right frequency - 48MHz. The crystal wich is connected between RA6 and RA7 is 4MHZ. This is my code:
Code:

#include "18F65J50.h"

#FUSES NOWDT                   
#FUSES WDT128                 
#FUSES H4_SW             
#FUSES NODEBUG         
#FUSES NOXINST           
#FUSES STVREN             
#FUSES NOPROTECT       
#FUSES FCMEN               
#FUSES IESO         
#FUSES MSSPMSK7           
#FUSES RESERVED 
#FUSES NOCPUDIV             
#FUSES PLL5           
#FUSES PMPDE                 
#use delay(clock=48000000)
//#include <pic18_usb.h>
//#include "usb_cdc.h"

void main ()
{
  //usb_cdc_init();
  //usb_init();
  for(;;)
  {
    output_high(PIN_B0);    //To see roughly what is frequency
    delay_ms(1000);
    output_low(PIN_B0);
    delay_ms(1000);
  }
}

Led connected on PIN B0 flash too slowly. I think that frequency is still 4MHZ.
Thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 05, 2011 2:03 pm     Reply with quote

Post your compiler version, because there are differences in the fuses
between older versions and the current compiler version.
peterl



Joined: 09 Oct 2009
Posts: 13
Location: SF,BG

View user's profile Send private message

RE:
PostPosted: Fri Aug 05, 2011 2:21 pm     Reply with quote

My compiler version is 4.084. I reduced code to this:
Code:

#include "18F65J50.h"

#FUSES H4_SW                   
#FUSES NOCPUDIV             
#FUSES PLL1                             
#use delay(clock=4M)

void main ()
{
  for(;;)
  {
    output_high(PIN_B0);
    delay_ms(1000);
    output_low(PIN_B0);
    delay_ms(1000);
  }
}

The Led connected on PIN B0 is still flashing with exactly 1 second. Crystal is 4MHZ and capacitors is 20pf.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 05, 2011 2:42 pm     Reply with quote

Try this oscillator setup:
Code:

#include <18F65J50.h>
#fuses H4_SW, NOWDT
#use delay(clock=48M)

//============================
void main()
{

while(1);
}
peterl



Joined: 09 Oct 2009
Posts: 13
Location: SF,BG

View user's profile Send private message

RE:
PostPosted: Fri Aug 05, 2011 11:58 pm     Reply with quote

Now interval is ~12 sec, PLL still not working.

C code:
Code:

#include "18F65J50.h"
#FUSES H4_SW 
#FUSES NOWDT                                               
#use delay(clock=48M)

void main ()
{
  for(;;)
  {
    output_high(PIN_B0);
    delay_ms(1000);
    output_low(PIN_B0);
    delay_ms(1000);
  }
}


ASM code:
Code:

CCS PCH C Compiler, Version 4.084           06-Aug-11 08:52

               Filename: UPS-IARA.lst

               ROM used: 114 bytes (0%)
                         Largest free fragment is 32646
               RAM used: 6 (0%) at main() level
                         7 (0%) worst case
               Stack:    1 locations

*
0000:  GOTO   002C
.................... #include "18F65J50.h"
.................... //////// Standard Header file for the PIC18F65J50 device ////////////////
.................... #device PIC18F65J50
.................... #list
.................... 
.................... 
.................... #FUSES H4_SW   
.................... #FUSES NOWDT                                               
.................... #use delay(clock=48M)
0004:  CLRF   FEA
0006:  MOVLW  07
0008:  MOVWF  FE9
000A:  MOVF   FEF,W
000C:  BZ    002A
000E:  MOVLW  0F
0010:  MOVWF  01
0012:  CLRF   00
0014:  DECFSZ 00,F
0016:  BRA    0014
0018:  DECFSZ 01,F
001A:  BRA    0012
001C:  MOVLW  8F
001E:  MOVWF  00
0020:  DECFSZ 00,F
0022:  BRA    0020
0024:  NOP   
0026:  DECFSZ FEF,F
0028:  BRA    000E
002A:  RETLW  00
.................... void main ()
.................... {
002C:  CLRF   FF8
002E:  BCF    FD0.7
0030:  CLRF   FEA
0032:  CLRF   FE9
0034:  BSF    FC0.4
0036:  MOVLW  FF
0038:  MOVWF  FC1
003A:  BCF    FC0.4
003C:  BCF    FC2.6
003E:  BCF    FC2.7
0040:  BSF    FC0.4
0042:  MOVWF  FC2
0044:  BCF    FC0.4
0046:  CLRF   FD2
0048:  CLRF   FD1
....................   for(;;)
....................   {
....................     output_high(PIN_B0);
004A:  BCF    F93.0
004C:  BSF    F8A.0
....................     delay_ms(1000);
004E:  MOVLW  04
0050:  MOVWF  06
0052:  MOVLW  FA
0054:  MOVWF  07
0056:  RCALL  0004
0058:  DECFSZ 06,F
005A:  BRA    0052
....................     output_low(PIN_B0);
005C:  BCF    F93.0
005E:  BCF    F8A.0
....................     delay_ms(1000);
0060:  MOVLW  04
0062:  MOVWF  06
0064:  MOVLW  FA
0066:  MOVWF  07
0068:  RCALL  0004
006A:  DECFSZ 06,F
006C:  BRA    0064
....................   }
006E:  BRA    004A
.................... }
0070:  SLEEP

Configuration Fuses:
   Word  1: F7AE   NODEBUG NOXINST STVREN NOWDT NOPROTECT RESERVED NOCPUDIV PLL1
   Word  2: FFC5   H4_SW WDT32768 FCMEN IESO RESERVED
   Word  3: FD00   CCP2C1 MSSPMSK7 RESERVED PMPDE
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 06, 2011 1:54 am     Reply with quote

I'm staying up late so I might as well do this. One more thing needs to
be done. We need to set the PLLEN bit in the OSCTUNE register.
That's the "_SW" (software) part of it. See the 3 new lines in the
program below:
Code:

#include <18F65J50.h>
#fuses H4_SW, NOWDT
#use delay(clock=48M)

#byte OSCTUNE = getenv("SFR:OSCTUNE")
#bit  PLLEN = OSCTUNE.6

//============================
void main()
{
PLLEN = 1;


while(1);
}
peterl



Joined: 09 Oct 2009
Posts: 13
Location: SF,BG

View user's profile Send private message

RE:
PostPosted: Sat Aug 06, 2011 4:19 am     Reply with quote

Now it work Smile Thank you very much!
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