View previous topic :: View next topic |
Author |
Message |
farouk_baya
Joined: 18 Jun 2010 Posts: 27
|
Sleep mode 18f25k20 |
Posted: Fri Jan 16, 2015 9:06 am |
|
|
Hello;
I want to put the 18f25k20 in sleep mode.
I use the following code.
Code: |
#include "18f25k20.h"
#device PIC18f25k20
#fuses MCLR,INTRC_IO,PUT,NOWDT,NOLVP,NOBROWNOUT,BORV18,NOPROTECT,DEBUG,NOSTVREN
#use delay(internal = 4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=BTDATA) //printf("Hello");
#use i2c(Master,SLOW=40000,sda=PIN_C4,scl=PIN_C3,FORCE_HW)
#use fast_io (C)
#byte PORTA = 0xf80
#byte PORTB = 0xf81
#byte PORTC = 0xf82
#byte TRISA = 0xf92
#byte TRISB = 0xf93
#byte TRISC = 0xf94
void initialization()
{
setup_oscillator(OSC_4MHZ);
PORTA = 0xFF;
TRISA = 0x00;
PORTB = 0xFF;
TRISB = 0x00;
PORTC = 0xFF;
TRISC = 0x00;
}
void main()
{
initialization();
//
sleep(SLEEP_FULL);
while(1);
}
|
The problem is that when 18f25k20 is put in sleep mode after executing ( sleep() ), I get:
- 3.3 V in the outputs.
- 1.96 mA in an output which drive a led.
It is not normal that the outputs are not 0 V and the current is high?
What do you think?
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 16, 2015 10:50 am |
|
|
Quote: | #include "18f25k20.h"
#device PIC18f25k20
#fuses MCLR,INTRC_IO,PUT,NOWDT,NOLVP,NOBROWNOUT,BORV18,NOPROTECT,DEBUG,NOSTVREN
#use delay(internal = 4M)
void main()
{
initialization();
//
sleep(SLEEP_FULL);
while(1);
}
|
The MPLAB help file for the ICD3 says:
Quote: |
PIC18F Extended, PIC18FXXK Limitations
- The SLEEP instruction cannot be used when debugging.
- The Watchdog Timer (WDT) cannot be used when debugging.
- You cannot view the stack even though you can access it.
- You cannot single step through an interrupt |
|
|
![](templates/subSilver/images/spacer.gif) |
farouk_baya
Joined: 18 Jun 2010 Posts: 27
|
|
Posted: Fri Jan 16, 2015 12:02 pm |
|
|
I added the DEBUG to the fuses but I have the same result.
I use PICKIT3 as programmer (not debugger) but I have always the same result.
I use also:
Code: |
#ASM ASIS
sleep
#ENDASM
|
But no result.
I have the same consumption from the microcontroller. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 16, 2015 1:56 pm |
|
|
Quote: | I added the DEBUG to the fuses but I have the same result |
They want you to remove the DEBUG fuse. Don't run the program
in debug mode. Run it in Release mode.
Also, you said:
Quote: | The problem is that when 18f25k20 is put in sleep mode after executing ( sleep() ), I get:
- 3.3 V in the outputs.
- 1.96 mA in an output which drive a led. |
Post a schematic of your LED circuit. Does it look like this:
Code: |
PIC 470 ohms LED
pin -----/\/\/\/------->|----
|
|
----- Ground
---
- |
What PIC pin is used for the LED ? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Fri Jan 16, 2015 3:20 pm |
|
|
The other thing is the old 'is he working through MPLAB' question?. It's possible he has been compiling permanently in DEBUG mode, whatever he selects if this is the case... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 16, 2015 3:43 pm |
|
|
Ttelmah means you should set the Build Configuration box to "Release"
as shown below:
This is for MPLAB vs. 8.92. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Sat Jan 17, 2015 1:33 am |
|
|
What puzzles me, is he says:
"It is not normal that the outputs are not 0 V and the current is high? "
yet he is setting all the outputs high, so 'of course' they are high.....
I think he perhaps expects the output drivers to go off when the chip sleeps.
This is not what happens. The outputs are simple static logic. They _hold_ whatever they are set to when you go to sleep. This is why you will see lots of posts here explaining that _before_ you go to sleep, _you_ (nobody else), need to ensure that every pin is set to the output level for low power. So things like LED's are turned off. Lines that control other logic, need to be set to high or low, to turn that logic off. Inputs need to have external circuitry holding them to either high or low (a floating input will draw significant power as the line transitions from low/high or high/low). This is all down to the design of the hardware and code. Only once the lines are in the correct state for least power, do you then put the chip to sleep. |
|
![](templates/subSilver/images/spacer.gif) |
farouk_baya
Joined: 18 Jun 2010 Posts: 27
|
|
Posted: Tue Jan 20, 2015 8:15 am |
|
|
Thanks a lot ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|