|
|
View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 218
|
18F2550 change clock with bootloader |
Posted: Thu Jun 26, 2014 2:04 pm |
|
|
Hi everyone !
I have a problem and don't find a solution :
pic18F2550, quartz 4MHz
I use the usb bootloader to load the software, and it works well.
BUT ... ^^
To reduce power consumption, I would like to disable PLL when I don't use bootloader.
-> when I use bootloader XTPLL and clock 48MHz
-> when I use in normal mode XT and clock 4MHz
How can I change clock setting by software ?
If it's not understandable, I will try to explain more
thanks for your help
Spilz |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9219 Location: Greensville,Ontario
|
|
Posted: Thu Jun 26, 2014 2:54 pm |
|
|
So I'm thinking this is a battery powered device and NOT connected to a USB port 24/7?
Have you measured the power consumption under both conditions ?
What is the desired life 'on batteries'?
Without knowing what else the PIC does you may have to change several register settings..the datasheet will show what's needed.
Others will know how to change the clock setup though it might be a lot easier to toss a bigger battery in the circuit!
hth
jay |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Thu Jun 26, 2014 3:12 pm |
|
|
Hi temtronic
thanks for your interest
Yes you're right, it's a battery powered device, I use USB only to load new software.
right now with this battery the device "live" 5 days, and I want to increase it as much as I can
It will be too long to explain all the pic has to do, it's data recorder.
But here I just want to try a basic function like an "hello word" printf with the good clock setting.
I write code which run at 4MHz, with quartz at 4MHz, loaded without bootloader -> OK
I write code which run at 48MHz, with quartz at 4MHz and PLL, loaded without bootloader -> OK
I write code which run at 48MHz, with quartz at 4MHz and PLL, loaded with USB bootloader -> OK
How to load code which run at 4MHz, with quartz at 4MHz and NOPLL, loaded with USB bootloader ?
Because temperature change, I can't use internal oscillator (issue with baudrate on serial port), I have to use external quartz |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9219 Location: Greensville,Ontario
|
|
Posted: Thu Jun 26, 2014 4:49 pm |
|
|
Probably NOT possible as USB needs speed and there isn't a 'legal' 4MHz input to USB without the PLL.
Some years ago I used the 4550 and gave up on using the internal USB.While power/speed wasn't the issue, the USB drivers took up a LOT of codespace!
I used an external $3 USB<>TTL module. NO codespace needed for USB drivers,idiotproof connections(module has connector on it),also comes with couple of LEDs and was a simple 'plug and go' setup.
Overall the module added about $1.50 to the product per unit but saved hundreds if not thousands of $$$ in R&D time as well as real time to market.
You may want to consider this method, at least it's food for thought.
Jay |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Fri Jun 27, 2014 1:45 am |
|
|
I understand this solution, but I don't have enough space to add other component.
And I would like to find a way to do that.
I found a solution by switching to internal oscillator, but the internal oscillator is not reliable when temperature changes :(
The question can be reformulated like this :
How can we load by usb bootloader and run a software which don't use the same clock setting as the bootloader ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Fri Jun 27, 2014 8:29 am |
|
|
You don't need to have the PLL enabled, to use it for the USB!.....
The way the chip is done, the PLL is _always_ enabled. If the HS, or XT fuse is selected, the PLL is still running, but only feeds the USB circuitry, not the CPU. The 'PLL' in the fuses only controls whether the CPU clock comes from the PLL route or directly.
If you look in the data sheet at the table of 'oscillator configuration options for USB operation', you will see a line starting '4MHz', which shows XT, which CPUDIV1, giving 4MHz CPU operation, but still listed as valid for USB.
So:
CPUDIV1, XT
Will still run the USB circuitry at 48Mhz, but the CPU will run at 4Mhz.
The only problem is that sometimes (depending on how carefully your USB code is written), a 4MHz CPU clock can give problems with not being fast enough.
Try it. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Sun Jun 29, 2014 12:19 am |
|
|
Hi ,
I didn't know that, thanks for explanation
I will try it, let see if 4MHz is enough for USB
I found a solution with write_configuration_memory()
It seems to work
Do you have an idea if there is a problem to do like this ?
Thanks for your help
Spilz |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Sun Jun 29, 2014 12:44 am |
|
|
Big problems with this.
If the clock is left programmed in the wrong mode, you have a permanently 'non working' device, until it is reprogrammed with a programmer.
You might try running the USB code from the internal RC oscillator at 8MHz.
Sounds insane, but provided the hardware fuse is set to XT, the USB will still be being clocked correctly, and there is nothing to stop you running the CPU off the internal RC. Then your speed goes up to 8MHz, which is enough for the USB code to run correctly (normally it needs somewhere around 4 to 6MHz). The speed error with the actual code doesn't matter for this, unlike for your 'run time' code.
I've run low power USB code this way on several devices, until I switched to better chips (like the 26J50), which draw less power, and give you better control over the oscillator. |
|
|
|
|
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
|