|
|
View previous topic :: View next topic |
Author |
Message |
Afroman
Joined: 03 Aug 2012 Posts: 2
|
PIC18F4550 dual oscillator options |
Posted: Fri Aug 03, 2012 4:16 pm |
|
|
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! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19497
|
|
Posted: Sat Aug 04, 2012 3:43 am |
|
|
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: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Aug 04, 2012 5:07 am |
|
|
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
|
|
Posted: Sat Aug 04, 2012 6:50 am |
|
|
@Temtronic: Link!
Id like to give that a read! _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Aug 04, 2012 2:22 pm |
|
|
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
|
|
Posted: Mon Aug 06, 2012 6:44 pm |
|
|
Excellent! All the info about those fuses was especially helpful thank you! |
|
|
spilz
Joined: 30 Jan 2012 Posts: 219
|
|
Posted: Tue Aug 07, 2012 5:47 am |
|
|
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: 219
|
|
Posted: Tue Aug 07, 2012 8:55 am |
|
|
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
|
|
Posted: Tue Aug 07, 2012 9:49 am |
|
|
Thaks Temtronic! _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|
|
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
|