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 and Idle Modes on an 18F4685

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







Sleep and Idle Modes on an 18F4685
PostPosted: Fri Dec 11, 2009 11:36 am     Reply with quote

PIC- 18F4685
Compiler- 4.085

I am trouble with the PIC low power modes.

When I put the PIC in SLEEP mode, it draws microamps.

However, when I put the PIC into IDLE mode, it draws ~ 5 mA, which is about the same as it draws in RUN mode. There appears to be no power saving in IDLE mode. I have all the tristates set to input, so it should not be driving any pins. I also used printfs to check the SFRs and confirm that all the peripherals were off. But it looks like some peripheral is on and consuming power...

I used printfs to confirm that the PIC goes into IDLE mode and never wakes up, since all interrupts are disabled.

Here's a test program:

Code:
#include <18F4685.h>
#device PASS_STRINGS = IN_RAM
#include <stdio.h>
#include <string.h>

#use delay(INTERNAL=8M, clock=16M)
#fuses INTRC, NOWDT, NOLVP, NOPBADEN, NOBROWNOUT, NOPROTECT//, DEBUG

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//SFRs///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#byte OSCCON   =      0xFD3   
#bit  IDLEN    =       OSCCON.7

#byte CCP1CON   =      0xFBD
#byte ECCP1CON   =      0xFBA
#byte SSPCON1   =      0xFC6
#byte RCSTA      =      0xFAB
#byte ADCON0   =      0xFC2
#byte CMCON      =      0xFB4
#byte CVRCON   =      0xFB5
#byte HLVDCON   =      0xFD2
#byte CANSTAT   =      0xF6E

//Debug         
//#use rs232(BAUD=9600, XMIT=PIN_B3, BITS=8, PARITY=N)

//Main////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup_clk() {
   setup_oscillator(OSC_16MHZ);
   delay_ms(10);
}

void setup_io() {
   //set tris         
   set_tris_a(0xFF);      
   set_tris_b(0xFF);         
   set_tris_c(0xFF);
   set_tris_d(0xFF);
   set_tris_e(0xFF);
}

void go_to_sleep() {
   IDLEN=1;               
   sleep();
}

void main(void) {
   //setup pic
   setup_clk();
   disable_interrupts(GLOBAL);
   setup_io();
   
   CMCON=0;
   CANSTAT=0x20;
   
/*   printf("Current Peripheral SFR Status\r\n");
   printf("CCP1CON      =      %X\r\n",CCP1CON);
   printf("ECCP1CON   =      %X\r\n",ECCP1CON);
   printf("SSPCON1      =      %X\r\n",SSPCON1);
   printf("RCSTA      =      %X\r\n",RCSTA);
   printf("ADCON0      =      %X\r\n",ADCON0);
   printf("CMCON      =      %X\r\n",CMCON);
   printf("CVRCON      =      %X\r\n",CVRCON);
   printf("HLVDCON      =      %X\r\n",HLVDCON);
   printf("CANSTAT      =      %X\r\n",CANSTAT);*/

   while(1) {
   //   printf("I'm asleep!\r\n");
      go_to_sleep();
   //   printf("I'm awake!\r\n");
   }
}

Thanks for your help.
JohnHopkins
Guest







Shutting Down CAN
PostPosted: Fri Dec 11, 2009 12:05 pm     Reply with quote

I just realized that I was trying to disable CAN in CANSTAT, when I should have used CANCON. I made the change, but that didn't solve the problem. However, when I read CANSTAT, it tells me that it is in configuration mode, not disable mode. So it looks like CAN is still on...
Code:

#include <18F4685.h>
#device PASS_STRINGS = IN_RAM
#include <stdio.h>
#include <string.h>

#use delay(INTERNAL=8M, clock=16M)
#fuses INTRC, NOWDT, NOLVP, NOPBADEN, NOBROWNOUT, NOPROTECT//, DEBUG

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//SFRs///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#byte OSCCON   =      0xFD3   
#bit  IDLEN    =       OSCCON.7

#byte CCP1CON   =      0xFBD
#byte ECCP1CON   =      0xFBA
#byte SSPCON1   =      0xFC6
#byte RCSTA      =      0xFAB
#byte ADCON0   =      0xFC2
#byte CMCON      =      0xFB4
#byte CVRCON   =      0xFB5
#byte HLVDCON   =      0xFD2
#byte CANSTAT   =      0xF6E
#byte CANCON   =      0xF6F

//Debug         
//#use rs232(BAUD=9600, XMIT=PIN_B3, BITS=8, PARITY=N)

//Main////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup_clk() {
   setup_oscillator(OSC_16MHZ);
   delay_ms(10);
}

void setup_io() {
   //set tris         
   set_tris_a(0xFF);      
   set_tris_b(0xFF);         
   set_tris_c(0xFF);
   set_tris_d(0xFF);
   set_tris_e(0xFF);
}

void go_to_sleep() {
   IDLEN=1;               
   sleep();
}

void main(void) {
   //setup pic
   setup_clk();
   disable_interrupts(GLOBAL);
   setup_io();
   
   CMCON=0;
   CANCON=0x20;

/*   printf("Current Peripheral SFR Status\r\n");
   printf("CCP1CON      =      %X\r\n",CCP1CON);
   printf("ECCP1CON   =      %X\r\n",ECCP1CON);
   printf("SSPCON1      =      %X\r\n",SSPCON1);
   printf("RCSTA      =      %X\r\n",RCSTA);
   printf("ADCON0      =      %X\r\n",ADCON0);
   printf("CMCON      =      %X\r\n",CMCON);
   printf("CVRCON      =      %X\r\n",CVRCON);
   printf("HLVDCON      =      %X\r\n",HLVDCON);
   printf("CANSTAT      =      %X\r\n",CANSTAT);*/

   while(1) {
   //   printf("I'm asleep!\r\n");
      go_to_sleep();
   //   printf("I'm awake!\r\n");
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 11, 2009 1:53 pm     Reply with quote

Your program is too complicated. Also, according to the Electrical
Characteristics section of the 18F4685 data sheet, the speed of the
internal oscillator makes a huge difference in the current consumption
during idle mode. So why not try it with the lowest speed ?
Try the incredibly stripped down program shown below. I don't have
your PIC so I can't test this, but I think it would be a good test.
Code:

#include <18F4685.h>
#use delay(INTERNAL=8M, clock=16M)
#fuses INTRC, NOWDT, NOLVP, NOPBADEN, NOBROWNOUT, NOPUT

//======================================
void main(void)
{
setup_oscillator(OSC_IDLE_MODE | OSC_INTRC | OSC_31KHZ);
sleep();

while(1);
}
 
JohnHopkins
Guest







That did the trick
PostPosted: Fri Dec 11, 2009 5:59 pm     Reply with quote

Thanks for your input. Reducing the clock speed reduced the power consumption by ~90%, so we are good.

Just as a point of interest, we still can't put the CANCON register into Disable mode. The CANSTAT register always indicates that the CAN is in Configuration mode. However, this does not draw a noticeable amount of power at lower frequencies.
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