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

Help me understand OSC1 & OSC2 and T1OSO & T1OSI pin

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



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

Help me understand OSC1 & OSC2 and T1OSO & T1OSI pin
PostPosted: Sun Mar 01, 2015 9:18 am     Reply with quote

Please help me understand OSC1-OSC2 and T1OSO-T1OSI pins and how CCS C compiler deal with them. I think I understand them, however I want to be sure. If I understood the datasheet correctly for most PIC that have OSC1, OSC2, T1OSO & T1OSI;

OSC1 & OSC2 are for the primary oscillator for the chip.

T1OSO & T1OSI are for the Timer1 oscillator only.

SO if I have 32 kHz crystal connected to OSC1 & OSC2 then the chip will operate only at 32 kHz configured as LP? In this case Timer0, Timer1 ...etc will only operate at MAX of 32 kHz?

if I have 32 kHz crystal connected to T1OSO & T1OSI then this will only effect Timer1. In this case I can run the chip at 4MHz internal or external and Timer1 at 32 kHz?

Thanks,
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 9:43 am     Reply with quote

You should post which PIC you're using !

While what you say is 'true', some PICs can have an 'interesting' clock path that may not be what you think it should be.

Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 9:56 am     Reply with quote

Jay,
Thanks for the reply. As example 18f2685.
Thanks
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 11:47 am     Reply with quote

I downloaded the datasheet and it appears that T1OSC is NOT limited to just the timer1 clock, rather it can be used for the CPU and other things....

perhaps others who use it will reply, i don't have that chip to test at this time.

Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 2:25 pm     Reply with quote

The datasheet that I have for the 18f2685 shows:
T1OSO is Timer1 oscillator output.
T1OSI is Timer1 oscillator input.
I understand that these pins also can be used as Digital I/O and other things.
If I want to use 32768Hz crystal to operate Timer1 as RTC, does it make a deference if the watch crystal was connected to OSC1-OSC2 or T1OSO-T1OSI. The datasheet shows the example with the crystal connected to T1OSO-T1OSI.
However if the crystal is connected to OSC1 & OSC2 would that achieve the same?
Which one would be more efficient as design HW and SW?
I just want to know for my own information!
Thanks'
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 2:48 pm     Reply with quote

Normally you'ld use the 32KHz xtal on T1OSO,-T1OSI pair, with appropriate caps(nominally 32puff). This would be the 'timebase' for your RTC.
There is a Software Based RTC program in the code library on this forum, you should look at it.
One MAJOR problem with ANY software based RTC is that you MUST have a GREAT power supply to the PIC ! You'll have to factor in what the PIC is doing, loads on the pins, Iq of the regulator, etc.etc. etc.
The way I've done it for decades , is to use a hardware RTC like the DS1307.Once programmed it keeps very good timing and with the coin cell battery backup, good for at least 10 years.

As far as using the 32KHz xtal as the 'primary' clock of the PIC, it will take a very,very long time to execute all instructions. compared to a 4MHz xtal, it will take 125 times LONGER ! That's a huge amount of time,allowing the PIC to drain the electrons out of your battery, in a very,very short amount of time.
That's why I said you need to do an 'energy study', read the Microchip AP note #AP606, for starters.
Also, when the PIC wakes up from sleep, it will take a LOT longer as well, so your battery will go dead sooner.
If you use a software clock, it involves a LOT of code, at 32KHz, that will take a LOT of power and time...

Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 3:17 pm     Reply with quote

temtronic,
I am learning and educating myself. Please do not think I am arguing this subject!
I got your point as far as the main clock as follow:
If using 32768Hz crystal using SLEEP() it will consume more power as per say 32768000Hz using SLEEP(). The instruction when waking up is less time for the higher clock than the slower clock? Less time mean less power?

Using the RTCC DS1307 required 32768Hz crystal in addition to the PIC. My thought is as far as power, regardless of the standalone RTC PIC clock will use less power than the PIC with the additional RTCC DS1307?
I will read the AP606.

Back to my main question in the first post; is my concept of OSC1-OSC2 and T1OSO-T1OSI pins correct?
Thanks,
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 3:33 pm     Reply with quote

Basic CMOS information.... it consumes power when in transition, steady state (either a high or a low) doesn't consume power.
So the faster you run a PIC (or other CMOS device) the more power it consumes.
Consider a program that requires 1000 cycles to complete the task. A pic using a 32KHz xtal will require more energy as the time per cycle is greater than at 4MHz. The PIC at 4MHz, while using more energy per cycle, gets the job done faster, so the net result is it will use less energy.

That AP note explains it better, with charts and real numbers and I understand English is not everyone's first language so information can be 'lost' in the translation.

You are right, the primary clock should be fast so that the PIC executes the code as fast as possible (or as accurately as possible if timers are involved). The T1 osc can be used for the SW RTC.

One item about a HW RTC is that is will keep time and not 'reset to zero' should the PIC be reset ! A 'glitch', noise spike', EMI , low battery can cause the PIC to reset and that will reset the SW RTC data. Something to consider.

Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Mar 01, 2015 6:13 pm     Reply with quote

Well, after reading the AN606 I came up with:
Code:
Osc.Type Frequency = Crystal 32.768 kHz
Osc. Mode = LP
Power-up Region Current,Time = 51.2 uA, 19 ms
Active Region Current,Time = 23.5uA, 93 ms
Sleep Region Current,Time = 0.3uA, 140 ms

Total Time = (Power-up Region Time + Active Region Time + Sleep Region Time)
Total Time = 19 ms + 93 ms + 140 ms
Total Time = 252 ms

power-up = ( 19 ms / 252 ms ) x 100 = 7.54%
active = ( 93 ms / 252 ms ) x 100 = 36.9%
sleep = ( 140 ms / 252 ms ) x 100 = 55.56%

Calculate the number of hours in 6 months = 4320 hours

power-up = 4320 hours x 7.54% x 51.2 uA
power-up = 4320 hours x .0754 x .0512 mA = 16.6772736 mAh

active = 4320 hours x 36.9% x 23.5uA
active = 4320 hours x .369 x 0.0235mA = 37.46088 mAh

sleep = 4320 hours x 55.56% x 0.3uA
sleep = 4320 hours x .5556 x 0.0003mA = 0.7200576 mAh

Sum the capacities of each period = 16.6772736 mAh + 37.46088 mAh +  0.7200576 mAh
Sum the capacities of each period = 54.8582112 mAh



Osc.Type Frequency = Crystal 8 MHz
Osc. Mode = HS
Power-up Region Current,Time = 123uA, 18 ms
Active Region Current,Time = 2.11mA, 250us
Sleep Region Current,Time = 0.3uA, 140 ms
                                                                     
Total Time = (Power-up Region Time + Active Region Time + Sleep Region Time)
Total Time = 18 ms + .25 ms + 140 ms
Total Time = 158.25 ms

power-up = ( 18 ms / 158.25 ms ) x 100 = 11.37%
active = ( .25 ms / 158.25 ms ) x 100 = .16%
sleep = ( 140 ms / 158.25 ms ) x 100 = 88.47%

Calculate the number of hours in 6 months = 4320 hours

power-up = 4320 hours x 11.37% x 123uA
power-up = 4320 hours x .1137 x .123 mA =  60.415632 mAh

active = 4320 hours x .16% x 2.11mA
active = 4320 hours x .016 x 2.11mA = 145.8432mAh

sleep = 4320 hours x 88.47% x 0.3uA
sleep = 4320 hours x .8847x 0.0003 mA=  1.1465712 mAh

Sum the capacities of each period = 60.415632 mAh + 145.8432mAh +  1.1465712 mAh
Sum the capacities of each period = 207.4054032 mAh

So the 32768Hz will use less power than the 8MHz unless my math is wrong!

Would someone please answer my original question about OSC1-OSC2 and T1OSO-T1OSI pins?
Thanks,
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 1:41 am     Reply with quote

Yes, using an 8MHz _crystal_.
However try your calculations using an internal RC clock (assuming the particular chip you want has one). Note my line is the other thread you are running (why two?):
"Internal oscillators cost less power than crystals etc.."
This is made worse, because crystals also take a long time to start, so you have several tens of uSec with the oscillator 'on', but code not actually able to run properly.

However you are also ignoring the other circuitry. At 32KHz, the PIC only executes 8000ips. Things like driving an LCD, take quite a large number of instructions, and the LCD will draw significant power. With the slow oscillator, it may well take you 1/10th second or more longer to actually generate the display wanted, so the LCD will have to be on for this much longer. Assuming the chip actually needs to do some work when awake (read something, display something etc..), you need to include how long the other circuitry will need to be 'on', and how much power this draws, into your calculation.

On the oscillators, you need to look at the data sheet for your particular chip. Temtronic answered for one, but there are something like ten different 'patterns' of actual clock circuitry. For instance some PIC's can wake using their internal RC oscillator, and then switch to using the T1 oscillator, without ever having to have an external oscillator on OSC1/OSC2. The max frequency useable on the T1 oscillator, also comes in the data sheet. On some chips it is limited to perhaps 32 to 33KHz, while others do have a wider range. So there is no generic answer to your question.

For really low power, look at the NanoWatt PIC's. Remember also that if you are wanting the clock to run when you are not working, this has to be factored into the calculation. The secondary oscillator on such a PIC, draws 0.5uA typically. Then add the base current of the chip, to give what it'll draw with the secondary oscillator running. Now compare with a RTC chip like the DS1307, which has a typical current with the oscillator running, of only 0.3uA, and using the separate chip uses less power than the PIC itself, especially if you want 'time', since this does all the work of keeping track of hours, minutes, day of week etc., without any code time in the PIC....
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 9:07 am     Reply with quote

Ttelmah,

I appreciate your detail answer. I will consider all the suggestions by you and Jay.

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