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 CCS Technical Support

sleep() not working
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wangine



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

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

PostPosted: Wed Nov 11, 2015 7:16 pm     Reply with quote

CMatic wrote:
Therefore my conclusion is that sleep(); is working. Could you post your code so I can see how did you get 20.5uA? Thanks

I miss something ? Here we tolk about uA and in datasheet tolk about
• Sleep mode: 20 nA @ 1.8V, typical
• Watchdog Timer: 500 nA @ 1.8V, typical
• Timer1 Oscillator: 600 nA @ 32 kHz, 1.8V, typica

Even one timer consume less than 1/4 of 20uA.
Is a big difference between uA and nA .Realy i'm confused. Confused
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 8:06 pm     Reply with quote

16F1825 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/40001440E.pdf

Look at parameter D022, in the gray colored section. It shows the
sleep current is 20.5ua at 3.0v:

wangine



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

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

PostPosted: Wed Nov 11, 2015 8:29 pm     Reply with quote

Yup you're right , i did't notice the 20nA has refered on LF device. Now is cleared. Anyway i cant take entire guilt , i was looking on others data http://ww1.microchip.com/downloads/en/DeviceDoc/41440B.pdf and they can put on top page both LF and F devices on same field .
Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 1:37 am     Reply with quote

Unfortunately, variants of the 'F' versus 'LF' problem are very common.

A lot of threads here (and elsewhere on the web), have people trying to run processors at voltages below their rating, and then having problems. not realising that the minimum voltage allowed, is for the LF variant, not the F variant of the chip.
Similarly you get problems with clock speeds being selected that are illegal at the voltage/variant involved.
Then people expecting inputs to work at voltages again not legal for the variant.

Historically early Microchip data sheets tended to actually have separate sheets where the variant was significantly different. Now unfortunately there are even cases of the 'LF' variant actually being structurally different (things like some USB chips where the LF version does not have the internal regulator).

Does make it easy to get the wrong bit of data. I was suffering from it yesterday, when a customer called an asked a question, and I went leaping to the sheet, and could not actually find the paragraph giving the data for the variant involved. Hundreds of lots of data for every other version, but not the one I wanted.... Crying or Very sad
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 7:30 am     Reply with quote

PCM programmer wrote:
I used your posted code. I used a PicDem Lab board for this test, as
shown in the photo below. See the two red and black wires connecting
to the board ? Those two wires have the B&K ammeter leads attached to
them. The wires are connected to a both sides of a 2-pin header that
supplies power to the PIC. The jumper is placed AFTER the voltage
regulator. So the meter only measures current going to the PIC.


Thanks for posting this image and most importantly, showing me where to measure the current. I was measuring it before the regulator. On my breadboard, the lowest current I am getting is 90uA (still a lot better than 2.1mA). Also when I pulled the /MCLR high via a 2.2K resistor, the current dropped, so my question is, do I need to pull MCLR high even when I am using it as a IO pin?
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 7:34 am     Reply with quote

Ttelmah wrote:
As further comments, the circuit posted does not show how the power supply to the PIC is generated, or whether there is any decoupling close to the PIC. It also doesn't show anything pulling up MCLR.


Ttelmah I am using a 3.3V power regulator and there are two decoupling caps near the rails. I did not use a pull up resistor on MCLR because I am using it as an IO pin. My question is if I need to pull it up even when I am using it as IO.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 7:42 am     Reply with quote

wangine wrote:
You can't measure current when Pickit are connected, or any programmer you use, also like _Ttelmah_ say, your MCLR, should not be floating, any parasite current can often wakeup your PIC. Is same rule on pre declared input pins.
Code:



                    .---------------.
                    |               |                    VCC
            ___MCLR |               | RA0   ___           +
          -|10k|--o-o               o-----o|10k|o---------|
         |        | |               | RA1 |        ___    |
    VCC  -        | |               o--o--|------o|10k|o--o
     +   ^ D1     | |               |  |  |
     o---o        | |               |  |  |     _/
              _/  | |               |  |  o---o/  oo------o
         o--o/  o-o |               |  |                  |
         |          |               |  |        _/        |
        ===         |               |  o-----oo/  o-o-----|
        GND         '---------------'                     o
                                                         ===
                                                         GND



Thanks for the reply and the diagram. I am not measuring the current with Pickit3 connected to the circuit. And I do need to pull up the MCLR pin high as suggested.
alan



Joined: 12 Nov 2012
Posts: 358
Location: South Africa

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 7:42 am     Reply with quote

MCLR can normally only act as an input pin. A search here would reveal why you should never leave any input pin floating but make sure it has a logic level on it.

Regards
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 7:47 am     Reply with quote

alan wrote:
MCLR can normally only act as an input pin. A search here would reveal why you should never leave any input pin floating but make sure it has a logic level on it.

Regards


Alan thanks. I agree, now I am pulling it high with a 2.2K resistor and its working properly. I am checking the other inputs and will report my results. So far I have managed to reduce the current from 2.1mA to 90uA! but there is still a lot of current to reduce. Thanks again
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 8:22 am     Reply with quote

Lets add a little bit about MCLR.

MCLR, is a bit of a 'naughty pin'...

Problem is that because it has to go above Vdd to trigger programming, it cannot have any of the protection circuitry normally built into a pin. If as the chip is powered 'off', it is connected to a source that remains above Vdd as the supply rail drops, this can lead to it triggering a sort of 'half programming' mode, that can erase cells in the chip!.
I've seen this happen where people have attached an RC 'clear' circuit, and have not included a diode in the circuit (so the capacitor holds the pin up), or where it is driven by external circuitry, that 'just happens' to stay on for a moment after the PIC powers down.
On older PIC's the current needed for this to happen was high, so it was rare, and the voltage needed was also high. Some modern chips are very prone to problems from this, seeming to actually start erasing, if the pin goes only a couple of volts above Vdd.
For myself, if using it as an input, I add a protection diode external to the chip, or feed it from an 'open collector' drive with a pull-up, so there is nothing to try to take it above the rail (and the resistor provides a reasonably low impedance path for any spikes on the line).

It's a pin to 'treat with care'.

Just updated this to add a further comment.

You can also see 'why' if you want low power, assuming you are going to use a regulator, you need to be looking at super low quiescent regulators. Some people like Motorola do designs than go down into the low uA area....
wangine



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

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

PostPosted: Thu Nov 12, 2015 2:54 pm     Reply with quote

I don't refer strictly on a Pickit 2, 3, i say or other programmer is in. I don't think a programmer connected on circuit when you measure current can keep perfectly a float pin, i just suggest to detach. Like PCM_p say already your PIC is in sleep mode, you running at 16MHz internal, on 5Vcc = 1.58mA typical, you get 90uA, then.. is in sleep. Can take in consideration your ammeter, the common use multimeters the low limit is 1uA, even on some advanced multimeters is difficult in that current region, on my personal multimeter http://www.nilampt.com/pdf/Fluke%20289%20True-rms%20Industrial%20Logging%20Multimeter%20with%20TrendCapture.pdf if i need to measure, example: 430nA i get 0.4 uA on my meter and when i go to measure on my job with other really advanced ammeter i get 430.46nA. That's is a big difference. In other point, not any source in the world can be linear except battery, then any undetected spike can easily confuse your ammeter, also the length of wire, any parasite current can easy induce into leads and again confuse your ammeter. Personally i think everything is ok in your design.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 9:09 pm     Reply with quote

Ttelmah wrote:
Lets add a little bit about MCLR.

MCLR, is a bit of a 'naughty pin'...

Problem is that because it has to go above Vdd to trigger programming, it cannot have any of the protection circuitry normally built into a pin. If as the chip is powered 'off', it is connected to a source that remains above Vdd as the supply rail drops, this can lead to it triggering a sort of 'half programming' mode, that can erase cells in the chip!.
I've seen this happen where people have attached an RC 'clear' circuit, and have not included a diode in the circuit (so the capacitor holds the pin up), or where it is driven by external circuitry, that 'just happens' to stay on for a moment after the PIC powers down.
On older PIC's the current needed for this to happen was high, so it was rare, and the voltage needed was also high. Some modern chips are very prone to problems from this, seeming to actually start erasing, if the pin goes only a couple of volts above Vdd.
For myself, if using it as an input, I add a protection diode external to the chip, or feed it from an 'open collector' drive with a pull-up, so there is nothing to try to take it above the rail (and the resistor provides a reasonably low impedance path for any spikes on the line).

It's a pin to 'treat with care'.

Just updated this to add a further comment.

You can also see 'why' if you want low power, assuming you are going to use a regulator, you need to be looking at super low quiescent regulators. Some people like Motorola do designs than go down into the low uA area....


Ttelmah Your reply has enlightened me and I had never read this great of explanation about MCLR, really thanks so much. And I hope everyone on this forum reads it and take note of it. Especially how you described about cell’s being erased and using a diode to protect it. Could you please also suggest the super low uA regulator part number that I can use in my design.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 9:16 pm     Reply with quote

wangine wrote:
I don't refer strictly on a Pickit 2, 3, i say or other programmer is in. I don't think a programmer connected on circuit when you measure current can keep perfectly a float pin, i just suggest to detach. Like PCM_p say already your PIC is in sleep mode, you running at 16MHz internal, on 5Vcc = 1.58mA typical, you get 90uA, then.. is in sleep. Can take in consideration your ammeter, the common use multimeters the low limit is 1uA, even on some advanced multimeters is difficult in that current region, on my personal multimeter http://www.nilampt.com/pdf/Fluke%20289%20True-rms%20Industrial%20Logging%20Multimeter%20with%20TrendCapture.pdf if i need to measure, example: 430nA i get 0.4 uA on my meter and when i go to measure on my job with other really advanced ammeter i get 430.46nA. That's is a big difference. In other point, not any source in the world can be linear except battery, then any undetected spike can easily confuse your ammeter, also the length of wire, any parasite current can easy induce into leads and again confuse your ammeter. Personally i think everything is ok in your design.

wangine thank you again, your suggestion is on point regarding detaching the PicKit's, and thank you for posting the specs for Fluke 289, its true that my multimeter's scale is low resolution and may not be so accurate. Therefore I will look into purchasing a better ammeter. Best regards
wangine



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

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

PostPosted: Thu Nov 12, 2015 10:28 pm     Reply with quote

CMatic wrote:
Ttelmah Your reply has enlightened me and I had never read this great of explanation about MCLR, really thanks so much. And I hope everyone on this forum reads it and take note of it. Especially how you described about cell’s being erased and using a diode to protect it. Could you please also suggest the super low uA regulator part number that I can use in my design.

I notice that long time ago, _Ttelmah_ always is on the point , like other here, him want to say to avoid linear regulators if you want low uA, the problem of linear regulators , drop much current when the difference voltage between in/out is large. then better to use high efficiency converters topology (buck) , or (step_down) , some are designed on 99% + efficiency , sure about each developer can take entire day. Personally for my projects i get from here , is cheap and enough good to do the job. http://www.aliexpress.com/item/RC-Airplane-Module-Mini-360-DC-Buck-Converter-Step-Down-Module-4-75V-23V-to-1V/32404644438.html?spm=2114.01020208.3.21.zYFoOO&ws_ab_test=searchweb201556_1_21_79_78_77_92_91_22_80,searchweb201644_5,searchweb201560_9
or
http://www.aliexpress.com/item/Free-shipping-LM2596-Power-Module-DC-DC-Buck-Converter-Step-Down-Module-LM2596-High-Quality-Wholesale/32363769998.html?spm=2114.01020208.3.11.zYFoOO&ws_ab_test=searchweb201556_1_21_79_78_77_92_91_22_80,searchweb201644_5,searchweb201560_9
can search on google and you will find alot of informations about BUCK.
Good luck and don't forget to put SOLVED in your topic title
Wink
edit: I forgot to say, in the links is an adjustable model but to get more low uA drop try to search the fixed regulators, the adjustable use a divider resistors or pot and that can take some current, with fixed point like 5.0 the IC deal with internal reference.
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Fri Nov 13, 2015 2:06 am     Reply with quote

For a linear regulator, look at chips like the NCP702, LM2936, & the Motorola (On Semi now) 78LCxx. The latter is very nice, and has less tendency to oscillate when the load drops than many regulators. However still up at about a uA quiescent. It's worth putting things into perspective though. If you can get your total current down to just 10uA, then a pair of alkaline AA batteries can run it for about 10000 days!.... You are limited more by the shelf life of the battery, than by the power the circuit uses.
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 Previous  1, 2, 3  Next
Page 2 of 3

 
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