• AVR Freaks

XLP Sleep mode in PIC18LF46K22?

Author
gbiradar
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2015/09/14 22:21:20
  • Location: Bangalore,Karnataka
  • Status: offline
2016/04/12 23:36:29 (permalink)
0

XLP Sleep mode in PIC18LF46K22?

Hi Guys,
 
          My project require to have power saving options, so for that i intend to use XLP Sleep Management. To do so how can i do it.
 
So for my understanding says
 
In OSCCON register if we set '0' to IDLEN bit. whenever i execute SLEEP instruction it will go to sleep mode. correct me if wrong. Now how do i verify internally what are the necessary circuits/peripherals are running. and how do i make sure it should wakeup after some time or maybe by an kind of interrupt.
 
I'm going through power managed modes. But still external input will be helpful.
 
regards,
gbiradar 
#1
MatthewM
Super Member
  • Total Posts : 204
  • Reward points : 0
  • Joined: 2014/08/08 03:49:49
  • Location: UK
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 00:49:06 (permalink)
+1 (1)
gbiradar
Hi Guys,
 
          My project require to have power saving options, so for that i intend to use XLP Sleep Management. To do so how can i do it.
 
So for my understanding says
 
In OSCCON register if we set '0' to IDLEN bit. whenever i execute SLEEP instruction it will go to sleep mode. correct me if wrong. Now how do i verify internally what are the necessary circuits/peripherals are running. and how do i make sure it should wakeup after some time or maybe by an kind of interrupt.
 
I'm going through power managed modes. But still external input will be helpful.
 
regards,
gbiradar 




IDLEN dictates whether the device enters Sleep (IDLEN=0) or Idle (IDLEN=1) when the SLEEP instruction is called. By default I think IDLE=0, but I can't see any harm/negatives in setting bits to be sure.
 
When you enter sleep you have to have an external source kick it awake. Internal oscillators don't (IIRC) operate in sleep mode, so timers that can generate an interrupt to wake the device, require an external clock source. You can use external timers or supervisors (something like a TPL5010) that can generate an IOC event on a pin to wake the device.
 
Setting the appropriate bits high in the PERIPHERAL MODULE DISABLE register will disable modules (such as ADC, TMRs, PSPs..etc). This will (should) yield better power saving than setting enable bits or putting the device in Idle. When you enter Sleep mode, I think these modules unless set up otherwise are disabled. Power loss is proportional to clock frequency, if the clock is gated, like it is in Sleep mode, these devices take very little power.
 
 
 
 
 
#2
gbiradar
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2015/09/14 22:21:20
  • Location: Bangalore,Karnataka
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 01:35:58 (permalink)
0
Hi MatthewM,
                 
                  Thanks For your reply, In my project i'm using INTOSC @16Mhz with 4 x PLL. Now as you said timer interrupt is not possible with INTOSC.
So i have two more interrupt, one EXT interrupt connected at RB0 and one IOC interrupt at RB4. can any of this interrupt is capable of wakeup the pic18f from sleep once i pass SLEEP instruction if so any changes required in ISR.
 
And were can  i gate clock and how?
 
regards,
Ganesh 
              
#3
MatthewM
Super Member
  • Total Posts : 204
  • Reward points : 0
  • Joined: 2014/08/08 03:49:49
  • Location: UK
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 01:52:19 (permalink)
+1 (1)
gbiradar
So i have two more interrupt, one EXT interrupt connected at RB0 and one IOC interrupt at RB4. can any of this interrupt is capable of wakeup the pic18f from sleep once i pass SLEEP instruction if so any changes required in ISR.

Yeah they should be able to cause the device to wake. You just have to set your interrupts properly. Nothing needs to be populated in your ISR function if you don't want to.
 
When you enter sleep, the next instruction (program counter + 1) is pre-fetched. When you wake, you execute the instruction after SLEEP, and then branch out into the interrupt address (0004h I believe)[1]. If you don't want the instruction to be executed straight after SLEEP, place an NOP after SLEEP. (I do this anyway).
 

 
 
 
SLEEP();
 
 
 
Nop();
 
 
 

 
gbiradar
And were can  i gate clock and how?

The sleep function does this, I was just stating that just for information.
 
Set the PERIPHERAL MODULE DISABLE (PMD) if to stop modules.
 
<edit> typos..
[1] 1and0 pointed out it's PIC family dependent. 
post edited by MatthewM - 2016/04/13 02:12:02
#4
1and0
Access is Denied
  • Total Posts : 9011
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 02:07:02 (permalink)
+2 (2)
If GIE is set to '1' before going to sleep, upon wakeup it will branch to interrupt vector after executing the instruction immediately following SLEEP.  If GIE is cleared to '0' before going to sleep, it will wakeup and continue on its merry way and not branch to ISR.
 
<edit> For PIC18 the high-priority interrupt vector is at 0x08 and the low-priority interrupt vector is at 0x18.
post edited by 1and0 - 2016/04/13 02:08:23
#5
MatthewM
Super Member
  • Total Posts : 204
  • Reward points : 0
  • Joined: 2014/08/08 03:49:49
  • Location: UK
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 02:10:44 (permalink)
0 (1)
1and0
If GIE is set to '1' before going to sleep, upon wakeup it will branch to interrupt vector after executing the instruction immediately following SLEEP.  If GIE is cleared to '0' before going to sleep, it will wakeup and continue on its merry way and not branch to ISR.
 
<edit> For PIC18 the high-priority interrupt vector is at 0x08 and the low-priority interrupt vector is at 0x18.


1and0 is right. Totally forgot about GIE bits (:
post edited by MatthewM - 2016/04/13 02:12:36
#6
gbiradar
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2015/09/14 22:21:20
  • Location: Bangalore,Karnataka
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 02:15:51 (permalink)
0
Hi 1and0,
 
            Thanks for the information, which means before i call SLEEP function i will disable GIE and after wakeup i can set GIE for the project. Does only GIE i have to worry because interrupt configuration i'm also enabling GIEL with GIEH. So do i have disable GIEL as well GIE/GIEH.
 
regards,
Ganesh 
#7
Mysil
Super Member
  • Total Posts : 3321
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 02:17:35 (permalink)
+2 (2)
Hi,
There are some internal peripherals that may make the PIC wake up from sleep mode:
The watchdog timer: when the device is in sleep mode, WDT will make the PIC  wake up, while a WDT interrupt while the PIC is awake will initiate a Reset.
 
The ADC, if the ADC is enabled,  working with it's own RC oscillator, and performing a conversion,
it may wake the CPU when the ADC conversion is completed. This may be used to get ADC measurements with less noise from digital sources.
 
If you have a watch crystal, 32.768 kHz, connected to the Secondary Oscillator pins,
the this oscillator may be kept working with Timer 1 ( or Timer 3) to keep time,
also when the rest of the chip is sleeping.
Before going to sleep, it is possible to switch the CPU to use the secondary crystal oscillator, that have to keep working, as the clock source, such that this is used while waking up for timekeeping updates.
See datasheet table 27.2 parameter D011 and D06, the white fields are for LF devices, gray fields for devices without L.
 
The PIC may also be made to wake up by pushing buttons from Interrupt On Change events,
or from other external interrupts.
 
If the device is a I2C slave, and is enabled, it may wake up when called with it's address.
 
Regards,
   Mysil
#8
Mysil
Super Member
  • Total Posts : 3321
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 02:28:28 (permalink)
0 (1)
Hi,
There is maybe a misunderstanding:
GIE and GIEH is the same bit in hardware.
PIE and GIEL is also the same bit in hardware.
These bits are just explained in different ways depending on the Interrupt mode selected.
When GIEH alias GIE is 0, all interrupts are disabled, also the low priority ones.
 
   Mysil
 
#9
1and0
Access is Denied
  • Total Posts : 9011
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/13 02:41:07 (permalink)
+2 (2)
gbiradar
... which means before i call SLEEP function i will disable GIE and after wakeup i can set GIE for the project. Does only GIE i have to worry because interrupt configuration i'm also enabling GIEL with GIEH. So do i have disable GIEL as well GIE/GIEH.
 

Setting or clearing GIE before SLEEP will depend on how you want your device to work after wakeup. GIE/GIEH controls the high-priority interrupts and PEIE/GIEL controls the low-priority interrupts; however, you cannot have low-priority interrupts without also enabling GIEH.
#10
gbiradar
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2015/09/14 22:21:20
  • Location: Bangalore,Karnataka
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/21 01:03:49 (permalink)
0
Hi 1and0,
 
Setting or clearing GIE before SLEEP will depend on how you want your device to work after wakeup. GIE/GIEH controls the high-priority interrupts and PEIE/GIEL controls the low-priority interrupts; however, you cannot have low-priority interrupts without also enabling GIEH.

 
             Well sorry for replying late, still i haven't able to solve this problem. well i have cleared GIE and then called SLEEP() after that i tried to use my hall sensor as ext interrupt but it is not waking up board. Can you tell me what it's mean "how you want your device to work after wakeup". I want my board to work as it was working before going to sleep how can i achieve this.
 
regards,
gbiradar
#11
1and0
Access is Denied
  • Total Posts : 9011
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/21 06:52:58 (permalink)
+1 (1)
gbiradar
... still i haven't able to solve this problem. well i have cleared GIE and then called SLEEP() after that i tried to use my hall sensor as ext interrupt but it is not waking up board.

Did you enable the INTx external interrupt? Did you select the correct external interrupt edge?

Can you tell me what it's mean "how you want your device to work after wakeup".

I meant how do you want your device to respond to the event that awaken the PIC device. Do you want to handle this event in the ISR or not upon waking up?

I want my board to work as it was working before going to sleep how can i achieve this.

You have not told us how your board and firmware work. Anyway, there is nothing complicated, just set it up like any other interrupts before the SLEEP instruction.
#12
gbiradar
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2015/09/14 22:21:20
  • Location: Bangalore,Karnataka
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/21 19:22:19 (permalink)
0
Hi 1and0,
 
               Well before calling SLEEP i checked EXT interrupt its working fine no issue with that. I have never performed SLEEP operation so i have no idea after wakeup where it will be.
 
I have some external peripherals whose register are initialize before i call infinite while loop.
 
In while loop i have to read certain parameter based on certain conditions then board should go to sleep in say after 30 sec for that i'm using timer(checked working fine). now once it goes sleep to after certain period EXT interrupt has to wakeup board. Once it wake up it has to be in while loop again perform the same job read EXT peripheral register and after 30sec it has to SLEEP again.
 
Maybe problem is:
 
I have set IDLEN = 0, SCS<1:0> = 0; in OSCCON Registers.
IN TABLE 3-1: Power Managed modes
CPU will be OFF
peripherals will be OFF & All clocks are disabled.
 
#13
gbiradar
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2015/09/14 22:21:20
  • Location: Bangalore,Karnataka
  • Status: offline
Re: XLP Sleep mode in PIC18LF46K22? 2016/04/21 20:46:57 (permalink)
+2 (2)
Sorry 1and0,
  
It's working i just called normally SLEEP which used EXT interrupt to wakeup it worked. My mistake,  i have written polling method as well as ISR method code but i didn't enable ISR method instead polling method was running. So when SLEEP was called it didn't work as i expected. After checking thoroughly i came across the real problem. Now no issues. Thanks once again.
 
#14
Jump to:
© 2019 APG vNext Commercial Version 4.5