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

USB problem connecting to PC with 18F87J50

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



Joined: 21 Feb 2008
Posts: 24

View user's profile Send private message

USB problem connecting to PC with 18F87J50
PostPosted: Tue Sep 30, 2008 2:20 pm     Reply with quote

I'm using Microchips demo board PIC18F85J50 PIM as a stand along module. All I want to do is print debug information out the USB port. However, I can not get the demo board to be recognized by my PC. I get the same message every time... "USB Device Not Recognized - One of the USB devices attached to this computer has malfunctioned, and Windows does not recognize it. For assistance in solving this problem, click this message."

Since I'm using the demo board, it can't be hardware... can it?

I'm following ex_usb_serial2.c. But here is my code...
Code:

#include <18F87J50.h>
 
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES H4_SW                    //High speed osc with SW enabled 4x PLL
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES MSSPMSK7              //#FUSES RESERVED                 //Used to set the reserved FUSE bits
#FUSES NOCPUDIV             
#FUSES PLL3                     //PLL PreScaler
 
#use delay(clock=12000000)

#use rs232(baud=9600,parity=N,xmit=PIN_C6, rcv=PIN_C7, bits=8,restart_wdt,STREAM=DEBUG232,errors)

#define USB_CON_SENSE_PIN PIN_B5
#define LED1  PIN_E1
#define LED2 PIN_E0
#define LED3 PIN_E2
#DEFINE BUTTON PIN_B4
#define LED_ON output_low
#define LED_OFF output_high

// Includes all USB code and interrupts, as well as the CDC API
#include <usb_cdc.h>


void main() {
   int i=0;
   
      delay_ms(3000);
   fprintf(DEBUG232, "\f\r\nWe are On\r\n");
   if(input(USB_CON_SENSE_PIN)) fprintf(DEBUG232, "And USB is Connected\r\n");

   usb_cdc_init();
      usb_init();
   
   //while(!usb_cdc_connected()) {}

   while(TRUE){
      usb_task();
      if (usb_enumerated()) {
         printf(usb_cdc_putc, "\r\n\nUSB device connected\r\n");              // Display contents of the first 64
      delay_ms(1000);
      }
      else{
      fprintf(DEBUG232, "usb device not installed\r\n");
   }

      if(i++%2==0){ LED_ON(LED1); LED_OFF(LED2); }
      else{ LED_OFF(LED1); LED_ON(LED2); }
      delay_ms(500);
     
   }
}


I'm using compiler version PCH V4.066. The demo board has a 12Mhz crystal.
ntgcp_08



Joined: 21 Feb 2008
Posts: 24

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 2:47 pm     Reply with quote

Well, as soon as I posted, I found the issue...

I needed the following line:
setup_oscillator(OSC_PLL_ON);

and I needed to change my clock speed to 48Mhz.


After searching through the forum, I found a few times where people said if using a clock greater than 8Mhz you need to have an external oscillator, rather than a crystal. However, the demo board I have has a 12Mhz crystal and it works. Why is it recommended to not use a crystal above 8Mhz? When I make my own PCB, shoule I put a 6 or 8Mhz crystal rather than the 12Mhz? Will it be more reliable?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 3:01 pm     Reply with quote

Quote:

I found a few times where people said if using a clock greater than
8Mhz you need to have an external oscillator, rather than a crystal.

Post links for these claims.
ntgcp_08



Joined: 21 Feb 2008
Posts: 24

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 3:04 pm     Reply with quote

The 3rd post...

http://www.ccsinfo.com/forum/viewtopic.php?t=35417&highlight=usb+connect
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 3:18 pm     Reply with quote

Download the 18F87J50 data sheet and look at page 39 (page 41 in
the Acrobat reader). Look at Table 2-5.
http://ww1.microchip.com/downloads/en/DeviceDoc/39775b.pdf

The first column is the crystal or external oscillator frequency. The 2nd
column is the multiplier. The 3rd column is the required fuse setting.

What Ttelmah was talking about was that for multipliers of 10 and 12,
you must use the "ECPLL" fuse. "EC" means external clock, which
means an external oscillator (not a crystal).

All the rest of the multiplier settings can use a crystal. You can tell this
because they allow a fuse of "HSPLL". That's a crystal fuse setting.
The crystals can be up to 24 MHz in frequency. A crystal of 12 MHz is
shown in the table and therefore it's OK to use.
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