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

PIC18F4550 running without USB any questions

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



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

PIC18F4550 running without USB any questions
PostPosted: Sun Jun 19, 2011 11:48 am     Reply with quote

Hello,

I have connected a 4x3 Keypad and a SIM Module on the PIC18F4550. So sometimes I use the USB connection to communicate with a pc, and sometimes the pic is running as stand alone.

Until now, I don't have use the USB Sense PIN (like in the ex_usb_serial.c) sample. Should I use this?

Is there anything to consider when I use the PIC in both modes?
I use the ex_usb_serial. c sample as base.

Best regards
Volker
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 2:09 am     Reply with quote

Yes.
It'll be far better in terms of processor usage, and things not going wrong, to just test the input sense pin (usb_task does this if the pin is available). The code also disables the USB interrupt if the bus goes 'unattached', and turns off the hardware (saving power as well).
Without this, the USB code has to assume the bus is there all the time, and the only way to find that it may not be, is usb_enumerated, which is a relatively complex route, and more likely to cause problems.

Best Wishes
Prefekt



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 10:56 am     Reply with quote

Hi,

so I have connected and activate the USB sense. But without USB connection the pic is not working Sad

What happend, when I send printf(usb_cdc_putc, ...) when USB is not connected?

Thanks
Volker
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 2:48 pm     Reply with quote

You don't.
You need to write your code, either adding a test in the putc, or in your own code, so that your prints are dumped, or fed to whatever you want, when the USB is not active.
So (just dumping):
Code:

void my_usb_putc(int8 chr) {
   if (usb_attached()) {
      usb_cdc_putc(chr);
   }
}


printf(my_usb_putd,"waht you want to send");

//Or

if (usb_attached()) {
    printf(usb_cdc_putc,.....);
}


Normally you would make the I/O functions independant of whatever else the code is doing, with a single test for attached/enumerated, and all the USB functionality only enabled, when the bus is attached.

Best Wishes
Prefekt



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 3:16 pm     Reply with quote

@Ttelmah...

ok, thanks ... i thought such things already.
So should it work.

But now, I have a crazy problem.

The pic works with usb connection with no problem. So I have put on the 'Test oscillator and debugger' Button on the ccsload software. Since my pic is very very slowly. I had this problem at start with usb debugging, but I don't know how I solve It Embarassed

Here is my config file:
Code:
#include <18F4550.h>
#device adc=8
/////////////////////////////////////////////////////////////////////////////
// Fuses
/////////////////////////////////////////////////////////////////////////////
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#FUSES NOWDT                     //No Watch Dog Timer
#FUSES WDT128                    //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL                     //High Speed Crystal/Resonator with PLL enabled
#FUSES NOPROTECT                 //Code not protected from reading
#FUSES NOBROWNOUT                //No brownout reset
#FUSES BORV20                    //Brownout reset at 2.0V
#FUSES PUT                       //Power Up Timer
#FUSES NOCPD                     //No EE protection
#FUSES STVREN                    //Stack full/underflow will cause reset
#FUSES NODEBUG                   //No Debug mode for ICD
#FUSES NOLVP                     //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                     //Program memory not write protected
#FUSES NOWRTD                    //Data EEPROM not write protected
#FUSES IESO                      //Internal External Switch Over mode enabled
#FUSES FCMEN                     //Fail-safe clock monitor enabled
#FUSES NOPBADEN                  //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                    //configuration not registers write protected
#FUSES NOWRTB                    //Boot block not write protected
#FUSES NOEBTR                    //Memory not protected from table reads
#FUSES NOEBTRB                   //Boot block not protected from table reads
#FUSES NOCPB                     //No Boot Block code protection
#FUSES MCLR                      //Master Clear pin enabled
#FUSES LPT1OSC                   //Timer1 configured for low-power operation
#FUSES NOXINST                   //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL5                      //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1                   //System Clock by 1
#FUSES USBDIV                    //USB clock source comes from PLL divide by 2
#FUSES VREGEN                    //USB voltage regulator enabled
#FUSES ICPRT                     //ICPRT enabled

/////////////////////////////////////////////////////////////////////////////
// Clock / RS232
/////////////////////////////////////////////////////////////////////////////
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

/////////////////////////////////////////////////////////////////////////////
// Configure the I/O
/////////////////////////////////////////////////////////////////////////////
//LED connection:
#define LED2       PIN_A4
#define LED3       PIN_A5
#define LED1       PIN_B4
//Servo connection:
#define SRV_POWER  PIN_C0
#define SRV_SIGNAL PIN_C1
//Keypad connection:
#define col0       PIN_D6
#define col1       PIN_D5
#define col2       PIN_D4
#define row0       PIN_D3
#define row1       PIN_D2
#define row2       PIN_D1
#define row3       PIN_D0
//LighBeam connection:
#define LS1        PIN_A1
#define LS2        PIN_A2
//USBSense
#define USBSENSE   PIN_B0
//SIM900B Power
#define SIM900BPWR PIN_C2

#define LED_ON output_high
#define LED_OFF output_low

//Gobal varaibles
int __DEBUG=0;             // debug mode 0=off, 1=on
char cSMSSerProv[21];
char cMEBPhoneNumber[21];


I have connected a 20MHz crystal with 2x27pf caps. This works for long time. And now is the pic slow, very slow. I have restart pc and so on.

Best regards
Volker
Prefekt



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

PostPosted: Wed Jun 22, 2011 2:05 pm     Reply with quote

Hello,

I found the problem... It was the crystal. The crystal go crazy sometime. Now, with a new crystal, It works perfect.

Thanks at all

Volker
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 1:57 am     Reply with quote

Possibly the crystal is being slightly overdriven.
Have seen this quite a few times on chips like the x550. If the crystal gain is too high, a series resistor needs to be added between the crystal and the PIC pin, or it can lock on to harmonics or undertones. If 'borderline' the behaviour can be erratic, and then makes working out what is actually wrong quite difficult, with the PIC changing frequency intermittently.
Glad you have found the problem.

Best Wishes
Prefekt



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 9:10 am     Reply with quote

Hi,
Do you have an idea, where to buy good crystals or alternatives? Resonators has 5% tolerance Confused

Best regards
Volker
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 3:08 pm     Reply with quote

There are plenty of resonators that will reach the accuracy needed for USB, 0.05%, but generally only for a fairly small temperature range. Crystal's are far more likely to be reliable. This is a common reason for some standard devices like hubs tending to fail when they are moved into outbuildings....

Microchip's application note on oscillators, recommends some crystals. A web search may well find a supplier near you. Then there are any number of suppliers doing crystals that can meet/exceed the required specification. In Europe, RS, Farnell, Arrow, Euroquartz (even have them custom made if required). In the US, Mouser, Digikey, etc.. Key thing though is to make sure you are looking for the right type of crystal. Parallel cut. If AT strip cut, a series resistor should be included on the board. A device like the TXC B-20.000MEEJ-B, would be typical, or for SMD, I use a lot of the Hosonic E3SB20.0000F16E11 parts. Price should be well under $1 (ought to be under $0.50 if your suppliers are any good, and drop to under $0.25 in reasonable quanitities), so little is to be gained from using a resonator.

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