PDA

View Full Version : PIC18LF13K50 Extremly low power counter



pedja089
- 11th October 2010, 19:13
What is the best way to wake up the PIC from sleep?
I need to check the state of pins about 30 times per second.
I tried with tmr1 and crystal @32,768KHz, to wake up pic. But i'm not happy with results. PIC does wake up, but never on time...
I measured time between pulses on oscilloscope, I just added in an interrupt pin high, low pin.
Time between pulses vary for about 10ms. Why does this happen??
Thanks

LinkMTech
- 12th October 2010, 02:10
Have you considered using the Interrupt On Change (IOC) feature? This way the little guy gets to sleep longer than 33ms before having to look for a status change. :)
Set it up to "wake" on a change of state and go from there. (I know I make it sound so easy) A quick glance at the data sheet shows that Ports A and B have pins available with this feature.

pedja089
- 12th October 2010, 12:04
I tried, but pull up resistor draw to much curent. So i use RA4 to switch on/off pull up. If pull up aren't always on, i can't use IOC. That is reason why i need to wake up...
Now i got an idea:) Maybe is better to use CLKOUT from RTC, and IOC, but again i need 1 more resistor. CLKOUT is open drain... But on other side i don't need tmrosc on pic...
What do you think about that?
EDIT:
Now I saw in RTC datasheet that CLKOUT can be set to 32.768 kHz, 1024 Hz, 32 Hz and 1 Hz. I'm thinking to set CLKOUT to 32 Hz. And to to use INT0 instead of IOC. I think that it should give me precise 32 wake up's per second.

LinkMTech
- 12th October 2010, 15:45
The external 32Hz clock trigger is worth a try, sounds simple enough.
For future reference, I found that I had to turn OFF particular device hardware and functions like WDT and BOR before going into Sleep mode or the unit drew too much current. It was a difference between approx. 150ua to a final 60nA while using the internal OSC set to 1MHz and 2 pins configured for IOC.
Looking at your schematic, I don't see any external loads that would cause the high current draw so my guess would be an internal drain.
The RTC CLKOUT looks like the simplest solution but now like you said, it needs to be pulled up.

pedja089
- 12th October 2010, 17:37
I'll try this tonight or tommorow ;)

pedja089
- 13th October 2010, 23:46
Finally over...
Here's the result:
RTC always power on, Pic 30mS in sleep, about 1 mS running, Open inputs, Average consumption about 50uA. Now just to determine the value of pull up resistors, and type of capacitors.
By the way wich type of capacitors have the lowest leakage current?

LinkMTech
- 14th October 2010, 21:27
Cool deal! Good feeling when you get over that hurdle huh?
I generally keep to XR7 type caps with the higher voltage (25V to 50V) rating.


Voltage Duration: Capacitors are operated at a voltage below their rated value then the reduced stress and lower leakage current will give an improvement in the life expectancy. Since leakage current increases with temperature the benefit of a reduced operating voltage is more pronounced at higher temperatures.

from: http://www.interfacebus.com/Engineering_Dictionary_Capacitors10.html

pedja089
- 14th October 2010, 22:28
It was not that difficult, but a nice feeling when you finish something:D
The problem was that this was the first time that I work with 18LF13K50. There are some specific things about this PIC:cool:
Now I'm trying to reduce run time on pic...
For testing I'm using 220uF/6.3V low esr capacitor in parallel with batery, close to pic power pins, and 100nF/50V ceramic capacitor on Vusb pin.
Thank you very much for your help:)

ScaleRobotics
- 15th October 2010, 05:19
Hello Pedja089,

Sounds like an interesting project. I have never dabbled in low power. Any chance you would be willing to share some of your code? I know there is a lot of interest in the 13k50 and 14k50 chips.

Thanks,

Walter

Jerson
- 15th October 2010, 06:01
Hi Walter

There's not much more than simply putting the PIC to sleep and turning off all peripherals you can do without. All these add up to give you a truly low power sleep operation. Typical drain should be in the 10s of uAmps if you have everything set up right.

The things to watch out for in low power sleep
1 - Disable the peripherals you do not need (saves some power)
2 - Turn off all ports which are draining power. For example, if a pin has a pull up on it, turn that pin high if you can afford to do it (should not turn on some device that you do not intend to).
3 - Keep an interrupt enabled so that you can get out of sleep

I use sleep mode quite extensively and get almost the shelf life out of my batteries

Regards
Jerson

ScaleRobotics
- 15th October 2010, 13:12
Thanks Jerson,

The main reason I ask is I think it would make a great little Wiki with some time/power results. I don't recall seeing anything like that on the forum. If there is not an interest here, then I will try working something up.

Walter

prstein
- 15th October 2010, 13:54
Can any of you folks share how you measure the average current draw? I've done a few extremely low power projects and have always sort of "eyeball averaged" the current on a standard multimeter. I'd love to learn a better method.

Best Regards,
Paul

ScaleRobotics
- 15th October 2010, 14:05
Good question. Maybe use a small capacitor, and see how long the power lasts? These guys had an interesting experiment. But at 3 weeks and counting, I think their capacitors were a bit too big. http://hackaday.com/2010/09/30/launchpad-takes-ultra-low-power-to-the-extreme/

mackrackit
- 15th October 2010, 14:05
I use a Fluke 83. It has a MIN/MAX button.

Jerson
- 15th October 2010, 14:08
Well almost all the folks who have tested use a multimeter to check. The benchmark is the datasheet which would show a typical draw of 40uA. Anything over that indicates something is drawing power and you need to check on it. I've listed some of the tricks that I used.

This is the code I use that puts the PIC into low power sleep



StopNow:

PORTB = $f8 ' turn all rows low for interrupt to occur
INTCON = $8 ' RBIE = 1 to wakeup from sleep, not necessary to have GIE enabled for this
asm
sleep
nop ' the 2 nops are a workaround for some pics
' that slip on the sleep
nop
endasm

PORTB = $ff ' turn off all rows
INTCON = 0 ' turn off the interrupts as I don't need them now
goto loopstart 'start right at the front



Besides this, things like BOR, Watchdog all consume power. You should consider if your application needs these features more than the minimized power drain.

Check each pin of the PIC to see that it is turned to a state which does not cause power drain due to itself or connected circuitry. For example, if you have the PORTB pullups turned on, putting a PORTB pin to 0 will cause a current drain there. Turning the port to all inputs may not be the best solution always.

pedja089
- 15th October 2010, 14:13
scalerobotics, Here is it, but not whole code.

define OSC 4
'RTC
SYMBOL SCL = PORTC.3
SYMBOL SDA = PORTC.6
symbol CLCK_Alrm = portc.7
input clck_alrm
'Input
symbol In1 = PORTA.1
symbol In2 = PORTA.0
symbol In3 = PORTA.5
symbol In4 = PORTC.5
INPUT PORTA.1
INPUT PORTA.0
INPUT PORTA.5
INPUT PORTC.5
'Pull
symbol Pull= PORTA.4
OUTPUT Pull
output portc.4 'just for testing
OSCCON=%01010110
OSCCON2.2=0
ANSEL=0
ANSELH=0
SLRCON=0
RCON.7=1

UCON.3=0 ' disable usb, to alow use of ra0 and ra1
IOCA=3 ' set ioc on ra0 and ra1 EDIT: bits 0 and 1 must be set, to use ra0, ra1...

INTCON=0
INTCON2=%10000000
INTCON3=%00000000
PIR1=0
PIR2=0
PIE1=0
PIE2=0
IPR1=0
IPR2=0




disable
PWR_On:
pause 10
I2CWrite sda,scl,$a2,$02,[1,1,1,1,1,1,1] ' just put some valid time/date in rtc
I2CWrite SDA,SCL,$A2,1,[%00000010]
I2CWrite SDA,SCL,$A2,$0D,[%10000010] 'enable clockout @ 32Hz
enable
INTCON=%10010000 'enable interrapt's
on interrupt goto int


Start:
sleep 60 'sleep until int0
goto start
disable interrupt

Int:
pull=1 'enable pull up
Toggle portc.4 'do something :)
'Read/write to portst etc.
pull=0 ' disable pull up
INTCON=%10010000
goto start
end

In file ppb/18F13K50.INC I'm just put OFF where ON was;)

__CONFIG _CONFIG1L, _CPUDIV_NOCLKDIV_1L & _USBDIV_OFF_1L
__CONFIG _CONFIG1H, _FOSC_IRC_1H & _PLLEN_OFF_1H & _PCLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2L, _PWRTEN_OFF_2L
__CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _BBSIZ_OFF_4L & _XINST_OFF_4L
Still I wonder why TMR0 was not stable...
Code is a similar, i just enabled tmr0osc and overflow interrupt.
Edit2: I'm using UNI-T UT81B

LinkMTech
- 15th October 2010, 18:39
Can any of you folks share how you measure the average current draw? I've done a few extremely low power projects and have always sort of "eyeball averaged" the current on a standard multimeter. I'd love to learn a better method.

Best Regards,
Paul

Hi Paul,
I used to use this meter for the low current stuff:
4838
But just as Jerson outlined the necessary steps and precautions of putting that baby to Sleep, I saw the current drop off the bottom edge, now that was exciting!
I bought the Fluke 8050A that can measure into the 10's of nano Amps to see what was really happening.

ScaleRobotics
- 16th October 2010, 17:04
Thanks for the code Pedja and Jerson,

I will try that out and promote it to a wiki once I get the chip.

I also found a little introduction to XLP (extremely low power) in Microchip's AN1267 http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en541031

Paul, my multi meter doesn't go that low, so I may have to buy something that does. But I did find this at Microchip for getting theoretical average power consumption (and estimated battery life):
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en545243

pedja089
- 16th October 2010, 19:48
Program is not working properly ...
Bug is in the last line of code...
Instead GOTO start must be RESUME.
I suppose to fill stack memory, because it is not empty when using GOTO.

prstein
- 17th October 2010, 02:01
With regard to measuring the current draw, thanks for all the suggestions. For the bottom line, I think I foresee a new multimeter in my future.

Best Regards,
Paul