View previous topic :: View next topic |
Author |
Message |
rightbak
Joined: 16 Sep 2011 Posts: 10
|
Application uses bootloader #fuses settings |
Posted: Fri Sep 16, 2011 4:37 am |
|
|
Hi
I'm using a PIC18F46J50, CCS V4.119 with a 12MHz crystal.
I am using a slightly modified version of the CCS USB bootloader to program the PIC with my application code. The bootloader has the following #fuses/#use statements set:
Code: |
#include <18F46J50.h>
#fuses HSPLL,NOWDT,NOPROTECT,PLL3,CPUDIV2,NOT1DIG,NOIESO
#use delay(clock=6000000)
|
The application code that is loaded into the PIC using the bootloader has different fuse settings as follows:
Code: |
#include "18F46J50.h"
#fuses HS,WDT,NOPROTECT,NOIESO,NOT1DIG
#use delay(clock=12000000, RESTART_WDT)
|
I am finding that the application code ignores its fuse settings and uses the bootloader fuse settings instead thereby making the application code run at the wrong speed.
Any ideas what I can do to force it to use the application fuse settings? Or is there something else I am doing wrong?
Many thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Sep 16, 2011 7:26 am |
|
|
Most bootloaders, _don't_ program the fuses.
Think about it for a moment. The bootloader _must_ know how fast the chip is running, so if the fuses were changed by the bootloader, it would then stop working, making it pointless.
You need to reprogram your bootloader to use the same fuses as your final code, and write this into the chip with a programmer....
Best Wishes |
|
|
rightbak
Joined: 16 Sep 2011 Posts: 10
|
|
Posted: Mon Sep 19, 2011 6:32 am |
|
|
Many thanks for your reply |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Tue Aug 07, 2012 4:00 am |
|
|
hey!
I have the same problem, I want to use bootloader, but in normal mode, I need to have a low consumption to save battery, so I want to use internal clock with no pll.
Is it possible to have a bootloader which forces the fuses for it at the start of the program, and an other part at the beginning of the "normal application" which force the fuse for it ?
I'm not sure to be clear, sorry for my bad english.
Spliz |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Tue Aug 07, 2012 6:51 am |
|
|
No.
The fuses in application, and bootloader _must_ normally be be the same.
However remember that on most modern chips, you can change the clock rate independant of the fuses. So (for instance), many chips allow selection of a clock from the timer oscillator, or the internal RC, or the fuse programmed default.
So you don't change the fuses, just use the setup_oscillator command to change the selected oscillator.
Best Wishes |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Tue Aug 07, 2012 8:55 am |
|
|
it's a 18F2550
I know how to use setup_oscillator() to change internal clock speed, but I don't know how to switch from quartz to internal clock.
and what about write_configuration_memory() ?
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 ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Tue Aug 07, 2012 11:28 am |
|
|
If you do this, you risk killing your chip.
The flash memory has limited write life.
Look at the settings for 'setup_oscillator'. However have to ask what you are using the 2550 for?. If you want USB, then you _must_ (not optional), have a quartz oscillator running at 4,6,8,12,16,20, or 24MHz.
setup_oscillator(OSC_4MHZ | OSC_INTRC);
switches to the internal 4MHz oscillator.
Best Wishes |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Thu Aug 09, 2012 2:05 pm |
|
|
hey
thanks Ttelmah, it's exactly what i was looking for, I didn't know
" | OSC_INTRC "
is there something to go back to HS or HSPLL ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Thu Aug 09, 2012 2:10 pm |
|
|
setup_oscillator(OSC_NORMAL);
Puts you back to the fuse selected oscillator.
Best Wishes |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Thu Aug 09, 2012 2:12 pm |
|
|
thanks a lot |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Aug 10, 2012 1:23 am |
|
|
Read the datasheet!
Oscillator section. There's a lot of cool stuff in there... _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Fri Aug 10, 2012 1:49 am |
|
|
I did, I understand it, but I don't know where I can find the syntax for the compiler. Often I know what I want to do, but I don't know how to do it with the ccs compiler |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Aug 10, 2012 2:03 am |
|
|
spilz wrote: | I did, I understand it, but I don't know where I can find the syntax for the compiler. Often I know what I want to do, but I don't know how to do it with the ccs compiler |
You can always look in the corresponding .H file for the PIC you're using...
It's in the CCS installdir.
For example, 18F46j11.h will be the starting place for using that PIC.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Fri Aug 10, 2012 2:10 am |
|
|
I will
thanks |
|
|
|