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

Cant put PIC16F1784 to sleep

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



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

Cant put PIC16F1784 to sleep
PostPosted: Wed Nov 04, 2015 9:51 am     Reply with quote

Hello Group:

I've been beating my head against a problem where I cant get a PIC16F1784 to stay in sleep mode. I've been very successful in the past with other Microchip controller to sleep, but for some reason not this project.

I've paired down the code to its basic functionality shown below. Here I increment a counter in Timer0 interrupt until reaching 5000 (3 seconds or so) and attempt sleep. Microcontroller never enters sleep as evident by current draw of 5 mA. I expect less than 100uA.

CAN ANYONE SPOT SOMETHING i'M NOT SEEING?

Thanks for the groups help.



Code:


//==================sleeptest.c

#include <16F1784.h>
#include <sleeptest.h>
#INCLUDE <math.h>


//Prototypes

void Go_To_Sleep (void);


#INT_TIMER0
void clock_isr(void)

{
int8   Num_Beeps;

set_timer0(60);                     //preload TMR0

if (Sleep_Tmr++ >= 5000)
   Go_To_Sleep();

}



void Go_To_Sleep (void)
{

restart_wdt();
clear_interrupt(INT_EXT);

setup_wdt(WDT_ON|WDT_32S);      //set watchdog timer to reset in ~3 secs.
disable_interrupts(GLOBAL);     // disable all interruptsleep();                  //sleep for one seccond
set_timer0(60);
sleep();

delay_cycles(1);
setup_wdt(WDT_OFF);

Sleep_Tmr= 0;



}



void main()
{
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
set_timer0(60);                        //preset timer0
enable_interrupts(INT_TIMER0);                // Enable timer0 interrupt
enable_interrupts(GLOBAL);                  // Enable all interrupts

while (True)
   {

   }
}



//==================sleeptest.h


#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOPUT               //Power up timer off for debugging


#use delay(int=8000000)


//#use spi(MASTER, DI=Data_In, CLK=SClk, BAUD=100000, BITS=18, MODE=1, stream=AD)


//VARIABLES

int32      Sleep_Tmr;



PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 11:56 am     Reply with quote

Try doing a more simple test. Disconnect all other circuits from the PIC
except for the MCLR pullup resistor and the following LED circuit:
Code:

PIC      470 ohms      LED       
pin -----/\/\/\/------->|----
B0                          |
                            |
                          -----  Ground 
                           ---
                            -

Also, disconnect your programmer from the board (Pickit 3, ICD3, etc).
If it's connected during current measurement, it will draw a few ma and
ruin your low sleep current test.
Code:

#include <16F1784.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=8M)

#define LED_PIN  PIN_B0

//================================
void main()
{
// Set all unused i/o pins as low-level outputs
// to avoid spurious current from floating inputs.
output_a(0);
output_b(0);
output_c(0);
output_d(0);
output_e(0);

// Turn LED on for 1 second to show PIC is running.
output_high(LED_PIN);
delay_ms(1000);
output_low(LED_PIN);   

sleep();   // Then sleep.  LED should stay off.

// If the PIC is not sleeping, then the LED will  blink rapidly.
while(TRUE)   
  {
   output_toggle(LED_PIN);
   delay_ms(250);
  }
}
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 12:06 pm     Reply with quote

Will do stand-by

Jerry
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 2:09 pm     Reply with quote

PCM:

Thanks for the exercise. It always pays to reduce to minimum code and hardware when troubleshooting a problem. I had NOWDT and Timer0 interrupts were interrupting my sleep.

Sleep current down to 17uA. Would like lower, but that should satisfy my requirements.

Thanks again
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Nov 04, 2015 2:11 pm     Reply with quote

//VARIABLES
// add some INIT
int32 Sleep_Tmr=0;

seems like a useful play
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 2:50 pm     Reply with quote

asmboy: Yes, good catch. Before dumbing down the code, I had Sleep_Tmr initialized in main.

All the best!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 3:03 pm     Reply with quote

Quote:
Sleep current down to 17uA. Would like lower, but that should
satisfy my requirements.

Are you using the "F" device (and not the "LF") ?
If so, you have the option of putting the LDO regulator into low power
mode during sleep.

Read section 9.2 in the 16F1784 data sheet for more details on this.
The low power mode is disabled if certain peripherals are active in
sleep mode, such as BOR, WDT, and interrupts. This is given in section 9.2.2.

Also, the implication is that VREGPM is automatically reset back to 0
when the PIC leaves sleep mode.

Also, the wake-up time from sleep is increased by several usec when
the LDO low-power-in-sleep mode is used. Graphs are given for this
in the data sheet's electrical section. Data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/40001637C.pdf
Code:

#bit VREGPM = getenv("BIT:VREGPM")

//================================
void main()
{
.
.
.
.
VREGPM = 1;  // Enable low power mode for the LDO during sleep

sleep();   

.
.
.
}
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Wed Nov 04, 2015 6:14 pm     Reply with quote

Yes! I am using the "F" not LF and I will give that a try as well. Thanks for your suggestion, I've tried that before with a PIC16F688.

All the best my friend.
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