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

PIC18F24J11 + DEEP SLEEP?

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



Joined: 20 Aug 2015
Posts: 17

View user's profile Send private message

PIC18F24J11 + DEEP SLEEP?
PostPosted: Mon Sep 19, 2016 2:29 am     Reply with quote

Hello,

I think I have a concept problem with the DEEP SLEEP feature...

This is my source code:
Code:

#include <main.h>

#INT_EXT

void EXT_isr(void) { 
    clear_interrupt(INT_EXT);   
}


void main() {

   setup_timer_2(T2_DIV_BY_4,243,1);      //488 us overflow, 488 us interrupt

   setup_ccp1(CCP_PWM|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
   set_pwm1_duty((int16)486);
   
   delay_ms(1000);
   
   ext_int_edge(0, H_TO_L);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   while(TRUE){
   
   sleep(DEEP_SLEEP);
   delay_cycles(1);
      //TODO: User Code
   }

}



#include <18F24J11.h>
#device ADC=10

#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NODSBOR                  //BOR disabled in Deep Sleep
#FUSES NODSWDT                  //Deep Sleep Watchdog Timer disabled

#use delay(internal=8000000)

#pin_select P1A=PIN_B2 //BUZZER + PWM



I'm just testing that the interruption on INT0 is causing the reboot of the MCU, but it seems is not even going to sleep...Maybe a wrong configuration of INT0?
Code:


*
0000:  GOTO   00DE
*
0008:  MOVWF  04
000A:  MOVFF  FD8,05
000E:  MOVFF  FE0,06
0012:  MOVLB  0
0014:  MOVFF  FE9,0C
0018:  MOVFF  FEA,07
001C:  MOVFF  FE1,08
0020:  MOVFF  FE2,09
0024:  MOVFF  FD9,0A
0028:  MOVFF  FDA,0B
002C:  MOVFF  FF3,12
0030:  MOVFF  FF4,13
0034:  MOVFF  FFA,14
0038:  MOVFF  FF5,15
003C:  MOVFF  FF6,16
0040:  MOVFF  FF7,17
0044:  MOVFF  00,0E
0048:  MOVFF  01,0F
004C:  MOVFF  02,10
0050:  MOVFF  03,11
0054:  BTFSS  FF2.4
0056:  GOTO   0060
005A:  BTFSC  FF2.1
005C:  GOTO   00AE
0060:  MOVFF  0E,00
0064:  MOVFF  0F,01
0068:  MOVFF  10,02
006C:  MOVFF  11,03
0070:  MOVFF  0C,FE9
0074:  MOVFF  07,FEA
0078:  BSF    07.7
007A:  MOVFF  08,FE1
007E:  MOVFF  09,FE2
0082:  MOVFF  0A,FD9
0086:  MOVFF  0B,FDA
008A:  MOVFF  12,FF3
008E:  MOVFF  13,FF4
0092:  MOVFF  14,FFA
0096:  MOVFF  15,FF5
009A:  MOVFF  16,FF6
009E:  MOVFF  17,FF7
00A2:  MOVF   04,W
00A4:  MOVFF  06,FE0
00A8:  MOVFF  05,FD8
00AC:  RETFIE 0
.................... #include <main.h>
.................... #include <18F24J11.h>
.................... //////////// Standard Header file for the PIC18F24J11 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... ////        (C) Copyright 1996, 2014 Custom Computer Services          ////
.................... //// This source code may only be used by licensed users of the CCS C  ////
.................... //// compiler.  This source code may only be distributed to other      ////
.................... //// licensed users of the CCS C compiler.  No other use, reproduction ////
.................... //// or distribution is permitted without written permission.          ////
.................... //// Derivative programs created using this software in object code    ////
.................... //// form are not restricted in any way.                               ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC18F24J11
.................... 
.................... #list
.................... 
.................... #device ADC=10
.................... 
.................... #FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
.................... #FUSES NOFCMEN                  //Fail-safe clock monitor disabled
.................... #FUSES NODSBOR                  //BOR disabled in Deep Sleep
.................... #FUSES NODSWDT                  //Deep Sleep Watchdog Timer disabled
.................... 
.................... #use delay(internal=8000000)
*
00B6:  CLRF   FEA
00B8:  MOVLW  1A
00BA:  MOVWF  FE9
00BC:  MOVF   FEF,W
00BE:  BZ    00DA
00C0:  MOVLW  02
00C2:  MOVWF  01
00C4:  CLRF   00
00C6:  DECFSZ 00,F
00C8:  BRA    00C6
00CA:  DECFSZ 01,F
00CC:  BRA    00C4
00CE:  MOVLW  97
00D0:  MOVWF  00
00D2:  DECFSZ 00,F
00D4:  BRA    00D2
00D6:  DECFSZ FEF,F
00D8:  BRA    00C0
00DA:  GOTO   014E (RETURN)
.................... 
.................... #pin_select P1A=PIN_B2 //BUZZER + PWM
.................... 
.................... 
.................... 
.................... #INT_EXT
.................... 
.................... void EXT_isr(void) {   
....................     clear_interrupt(INT_EXT);   
*
00AE:  BCF    FF2.1
00B0:  BCF    FF2.1
00B2:  GOTO   0060
.................... }
.................... 
.................... 
.................... void main() {
*
00DE:  CLRF   FF8
00E0:  BCF    FD0.7
00E2:  BSF    07.7
00E4:  MOVLB  E
00E6:  MOVLW  55
00E8:  MOVWF  FA7
00EA:  MOVLW  AA
00EC:  MOVWF  FA7
00EE:  BCF    xFF.0
00F0:  MOVLW  0E
00F2:  MOVWF  xCB
00F4:  MOVLW  55
00F6:  MOVWF  FA7
00F8:  MOVLW  AA
00FA:  MOVWF  FA7
00FC:  BSF    xFF.0
00FE:  CLRF   F9B
0100:  MOVLW  70
0102:  MOVWF  FD3
0104:  MOVF   FD3,W
0106:  MOVLW  FF
0108:  MOVLB  F
010A:  MOVWF  x48
010C:  BCF    FC2.6
010E:  BCF    FC2.7
0110:  MOVF   x49,W
0112:  ANDLW  E0
0114:  IORLW  1F
0116:  MOVWF  x49
0118:  MOVLW  07
011A:  MOVWF  FB4
.................... 
....................    setup_timer_2(T2_DIV_BY_4,243,1);      //488 us overflow, 488 us interrupt
011C:  MOVLW  00
011E:  IORLW  05
0120:  MOVWF  FCA
0122:  MOVLW  F3
0124:  MOVWF  FCB
.................... 
....................    setup_ccp1(CCP_PWM|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
0126:  BCF    F93.2
0128:  BCF    F8A.2
012A:  MOVLW  0C
012C:  MOVWF  FBA
012E:  CLRF   FBD
0130:  CLRF   FBE
0132:  MOVLW  01
0134:  MOVWF  FBF
....................    set_pwm1_duty((int16)486);
0136:  MOVLW  79
0138:  MOVWF  FBB
013A:  MOVF   FBA,W
013C:  ANDLW  CF
013E:  IORLW  20
0140:  MOVWF  FBA
....................     
....................    delay_ms(1000);
0142:  MOVLW  04
0144:  MOVWF  19
0146:  MOVLW  FA
0148:  MOVWF  1A
014A:  MOVLB  0
014C:  BRA    00B6
014E:  DECFSZ 19,F
0150:  BRA    0154
0152:  BRA    0158
0154:  MOVLB  F
0156:  BRA    0146
....................     
....................    ext_int_edge(0, H_TO_L);
0158:  BCF    FF1.6
....................    enable_interrupts(INT_EXT);
015A:  BSF    FF2.4
....................    enable_interrupts(GLOBAL);
015C:  MOVLW  C0
015E:  IORWF  FF2,F
.................... 
....................    while(TRUE){
....................     
....................    sleep(DEEP_SLEEP);
0160:  MOVLB  F
0162:  BSF    x4D.0
0164:  BCF    x4D.1
0166:  BSF    FC0.7
0168:  BCF    FD3.7
016A:  BCF    FF2.7
016C:  BSF    x4D.7
016E:  SLEEP
....................    delay_cycles(1);
0170:  NOP   
0172:  BRA    0162
....................       //TODO: User Code
....................    }
.................... 
.................... }
0174:  SLEEP

Configuration Fuses:
   Word  1: F4A0   NOWDT STVREN NOXINST NODEBUG NOPROTECT
   Word  2: FF98   INTRC_IO T1DIG NOLPT1OSC NOFCMEN IESO WDT32768
   Word  3: F9F3   DSWDTOSC_INT RTCOSC_T1 NODSBOR NODSWDT DSWDT2147483648 IOL1WAY MSSPMSK7
   Word  4: F1CF   WPFP WPEND NOWPCFG WPDIS

Any idea???

Thanks in advance
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon Sep 19, 2016 7:43 am     Reply with quote

Code:

//Comments inline
#include <main.h>

void main(void)
{
   setup_timer_2(T2_DIV_BY_4,243,1); //488 us overflow, 488 us interrupt

   setup_ccp1(CCP_PWM|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
   set_pwm1_duty((int16)486);

   delay_ms(1000);

   ext_int_edge(0, H_TO_L);
   enable_interrupts(INT_EXT);
   disable_interrupts(GLOBAL);
//An interrupt handler is only called
//when the following things occur:
//Interrupt is triggered
//Interrupt is enabled
//GLOBAL is enabled
//If we enable the interrupt _[u]and do not enable GLOBAL[/u]_
//Then the handler is not needed.

   while(TRUE)
   {
      clear_interrupts(INT_EXT);
      //Changing he interrupt edge can trigger the interrupt
      //Also it can be set at wake up. Hence _must_ be cleared before
      //calling sleep.
      sleep(DEEP_SLEEP);
      delay_cycles(1);
      //You will get here (not reboot), when the interrupt triggers and wakes
      //Ideally do something here to show you are awake
     
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 19, 2016 2:15 pm     Reply with quote

Quote:
the interruption on INT0 is causing the reboot of the MCU

That is the correct operation. Read the 18F24J11 data sheet:
Quote:
4.6.3 DEEP SLEEP WAKE-UP SOURCES

While in Deep Sleep mode, the device can be awakened
by a MCLR, POR, RTCC, INT0 I/O pin interrupt,
DSWDT or ULPWU event. After waking, the device performs
a POR.
When the device is released from Reset,
code execution will begin at the device’s Reset vector.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Sep 20, 2016 10:20 am     Reply with quote

The obvious question is why you want to use deep-sleep?. The power consumption of the CPU in a normal full sleep mode, is tiny. The point about 'deep sleep' is effectively the CPU is taken to the state it is in when the chip hasn't yet started, with all memory cleared, clocks stopped, most peripherals stopped etc.. Almost switched 'off', but with a few things left available to trigger a wake. The power difference is tiny....
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