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

TIMER 0 - [Solved]

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

TIMER 0 - [Solved]
PostPosted: Thu Jun 21, 2012 9:25 pm     Reply with quote

Hi,

PCM 4.132 + MPLAB 8.85
16F88

Code:
#fuses HS,NOWDT,NOPROTECT, NOLVP,INTRC_IO

I'm using the internal 8mhz osc.

Is there any way to turn off timer 0 _after its started_?

I'm using:
Code:
SETUP_TIMER_0(RTCC_DIV_2|RTCC_INTERNAL);


This drives PIN_A6 ( toggles in ISR) to drive a charge pump.
However after I'm done reading the sensor powered via the charge pump... I would like to stop the pump.

I was thinking:
Code:
SETUP_TIMER_0(RTCC_DIV_2|RTCC_EXT_L_TO_H);

and there is no external osc... I'm using it as an ANALOG port.

This does work... however I don't want to put the PIC in a weird state...and i don't know the consequences of this.

Do you guys know if this is acceptable?

Should I go for direct control of T0CS on OPTION_REG?... sounds simple enough.
_________________
CCS PCM 5.078 & CCS PCH 5.093


Last edited by Gabriel on Fri Jun 22, 2012 8:02 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 21, 2012 10:24 pm     Reply with quote

Quote:
This drives PIN_A6 ( toggles in ISR) to drive a charge pump.

Just disable the Timer0 interrupt and set Pin A6 to whatever inactive state
you want (high or low).
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu Jun 21, 2012 10:41 pm     Reply with quote

Hi PCM...

Thanks for the suggestion, however i think i need to further explain my intentions...
Its powering a sensor in a data logger... I'm trying to save power by disabling the module...

In your proposed solution, does the timer keep counting? (consuming energy)

I don't really get how you can turn it on but not off...
or is it always on? and I'm just using its output selectively as you mention?

Pardon my timer ignorance..

Edit: I see its off during sleep so thats good for my app... but still ... I want to turn it OFF.

Edit (again):... I believe the secret lies in T0CS on OPTION_REG indeed.... I shall test and share!


thanks!

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 21, 2012 11:40 pm     Reply with quote

Before worrying about this issue, I would check the current consumption
of Timer0 by connecting an Ammeter that reads in microamps or
Nanoamps to the PIC and measure it. You can easily do this with
Timer1 or Timer2, since they can be turned on and off.
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Fri Jun 22, 2012 1:54 am     Reply with quote

As a comment, setting it to the external pin, if this pin isn't driven, risks drawing significantly _more_ power, than just letting it run!....

If you look in the header file for the PIC, you will find (for instance), that Timer1, has a 'T1_DISABLED' option. Then that there is no similar option for Timer0. Look in the data sheet, and the reason 'why', is simply that there is no option to disable this timer. You will save a tiny fraction, by setting it to clock as slowly as possible (T0_DIV_256), but the amount is so incredibly small, that even having a single pin floating, will draw hundreds of times as much....

So, you can stop it by selecting:
SETUP_TIMER_0(T0_DIV_256|T0_EXT_L_TO_H);

but you _must_ then drive the RA4 pin either high or low.

The same applies to all input pins, these _must_ be driven to either Vss, or Vdd levels, or you risk power consumption that makes the timer look totally insignificant.

Worth perhaps putting it in perspective. The current drawn by not washing the PCB really thoroughly, or even breathing near the board, far exceeds what is drawn by this module....

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Fri Jun 22, 2012 5:19 am     Reply with quote

also....

you can always add a larger capacity battery to your project !
The amount of time spent on reducing current flow is HUGE compared to the cost of another battery.Realistically you'll have to tear your code apart line by line to see if it can be made smaller or more efficient,getting rid of excess code,dupicate functions,use fast_io() not stanard_io(), etc.

Unless you've got a LOT of time and like the 'exercise' of maximizing power consumption(who wnats to count electrons ?!), reality is that a bigger battery is easier,cheaper,faster and works a whole lot better.

I gave up on the 'smaller is better' idiom decades ago.My boards are 'man-sized' allowing easy upgrades or mods the customer wants(always AFTER the project is 'done'),battery option is always AA cells,with pins for external battery as well.Same with code.I use a large memory PIC so it's easy to add those 'features' the customer forgot...

yes, it cost a few pennies up front but the added R&D/code cutting time is next to nothing as there's room to fulfill the project without making new board, another PIC,etc.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Jun 22, 2012 6:42 am     Reply with quote

Quote:
If you look in the header file for the PIC, you will find (for instance), that Timer1, has a 'T1_DISABLED' option. Then that there is no similar option for Timer0.


I precisly looked for the "reason Why"...

I see that i can enable the timer0 module by doing the Setup timer.. which writes to T0CS on OPTION_REG...which starts the timer...

now.. that enables and starts the timer... why cant i use that to disable it?

what happens on the hardware when i _do not_ include any timer code?

its off? right? ... so there _IS_ a way to stop it...



i guess you guys are right in that the TIMER0 consumes negligible power...
and it does _stop_ while in Sleep...

but i am sure the _has_ to be a way to stop it... after all ther is a "switch" to enable it... why cant that same switch go both ways?

that CCS didnt include that feature does not really mean its not posible, we have all had to modify a .h file before...

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
jeremiah



Joined: 20 Jul 2010
Posts: 1337

View user's profile Send private message

PostPosted: Fri Jun 22, 2012 7:22 am     Reply with quote

Gabriel wrote:

I see that i can enable the timer0 module by doing the Setup timer.. which writes to T0CS on OPTION_REG...which starts the timer...


TOCS only selects the clock source:

Quote:

T0CS: TMR0 Clock Source Select bit
1 = Transition on T0CKI pin
0 = Internal instruction cycle clock (CLKOUT)
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Jun 22, 2012 7:41 am     Reply with quote

Quote:
My boards are 'man-sized'


i forgot to mention... this is the funniest thing ive seen in this forum...
I agree with your temtronic...

you might like this:
http://www.element14.com/community/groups/hack-factory-global-hackerspace-challenge?view=blog

http://makerfaire.com/pub/e/8185

;)

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Solved
PostPosted: Fri Jun 22, 2012 7:49 am     Reply with quote

Jeremiah you are right..

so... what the hell is timer 0 doing if my code does _not_ use it?
(like in simple led blink program)

it has to be in a defined state:
ON
OFF
ALWAYS_ON (but "disconected")



EDIT:
So, further datasheet diving has convinced me its:
ALWAYS_ON (but "disconected")
In which case, as PCM Programmer suggested, the proper way to "turn it off" is to disable the interrupt... and as others suggested, its really not worth persuing as there are no tangible gains... however, when not using its better to leave it as a timer rather than a counter so that it does not pull any current from the external clock input pin...

i think that about sums it up. (might be old for you, but its new to me)

Thank you all..

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
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