| View previous topic :: View next topic |
| Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Mon Jun 22, 2015 5:36 am |
|
|
I tested your code and it works.
but this one doesn't :
| Code: | void main()
{
setup_oscillator(OSC_PLL_ON);
flash(); //48 seconds
setup_oscillator(OSC_PLL_OFF);
flash(); //48 seconds
while(TRUE)
{
delay_cycles(1);
}
} |
and this one doesn't too :
| Code: | void main()
{
flash(); //5 seconds
setup_oscillator(OSC_PLL_OFF);
flash(); //48 seconds
setup_oscillator(OSC_PLL_ON);
flash(); //48 seconds
while(TRUE)
{
delay_cycles(1);
}
} |
it seems there is an issue with : | Code: | | setup_oscillator(OSC_PLL_ON); |
one other question, with PLL_OFF by software, does it really stop PLL running ?
I mean, as goal is to save power, I don't want this part still run even if it's not use. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20061
|
|
Posted: Mon Jun 22, 2015 8:50 am |
|
|
PLLEN, does disable the PLL when low. The clock diagram does not show this.
You should really never need to turn it on. It is on when you boot, so you just have to decide you are 'not' doing the bootload, and then switch to low power, otherwise leave it on.
However the problem is a chip erratum.
Look at item 2 in the errata sheet.
This enables it:
| Code: |
#BIT PLLEN=getenv("BIT:PLLEN")
#byte OSCCON=getenv("SFR:OSCCON")
//to switch to the primary oscillator with PLL
setup_oscillator(OSC_4MHz); //internal oscillator
PLLEN=TRUE; //enable PLL
OSCCON&=0xFC; //just switch oscillator type without changing PLL
|
|
|
 |
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Tue Jun 23, 2015 5:28 am |
|
|
it works !
thanks for your help
I'm going to work on my bootloader now
I see you use lot of "getenv", where do you find the names you use inside ? I don't see them in .h |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20061
|
|
Posted: Tue Jun 23, 2015 7:07 am |
|
|
They are basically the register and bit names from the data sheet.
However if you have the IDE, select 'Tools', 'Device editor', then top right tab 'Registers', it opens a window with all the register and bit names for the current device.
In this particular case, the way that CCS changes the register (double byte wide writes to the two control registers), with the PLL selection for the primary oscillator, is exactly the scenario that causes the problem described in the erratum sheet. So you have to switch to the internal oscillator, then select the PLL enable without changing anything else in the register, and then change just the oscillator type.... |
|
 |
|