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 support@ccsinfo.com

Are peripherals disabled by default?

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



Joined: 27 Jul 2013
Posts: 79

View user's profile Send private message

Are peripherals disabled by default?
PostPosted: Fri Oct 02, 2015 5:26 am     Reply with quote

Are all the peripherals turned off when you create a new project in CCS?
Or do I have explicitly turn off modules such as ADC, comparators, UART and PWM to cut down on power consumption?

Any pointer to save precious battery power?

Compiler: v5.0xx
uController: PIC18LF45K22
temtronic



Joined: 01 Jul 2010
Posts: 9198
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 5:44 am     Reply with quote

No.. not all peripherals are turned off.IE: the ADC and comparators are defaulted on. Now that _might_ change depending on the PIC you're using.
It is ALWAYS best for YOU to setup the PIC and never rely on the 'defaults'.
I'd prefer if the PIC defaults were all digital I/O, all inputs as 40 years ago there weren't ANY peripherals inside the epoxy bug of 40 pins !

As for 'defaults', be sure to use #ZERO RAM directive unless you specifically assign values to your variables since during power up the RAM will contain random data.

Jay
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Are peripherals disabled by default?
PostPosted: Fri Oct 02, 2015 6:23 am     Reply with quote

haxan7 wrote:
Are all the peripherals turned off when you create a new project in CCS?

Any pointer to save precious battery power?

Compiler: v5.0xx


It's nothing to do with the compiler or the project: it is hardware behaviour. Many peripherals are turned off at a hardware reset. To use them, they have to be turned on, either by compiler added initialisation code or by user initialisation code. Some perpiherals are connected to some pins by default on some PICs. This often catches people out, but while they might be connected, they are often disabled/turned off. ADCs are often on, but not doing anything and with no inputs connected. The datasheet is the only way to know what does what.

One problem to note is that on some types of warm start some of the the peripherals may not be turned of: they stay running. Only a hardware reset sets them back to their default state.

Saving battery power is not as easy as just turning things off. Processor clock rate and how the clock is derived plays an important role, and hardware design, especially things such as the selection of pull-ups/downs and the "normal" state of pins can have siginificant impact on system power consumption. In systems that have bursts of activity and a significant time asleep/dormant faster clocks may lead to lower overall power consumption, but only careful testing can confirm it.

Very often though, the best advice that can be given when battery life is at a premium is to use a bigger battery. Not what some people want to hear, but it often gives the lowest overall cost and time to market.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 6:43 am     Reply with quote

Quote:
the ADC and comparators are defaulted on

Temtronic,
On your favorite chip, the 18F46K22, both of those are off by default.
That includes the OP's 18LF45K22.
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 7:16 am     Reply with quote

It really is a 'look at the data sheet' thing.
You get things like fuses that affect the PWM on some chips, and the ADC multiplexer.
Generally the bits default to '1' on most control registers and for a lot of things this is the 'off' state.
The 'Microchip default' has tended to change over the years. Most of the early chips defaulted for example to having the watchdog enabled in the 'erased' state. Lots now don't, but often these are the ones with more complex watchdog configurations.
The I/O pins will always tend to be set to 'input', so they won't clash with anything connected to the outside, except now for some of the power PWM pins that often now have a programmable 'boot' configuration.
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 1:33 pm     Reply with quote

As another comment to this, if you have things like FET drives that if enabled in the wrong sequence or at the wrong time, could result in silly currents being drawn, I'll always add external resistors to bias them 'off'.
Though it is 'tempting' to think 'undriven, so safe' when you wake up, it is surprising how often external RF, or leakage etc., can 'drive' an undriven input to a voltage. Something like a 100K resistor on each gate, helps ensure they _stay_ off, till you drive them....
newguy



Joined: 24 Jun 2004
Posts: 1904

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 2:40 pm     Reply with quote

A gate without a pullup or pulldown resistor can cause the FET to switch simply by waving your hand within a few inches of the thing. Touching it, even if you're grounded, was guaranteed to get it to change state.

I always design things with gate resistors to bias the FET in a guaranteed safe state. Peace of mind is definitely worth the fraction of a cent the resistor is worth.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 2:48 pm     Reply with quote

There is an additional cost there, if you're trying to make an extremely
low power design. The pull-up keeps the mosfet in the Off condition
for a p-channel high-side driver. Let's say you use a 100K pullup
with a 3.6v lithium battery circuit. That's 36ua of additional current
drain whenever the mosfet is turned on by setting the PIC's i/o pin to
a logic low level.

I'm not saying don't do it, but it is an annoying additional cost.
temtronic



Joined: 01 Jul 2010
Posts: 9198
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 3:23 pm     Reply with quote

something else....
Without knowing the details of your project..you might consider a BIGGER battery ! These days you can get a LOT of energy in a small package for a low cost. Spend an extra buck and get 3-5 times the life or more.
I've used sealed lead acid batteries that are 100 x the capacity I 'need' as they only cost a bit more what the design calls for.Also battery life is cut way short the colder it gets!

Just something to think about.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 3:56 pm     Reply with quote

The case is very small. We can't fit anything larger than a half AA cell.
newguy



Joined: 24 Jun 2004
Posts: 1904

View user's profile Send private message

PostPosted: Fri Oct 02, 2015 7:13 pm     Reply with quote

Low power is the last great unexplored unknown for me. So far in my career I've never had to design anything that's battery powered. I know that the pullup/down can be a power drain in a low power device but I've never had that limitation imposed on me.....yet.

...I guess I should apply at VW. Laughing
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Sat Oct 03, 2015 12:04 am     Reply with quote

PCM programmer wrote:
There is an additional cost there, if you're trying to make an extremely
low power design. The pull-up keeps the mosfet in the Off condition
for a p-channel high-side driver. Let's say you use a 100K pullup
with a 3.6v lithium battery circuit. That's 36ua of additional current
drain whenever the mosfet is turned on by setting the PIC's i/o pin to
a logic low level.

I'm not saying don't do it, but it is an annoying additional cost.


Agreed. There are though other things. Generally if the design is 'low power' stuff will be off, 99% of the time, so the extra consumption becomes insignificant. Also there are other ways. For instance, run all the resistors to a line connected to a small capacitor. Have this with a diode so it is always 'discharged' when the system is off. Then once the gates are driven, the capacitor charges to the average voltage on the gates, and reduces the power loss. Even better have a single FET that actually enables the power to all components that are 'off' when the chip is asleep. Only one resistor then needed for this. Smile

As a comment on 1/2AA. Look at the LS14250. 3.6v 1.2Ah. Compared to the batteries you could get only a few years ago, these give really good power for the size, and the technology has good durability itself, performing better at low temperatures than most batteries.
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