View previous topic :: View next topic |
Author |
Message |
Vamsi Guest
|
Problems with Bootloader and sleep |
Posted: Wed Jan 02, 2008 11:08 am |
|
|
Hi,
I have a peculiar problem using Pic18F4520. My application uses sleep mode and wakes up every 2 secs. Just after it wakes up it makes the pin D5 high and do some stuff make it low and go to sleep mode again. WHen i download this code directly using the ICD everything works fine.
But when i use it with the bootlaoder provided by CCS, whenever the controller wakes up from sleep mode, there is a reset.
Is the bootloader, sleep mode and the pin D5 related some how? Is D5 a special pin or being used by the bootlaoder?
Any kind of suggestion would be greatly appreciated.
Vamsi |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jan 02, 2008 11:53 am |
|
|
What is your compiler version?
Is your application using interrupts? |
|
|
Vamsi Guest
|
|
Posted: Wed Jan 02, 2008 3:42 pm |
|
|
I am using CCS compiler and i am using interrupts. I use timer1 to interrupt every 2 secs and the application code comes out of sleep. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jan 02, 2008 4:08 pm |
|
|
Maybe it is a known problem, that's why we want to know the version number of you compiler, not just if it is a CCS compiler (you being here at this forum I already assumed that). The version number can be found at several places, I always look at the top of the list file (*.lst). The number looks something like 3.249, 4.037 or 4.064
Most likely the interrupt is causing your problems. The CCS bootloader is located low in memory, overlapping the addresses for the hardware interrupt vector at 0x0008 and 0x0018. The CCS bootloader provides a jump from these addresses to a new location in your main program. What most likely has failed is that you didn't tell your main program the interrupt addresses have changed using the #build declaration. To fix this you only have to add the following line to the start of your main program: Code: | #include <bootloader.h> |
|
|
|
Vamsi Guest
|
|
Posted: Wed Jan 02, 2008 4:40 pm |
|
|
The version i am using is 4.032
I have already added that line and the interrupts are rightly changed to the new locations.
When i comment a particular line in the application i.e. output_high(pin_d5) everything works fine otrher wise there is a reset.
The code is like this
.
.
.
sleep();//it comes out of sleep only for every 2secs due to timer1 interrupt
output_high(pin_d5);//if i comment this everything is fine....i dont assume
// it is hardware problem becauze it works fine when i flash the code directly using ICD
a=b+c;//some code
sleep(); |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jan 03, 2008 10:51 am |
|
|
A strange problem... The PIC processor is very basic and there are not many things that can cause it to reset. Are you sure the processor is resetting?
If yes, try adding a call to restart_cause() to figure out what causes the reset.
What is connected to your pin D5? Is it possible that activating this pin causes a voltage spike? Is the PIC still resetting when you disconnect whatever is connected to this pin?
Try adding a NOP instruction, a delay_cycles(1), directly after the sleep call. The PIC processor has a primitive kind of instructions pipeline causing the next instruction to be already partially loaded on entering the sleep mode. Adding a NOP avoids some rare problems, especially when the next instruction is a conditional instruction.
Which silicon revision of the PIC18F4520 are you using? Check the errata data sheets, for example the B2 stepping has some problems when the Brown Out Reset is used in combination with Power-Up Timer.
Compiler version 4.032 is one of the first v4.0xx versions that became usable. I wouldn't use it for serious product development. It is worth upgrading to the latest release, in the 30+ releases since your version many bugs have been solved.
One thing that might be different from your stand alone version and the one with the bootloader are the #fuses settings. The bootloader will not reprogram the fuses, so whatever settings you used when programming the bootloader, that's what your application is running with. Especially take note when comparing the Power-Up Timer and Brown Out Reset settings. |
|
|
|