CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sleep mode 18f25k20

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
farouk_baya



Joined: 18 Jun 2010
Posts: 27

View user's profile Send private message

Sleep mode 18f25k20
PostPosted: Fri Jan 16, 2015 9:06 am     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 16, 2015 10:50 am     Reply with quote

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
farouk_baya



Joined: 18 Jun 2010
Posts: 27

View user's profile Send private message

PostPosted: Fri Jan 16, 2015 12:02 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 16, 2015 1:56 pm     Reply with quote

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 ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Fri Jan 16, 2015 3:20 pm     Reply with quote

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...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 16, 2015 3:43 pm     Reply with quote

Ttelmah means you should set the Build Configuration box to "Release"
as shown below:

This is for MPLAB vs. 8.92.
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Sat Jan 17, 2015 1:33 am     Reply with quote

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.
farouk_baya



Joined: 18 Jun 2010
Posts: 27

View user's profile Send private message

PostPosted: Tue Jan 20, 2015 8:15 am     Reply with quote

Thanks a lot Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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