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

PERIPHERAL MODULE DISABLE

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



Joined: 11 Jun 2013
Posts: 35
Location: Cape Town

View user's profile Send private message

PERIPHERAL MODULE DISABLE
PostPosted: Fri Jun 22, 2018 7:16 am     Reply with quote

Are there any CCS functions for using this feature? I did search the forum and found one post where registers for a specific chip were documented. Also looked the the chips .h file to check if the PMD registers were defined in any way. No luck.

Something like disable_module(FVRMD) to turn off the FVR module would be useful.

Or does one just address the PMD registers and set the bits manually Microchip / HiTech style?
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Fri Jun 22, 2018 9:28 am     Reply with quote

In most cases the individual peripheral enables, have disable defines in the .h file. So for instance the setup_adc function has as one of it's options ADC_OFF. This turns off the particular peripheral.
However to use the PMD, just generate the registers. Look in this thread:

<https://www.ccsinfo.com/forum/viewtopic.php?t=55498>

Shows how to disable all the peripherals. Obviously you can leave the ones you want enabled.

Note carefully the comment from Jeremiah on this. Problem is that PMD leaves you having to re-configure the peripheral when you re-awaken, so it doesn't seem to actually gain anything over just turning the peripheral off....

So, yes for the PMD functions, you just access these directly.
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Fri Jun 22, 2018 1:23 pm     Reply with quote

Ttelmah wrote:
Note carefully the comment from Jeremiah on this. Problem is that PMD leaves you having to re-configure the peripheral when you re-awaken, so it doesn't seem to actually gain anything over just turning the peripheral off....


Speaking from direct and recent experience, if ultra low power consumption is your goal, then using PMD to completely remove power from a peripheral is the only way to achieve it. Resetting a peripheral upon powering it back up only requires an instruction or two, so that "hit" in performance greatly outweighs completely powering down the peripheral when not needed.
blowtorch



Joined: 11 Jun 2013
Posts: 35
Location: Cape Town

View user's profile Send private message

PostPosted: Fri Jun 22, 2018 4:59 pm     Reply with quote

Thanks - I thought it would come to defining the registers and writing them directly to disable the various peripherals. So be it.

I expect at some point we will probably see some new commands appearing in CCS to exploit PMD.

TTelmah thanks for the heads up re re-configuring the peripherals. I guess it comes down to how much power is actually saved if completely disabling a peripheral as opposed to turning it off. Basically in my application I have a soft power off function, so I have to completely re-initialise everything on "power up" anyway.
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Fri Jun 22, 2018 11:15 pm     Reply with quote

Just doing a project now with 18F67K40 I added this to device header file.
Hope this helps.
Dave

Code:

#byte   PMD_0  =  getenv("SFR:PMD0")   //periperal enable/disable
#byte   PMD_1  =  getenv("SFR:PMD1")
#byte   PMD_2  =  getenv("SFR:PMD2")
#byte   PMD_3  =  getenv("SFR:PMD3")
#byte   PMD_4  =  getenv("SFR:PMD4")
#byte   PMD_5  =  getenv("SFR:PMD5")
//note to use any pin as a general digital I/O, any module that uses that PIN as an input must be disabled...as I undesrtand the datasheet
#byte   SLR_CONA  =  getenv("SFR:SLRCONA")
#byte   SLR_CONB  =  getenv("SFR:SLRCONB") //slew rate regs
#byte   SLR_CONC  =  getenv("SFR:SLRCONC")
#byte   SLR_COND  =  getenv("SFR:SLRCOND")
#byte   SLR_CONE  =  getenv("SFR:SLRCONE")
#byte   SLR_CONF  =  getenv("SFR:SLRCONF")
#byte   SLR_CONG  =  getenv("SFR:SLRCONG")
#byte   SLR_CONH  =  getenv("SFR:SLRCONH")

#byte   LAT_A  =  getenv("SFR:LATA") //  I always add these to any device header I am using unless they aint got em!!!
#byte   LAT_B  =  getenv("SFR:LATB")
#byte   LAT_C  =  getenv("SFR:LATC")
#byte   LAT_D  =  getenv("SFR:LATD")
#byte   LAT_E  =  getenv("SFR:LATE")
#byte   LAT_F  =  getenv("SFR:LATF")
#byte   LAT_G  =  getenv("SFR:LATG")
#byte   LAT_H  =  getenv("SFR:LATH")
/////////////////////////////////////////////

Edit:
I also list which PMD bit controls what as well, so I know at a quick glance what hardware on the device I am using if my brain cell is going to sleep
Very Happy


    //UNLESS PERIPHS DISABLED CANNOT USE PORT PINS AS GENERAL I/O
    // pmd'S SEE DATA SHEET FOR FULL DECSCRIPTION
    // in order from bit 7-0 module N/U=BIT NOT USED
    PMD_0=0b01111011; // SYSCMD|FVRMD|HVLD|CRCMD|NVMMD|CLKRMD|IOCMD
    PMD_1=0b11111110; // TRMR7MD|6MD|5MD|4MD|3MD|2MD|1MD|0MD
    PMD_2=0b00111111; // N/U|N/U|CWGMD|N/U|DSMMD|SMT2MD|SMT1MD|TMR8MD
    PMD_3=0b01111111; // N/U|DACMD|ADCMD|N/U|CMP3MD|CMP2MD|CMP1MD|ZCDMD
    PMD_4=0b01111111; // N/U|PWM7MD|PWM6MD|CCP5MD|CCP4MD|CCP3MD|CCP2MD|CCP1MD
    PMD_5=0b01110110; // N/U|UASRT5MD|USART4MD|USART3MD|USART2MD|MSSP2MD|MSSP1MD


Last edited by diode_blade on Mon Jun 25, 2018 1:22 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Sat Jun 23, 2018 1:26 am     Reply with quote

Yes.

The 'silly' thing is that on a lot of the modules, the 'off' function in the module already saves all the power. On the ADC for example, provided it is being clocked from it's internal clock it goes fully off. The key though is that if it is set to use the CPU clock, the circuitry that handles this remains enabled, and it is this that can result in a little power being drawn. The PMD disable, stops these clocks as well.
Now modules that don't have their own enables in the module itself, are things like the FVR, input change notification, & input capture. In these cases PMD is brilliant.
However it is worth saying that SIDL may well be better. Most of the PIC24 peripherals have an SIDL bit, which if set, makes the peripheral _automatically_ stop, when the chip goes to idle. This is a much more convenient way of having all the things you don't want running stopped for you when you sleep (might be worth investigating....).

I'd sit down and draw a list of the modules you want to keep running. Then generate bit pattern defines for each of the PMD registers to give these. Then do the same for all the patterns needed during normal operation (it is quite common to find quite a few modules never need to be turned on). Then your sleep can load all the disabled patterns before triggering, and on wake up you load the running patterns, and re-configure the peripherals. Hurrah!... Smile
blowtorch



Joined: 11 Jun 2013
Posts: 35
Location: Cape Town

View user's profile Send private message

PostPosted: Sat Jun 23, 2018 8:42 am     Reply with quote

Thanks Gents
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