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

PIC18F4550 dual oscillator options

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



Joined: 03 Aug 2012
Posts: 2

View user's profile Send private message

PIC18F4550 dual oscillator options
PostPosted: Fri Aug 03, 2012 4:16 pm     Reply with quote

Hi everyone,

I am trying to create a project which will sometimes be powered by a battery, and sometimes be powered by USB. This is my first proper USB project and I could use some help.

When in battery mode, I need power consumption to be an absolute minimum - just a few uA. I was hoping to run the PIC18F4550 at 2.0V and use the 125kHz internal oscillator.

Then when the user plugs in the USB cable, the USB's 5V line goes to a 3.3V LDO, which connects to the PIC's VUSB pin. (I can't rely on the battery to power VUSB because it could be anywhere from 3.0V to 4.2V). When the USB cable is plugged in, I would like to be able to send some simple low speed USB data across the bus. I know that you can't do USB at 125kHz so an external crystal oscillator of some kind will be needed.

Is it even possible to have the two different parts of the PIC running at different clock speed and voltages like this?

There are so many different oscillator configuration options I don't know how to begin. What speed crystal should I use? And what oscillator settings? And how do I switch between the two settings when I plug/unplug the USB cable?

Thanks in advance for any advice you have to offer! Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19448

View user's profile Send private message

PostPosted: Sat Aug 04, 2012 3:43 am     Reply with quote

Step 'back' a bit.
The PIC itself, contains a LDO regulator to generate Vusb. Use it.
When the USB power is available, power the circuit from this. You _need_ (not optional), a crystal oscillator at a multiple of 4Mhz, to run the USB (OK, you can use in some cases ceramic resonators, and can run low speed USB with 6MHz), but basically you must have something meeting the USB clock accuracy specs.
Look at the data sheet. Figure 17-12. This shows how to handle the power switching.
Then, add an external crystal oscillator module at (say) 4MHz, powered from the USB power line.

Then the key thing is the transitions between 'USB powered', and 'self powered'. This is detected using the I/O pin, and then involved a series of hardware things having to change:
1) The oscillator. For the 4MHz module, fuses ECPLL, PLL1, USBDIV, FSEN and perhaps CPUDIV4, clock=8MHz as the default settings.
Then setup_oscillator(INT_RC | OSC_125KHZ); for low speed operation and
setup_oscillator(OSC_NORMAL); to run off the fuse programmed settings.

2) The USB transceivers. The USB 'suspend' mode, is normally used to switch a USB device down to low power, when it's host computer sends a 'sleep' signal. However you can use this bit, to turn the regulator, and transceivers into 'low power' mode. (SUSPND - UCON bit 1). Setting this, and UTRDIS, turns off the transceivers, and the pull up sources, putting the whole USB circuitry in a 'ready to go, but switched off as far as possible' mode.

You need to have the FSCM fuse enabled (so the chip will 'fall back' to the internal oscillator if an external one is not available).

Using ECPLL, means the chip won't try to run it's own crystal oscillator, but will be dependant of receiving a clock input, which the external module will generate when USB power is available. This then feeds the PLL, and generates the 96MHz used by the USB, and at the same time gives an 8MHz clock for the CPU (generally you need a CPU speed of perhaps 6Mhz minimum, to actually handle USB).

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9204
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 04, 2012 5:07 am     Reply with quote

You should also 'do the math' and see what your real world energy requirements are. Run your PIC hardware and monitor/record the current demands over say a day or two. Based on that data it might be easier to just use a couple 'D' cells instead of a 'coin cell' battery. Today's batteries have a great amount of energy inside them! Microchip wrote an application on this (sw based RTC/data logger->RS232) and should be read. While it's nice to reduce millamps to microamps there comes a point where it's not advantangeous to the overall project.

Also by running tests, you can see what really works in your project. Reducing clock speed might sound good, but if it takes longer to acquire and store the data, the net gain might be negative. Only testing will tell and each project has it's 'quirks'.
hth
jay
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Aug 04, 2012 6:50 am     Reply with quote

@Temtronic: Link!
Id like to give that a read!
_________________
CCS PCM 5.078 & CCS PCH 5.093
temtronic



Joined: 01 Jul 2010
Posts: 9204
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 04, 2012 2:22 pm     Reply with quote

Ok...took awhile but...

It's AN606 Low Power Design Using PIC16/17 found in 1995/1996 ECHB
Update I supplement.

hth
jay
Afroman



Joined: 03 Aug 2012
Posts: 2

View user's profile Send private message

PostPosted: Mon Aug 06, 2012 6:44 pm     Reply with quote

Excellent! All the info about those fuses was especially helpful thank you!
spilz



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 5:47 am     Reply with quote

hey !

I'm interested too

can someone post code sample to have an idea how to do that?

thanks
spilz



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 8:55 am     Reply with quote

it's a 18F2550
I had
Code:
int data[6] = {0x24,0x0E,0x3E,0x1E,0x00,0x03};
write_configuration_memory(data,6);

at the beginning of the bootloader,
like this whatever is changed by the program after, when the pic restart, the fuses are still right for bootloader.
But I didn't find the good way to change the configuration in the program load.
How the compiler know when the clock change, for delay for example ?
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 9:49 am     Reply with quote

Thaks Temtronic!
_________________
CCS PCM 5.078 & CCS PCH 5.093
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