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

12F629 @ 32kHz - driving me barmy!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dazlogan



Joined: 19 Oct 2003
Posts: 24
Location: Cambridge, UK

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

12F629 @ 32kHz - driving me barmy!
PostPosted: Wed Apr 14, 2004 4:55 pm     Reply with quote

Hi,

Please help before I jump out of the window...

I have a PIC12F629 running at 3V with a 32kHz watch crystal as the clock.

I simply want to put the PIC to sleep() and wake up on a timer 1 overflow but cannot for the life of me get it to work.

The PIC is running ok, i've got an LED to flash so I know the hardware's ok. It's just this damn sleep/wake up on timer 1 overflow i cant fathom out.

The window is open and i'm ready to jump!

Regards,
Darren
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

Do not jump yet!
PostPosted: Thu Apr 15, 2004 2:20 am     Reply with quote

I think that you need to know that when a PIC is in sleep mode

The timers will not be counting (As stated in the microchip datasheet)

IF the timer does not count then THE TIMER will never overflow!!!

-----------------------------------------------------------------------
Best Regards
_________________
Best Regards
Ttelmah
Guest







Re: Do not jump yet!
PostPosted: Thu Apr 15, 2004 2:25 am     Reply with quote

asjad wrote:
I think that you need to know that when a PIC is in sleep mode

The timers will not be counting (As stated in the microchip datasheet)

IF the timer does not count then THE TIMER will never overflow!!!

-----------------------------------------------------------------------
Best Regards


To do what is wanted, the poster needs to add a second crystal. Attach this to Timer1, and set Timer1 to 'oscillator' mode. Timer 1 _will_ run when the chip is asleep, _but only if it is being clocked by an external source (in asynchronous mode), or using it's own oscillator_....
Reading the chips data sheet, is vital.

Best Wishes
arif
Guest







sleep
PostPosted: Thu Apr 15, 2004 1:44 pm     Reply with quote

#include <12f675.h>
#device adc=10
#use delay(clock=4000000)

#fuses intrc_io,WDT,NOPROTECT,NOMCLR,NOBROWNOUT

#define vericiled pin_a5
#define alarmled pin_a4

main()
{
long int offset,olcum;
int i=0,olc;


setup_counters(RTCC_INTERNAL,WDT_2304MS);
setup_timer_1(T1_DISABLED);

while(1)
{
sleep();
output_high(alarmled);
delay_ms(1);
output_low(alarmled);
}
}


i used this code. this will sleep and wake up every 2304 ms.
i tried this for 12F675 and i hope it will work for 12Fxx too.
Ttelmah
Guest







Re: sleep
PostPosted: Thu Apr 15, 2004 2:41 pm     Reply with quote

arif wrote:
#include <12f675.h>
#device adc=10
#use delay(clock=4000000)

#fuses intrc_io,WDT,NOPROTECT,NOMCLR,NOBROWNOUT

#define vericiled pin_a5
#define alarmled pin_a4

main()
{
long int offset,olcum;
int i=0,olc;


setup_counters(RTCC_INTERNAL,WDT_2304MS);
setup_timer_1(T1_DISABLED);

while(1)
{
sleep();
output_high(alarmled);
delay_ms(1);
output_low(alarmled);
}
}


i used this code. this will sleep and wake up every 2304 ms.
i tried this for 12F675 and i hope it will work for 12Fxx too.

This only wakes up at very approximate intervals. It is great if you don't want accuracy, but not if you want things to be done at exact times. The variation in time for the watchdog timeout, depending on voltage, chip example, and temperature, can be massive (I have seen the 'nominal' 18mSec watchdog, timeout at around 8mSec...).

Best Wishes
dazlogan



Joined: 19 Oct 2003
Posts: 24
Location: Cambridge, UK

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

Oh dear
PostPosted: Thu Apr 15, 2004 2:52 pm     Reply with quote

Hi,

Thanks for watchdog trick, but as the poster above says, it is inaccurate and I do need a certain amount of accuracy.

The PIC needs to count up to 6 months (183 days) - the tolerance on this is plus/minus 5 days.

So the only way I can wake up on timer 1 interrupt is by applying a second crystal - is that right?
So I guess in this situation, I could use the internal 4MHz clock for normal running mode but power timer 1 from the 32KHz watch crystal?

EEeek!, that means high currents (mA or so in normal running mode) which I want to avoid, as I'm using a 3V CR2032 coin cell to power the PIC which must stay alive for at least 9 months.

Regards,
Darren
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Oh dear
PostPosted: Thu Apr 15, 2004 4:05 pm     Reply with quote

dazlogan wrote:
Hi,

Thanks for watchdog trick, but as the poster above says, it is inaccurate and I do need a certain amount of accuracy.

The PIC needs to count up to 6 months (183 days) - the tolerance on this is plus/minus 5 days.

So the only way I can wake up on timer 1 interrupt is by applying a second crystal - is that right?
So I guess in this situation, I could use the internal 4MHz clock for normal running mode but power timer 1 from the 32KHz watch crystal?

EEeek!, that means high currents (mA or so in normal running mode) which I want to avoid, as I'm using a 3V CR2032 coin cell to power the PIC which must stay alive for at least 9 months.

Regards,
Darren


The oscillator running at 32K has a typical supply current of 18uA with a 3V supply. At that level you can run for a long time. You don't need a sleep mode at all. Just don't power any external circuits unless they are in use.
dazlogan



Joined: 19 Oct 2003
Posts: 24
Location: Cambridge, UK

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

190uA!?
PostPosted: Tue Apr 20, 2004 6:09 pm     Reply with quote

Hi,

Sorry to drag this thread up again.

I've got the 12F629 being driven by a 32kHz crystal. With only the PIC attached to a 3V, I am finding a current draw of about 190uA.

(I know the PIC is running correctly i've had a LED flashing just to prove the thing is ok)

Any ideas why im getting such a high current draw?

Code:

#include <12F629.h>
#use delay(clock=32768)
#fuses LP,BROWNOUT,WDT,PUT
//#fuses XT,BROWNOUT,NOWDT,PUT
#define PIN_LED   PIN_A0
#define PIN_RESET   PIN_A1

// Main function
void main() {

int NumMins,i,j;
long NumHours;
boolean FirstPower=TRUE;

   #byte CMCON=0x19
      setup_counters(RTCC_INTERNAL,WDT_2304MS);
      setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
      setup_vref(VREF_LOW|6);
      enable_interrupts(INT_TIMER1);
      enable_interrupts(INT_COMP);
      enable_interrupts(global);

// other basic code...


Cheers

Darren
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 20, 2004 6:25 pm     Reply with quote

Quote:
I've got the 12F629 being driven by a 32kHz crystal. With only the PIC attached to a 3V, I am finding a current draw of about 190uA.
Any ideas why im getting such a high current draw?


I know you don't want to hear this, but go to Microchip's website
and download the data sheet for the 12F629, here:
http://www.microchip.com/1010/pline/picmicro/category/embctrl/8kbytes/devices/12f629/index.htm
Then look at the appropriate chart in Section 12. Find the chart
the shows the current used for your particular oscillator mode,
and also find a chart for the various perpherals that you have
turned on. (ie., WDT, Brownout, etc.) Just add up the currents.
dazlogan



Joined: 19 Oct 2003
Posts: 24
Location: Cambridge, UK

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

8-)
PostPosted: Wed Apr 21, 2004 1:15 am     Reply with quote

Hi,

Errrr, do I detect a hint of sarcasm? (yes, of course I do)

Smile

The reasons I post such questions are:

a/ I've found that 10-15% of the time, problems are due to bugs in the compiler and i'd rather tap into members of this message boards vast and helpful experience rather than waste weeks of time trying to find the problem

b/ Sometimes I have a hunch at what the problem is, and it is reassuring to hear others from this board confirm my thoughts

c/ I would like to think that the use of this board, speeds up development time

There are often many things to be taken into consideration when using PICs for special projects. I've always used PICs at 4.0MHz without a care for current consumption but this time current is critical, and there are new areas to explore.

Apart from that, thanks for your reply.

Very Happy

Regards,
Darren
Ttelmah
Guest







Re: 8-)
PostPosted: Wed Apr 21, 2004 2:35 am     Reply with quote

dazlogan wrote:
Hi,

Errrr, do I detect a hint of sarcasm? (yes, of course I do)

Smile

The reasons I post such questions are:

a/ I've found that 10-15% of the time, problems are due to bugs in the compiler and i'd rather tap into members of this message boards vast and helpful experience rather than waste weeks of time trying to find the problem

b/ Sometimes I have a hunch at what the problem is, and it is reassuring to hear others from this board confirm my thoughts

c/ I would like to think that the use of this board, speeds up development time

There are often many things to be taken into consideration when using PICs for special projects. I've always used PICs at 4.0MHz without a care for current consumption but this time current is critical, and there are new areas to explore.

Apart from that, thanks for your reply.

Very Happy

Regards,
Darren

Using PICs at low current, does require a lot of 'thinking'. The critical things are to ensure that no inputs are allowed to float, and no outputs are 'driving'. Either of these, makes a huge difference to the consumption of the chip. Other things that make large effects (wouldn't apply off a 3v battery), are voltage regulators (many normal types draw several mA themselvs). Also when running at low speeds, remember that pull-up/pull down resistors can also scale with frequency. So a line that needs a 4K7 resistor, to make it settle quickly on a part running at 4MHz, can work with a 100K or more resistor at 32KHz. The watchdog draws an extra amount of current, but this can be worthwhile for reliability. The 'brownout' detector, also uses a suprising amount of current (disable this on such an application).
Remember if using an external oscillator, that these will typically draw more power than the PIC. They have fairly powerful 'drive' outputs, and unfortunately, these require a significant current. Special ultra low power designs are available. Try:
http://www.euroquartz.co.uk/oscillators-lowpower.htm
You might want to consider something like a DS1307 real-time clock chip. This is specifically designed to draw little power. Then sleep the PIC with the watchdog, and when it wakes, read the 'real' time from this chip. Also don't be afraid of the PIC drawing mA's when 'awake'. If you do things right, the PIC can sleep for (say) 2 seconds, and wake for just 50-60uSec, drawing perhaps 5uA when asleep, and 200uA when awake (and driving the I2C bus). With the consumption of the RTC chip (0.5uA typically), the whole unit then averages a consumption of under 6uA.
Your high consumption 'on test', suggests you have something 'missed', like a floating input, and (of course), the fact that it is driving an LED...

Best Wishes
Pete Smith



Joined: 17 Sep 2003
Posts: 55
Location: Chester, UK

View user's profile Send private message Visit poster's website MSN Messenger ICQ Number

Re: 8-)
PostPosted: Wed Apr 21, 2004 7:22 am     Reply with quote

Ttelmah wrote:

You might want to consider something like a DS1307 real-time clock chip. This is specifically designed to draw little power. Then sleep the PIC with the watchdog, and when it wakes, read the 'real' time from this chip. Also don't be afraid of the PIC drawing mA's when 'awake'.


You could also try hooking the "Test" output of this RTC (when in 1Hz output mode) to a wakeup on change/interrupt pin.

This way, you don't need to use the WDT at all (which IME is quite power hungry).

You could also try a PCF8583 (IIRC), which has a programmable alarm output. You could set it to interrupt you 30sec in the future, and just shut everything down.

If power is an important factor, you'll have to consider the RTC read/Alarm set time when accessing the I2C bus, and weigh up the pros & cons of the power used to write and power used to sleep/wake.

HTH

Pete.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 21, 2004 11:45 am     Reply with quote

Quote:
Errrr, do I detect a hint of sarcasm?

Actually it was mild exasperation. I know I shouldn't do it,
but sometimes I just give in to it. Mr. Green

But truly, the current data sheet (Rev. C) for the 12F629/12F675
is a lot better in the Electrical section than the typical Microchip
data sheet. The typical data sheet has "TBD" or "Preliminary"
plastered all over the charts. The Rev. C data sheet has very
detailed charts for power consumption. For example, Tables
12-3 and 12-4 show the following values for 3.0v operation:

LP MODE: 18 ua
WDT: 1.8 ua
BOD: 58 ua
T1OSC: 4.6 ua
CVREF: 85 ua
COMP: 6.1
--------------
Total 173.5 ua

That list above explains most of the current draw that you're seeing.
There may be other peripherals that you have turned on, that I'm not
aware of. Also, the values given above are from the "Typical" column
in the chart. It also gives "Maximum" values, so one or more of the
numbers above could actually be higher. Then it would explain the
entire 190 ua that you're seeing.

This is why I was mildly bugging you to look at the data sheet.
It's because the answer is there.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed Apr 21, 2004 1:07 pm     Reply with quote

You might try turning the refrence on and off as needed it can be configured on the fly. Same for the comparitor. Brownout is not going to help you.
dazza
Guest







thanks
PostPosted: Fri Apr 23, 2004 1:08 am     Reply with quote

Hi,

Thanks everyone.

PCM - yes it was because of all those features I had enabled. After disabling them, I'm down to about 30uA.

I do not have a regulator - instead im running directly off the CR2032 battery.

I shall have to put some sort of low-batt detection on here... I was going to use the on-chip comparator but that takes too much juice to be left on permanently.
So my next question is, can I turn the comparator on, do a batt. check and then turn it off again, say once every hour??? or does it need to be left on permanently?
Im thinking that a low batt. condition is when the voltage is 2.1V or less. If 2.1V, simply go to sleep.

Is there an on-chip voltage reference which will still be reliable at 2.1V?
Or do you think it's better to have an external ref. / op-amp configuration to detect low batt. at these low voltage levels?

Regards,
Darren
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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