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 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
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

sleep() not working
PostPosted: Tue Nov 10, 2015 8:56 am     Reply with quote

Compiler 5.026
Pic16F1825 at 16Mhz running with Internal Osc

The program seem never to execute sleep(); instruction. Its a very simple program but somehow, it will not execute sleep. I am scratching my head Mad Thanks for your comments and ideas.

Here is the code
Code:

#include <16F1825.h>

#FUSES NOCLKOUT      //I/O function on OSC2
#FUSES NOWDT         //Watch dog timer
#FUSES INTRC_IO      //Internal RC Osc
#FUSES NOPROTECT     //Code Protection
#FUSES NOBROWNOUT    //Brown-out
#FUSES NOCPD         //Data Protection
#FUSES NOFCMEN       //Fail-Safe Clock Monitor Enable Bit
#FUSES NOIESO        //Internal External Switchover bit
#FUSES NOPUT         //Power Up Timer
#FUSES NOMCLR        //Memory Clear
#FUSES NOWRT         //No Program Memory write Protected
#FUSES STVREN        //No Stak full/underflow reset
#FUSES NODEBUG       // No Debug mode for ICD
#FUSES NOLVP         //No Low Voltage Programming

#use delay(internal=16000000)
#include <stdio.h>


//////////////////////////////////////////////////////////
//                                                      //
//                  PROTOTYPES                          //
//                                                      //
//////////////////////////////////////////////////////////
void Init_eeprom();
void Init_interrupts();

//////////////////////////////////////////////////////////
//                                                      //
//                  DEFINES / VARIABLES                 //
//                                                      //
//////////////////////////////////////////////////////////

#define ALM PIN_C0 // Alarm Red LED




//////////////////////////////////////////////////////////
//                                                      //
//                  MAIN PROGRAM                        //
//                                                      //
//////////////////////////////////////////////////////////


void main() {
       
     output_toggle(ALM);
     delay_ms(1000);
       
     sleep(); //goto sleep
     delay_cycles(1);//You need to have this NOP instruction as
                      //sleep prefetches next instruction
     while(TRUE) {
 
     }
   
}// Main
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 10, 2015 10:56 am     Reply with quote

How are you testing whether or not the PIC is in sleep mode ?
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Tue Nov 10, 2015 9:14 pm     Reply with quote

PCM programmer wrote:
How are you testing whether or not the PIC is in sleep mode ?


Thanks for your reply. I am measuring the current and it is drawing 2.5mA which I think is a lot. Also when the LED is lit alternatively, the current is 21.7mA. So I am thinking that the circuit is not in sleep mode?
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: Tue Nov 10, 2015 9:28 pm     Reply with quote

Forget the LED, just blink one time to be sure PIC is _alive_ , after put sleep on and measure the current , look first page on datasheet Sleep mode: 20 nA @ 1.8V, typical. What need to complicate more your measurement with that _led_. Anyway to measure a nA value is not really easy without a precise device.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 10, 2015 9:47 pm     Reply with quote

Are you using a voltage regulator ? If so, they often have a considerable
quiescent current, even if the load current is zero.

Post the details of your hardware test setup.
I have a 16F1825 and can duplicate your test setup if necessary.
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: Tue Nov 10, 2015 10:07 pm     Reply with quote

Also can be considered
Code:
struct  {
   unsigned int PD:1;
   unsigned int TO:1;
} STATUS;
#byte STATUS = 0x003

no WDT ,
Code:
STATUS.TO = true;
STATUS.PD = false;

Look at page 26 in datasheet, processor should sleep.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Tue Nov 10, 2015 10:32 pm     Reply with quote

PCM programmer wrote:
Are you using a voltage regulator ? If so, they often have a considerable
quiescent current, even if the load current is zero.

Post the details of your hardware test setup.
I have a 16F1825 and can duplicate your test setup if necessary.


I did not realize that I can not post a picture, so now I am looking to host it on a site where I can then load the circuit diagram and then link to it. I will post it asap.
This is the circuit setup


[img]https://www.flickr.com/photos/137717282@N05/22921743172[/img]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 1:14 am     Reply with quote

Your image hosting website requires a login. Please re-post your image
on an open image host. Example:
http://postimage.org/
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 6:21 am     Reply with quote

PCM programmer wrote:
Your image hosting website requires a login. Please re-post your image
on an open image host. Example:
http://postimage.org/


my apologies here is the image
[img]http://postimg.org/image/r4u8n4yw9/[/img]
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 7:18 am     Reply with quote

wangine wrote:
Also can be considered
Code:
struct  {
   unsigned int PD:1;
   unsigned int TO:1;
} STATUS;
#byte STATUS = 0x003

no WDT ,
Code:
STATUS.TO = true;
STATUS.PD = false;

Look at page 26 in datasheet, processor should sleep.


Thanks for reply. There is no WDT. I have added the STATUS struct above and I am checking the TO and PD bits. But still the circuit is showing 2.9 mA
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 9:03 am     Reply with quote

Your code will turn on the LED and then go to sleep. The LED remains on
in sleep. Sleep mode does not make the PIC's i/o pins go to high-Z state.
This may be the source of your whole problem.

Also, the programmer must be disconnected from the board before you
measure the sleep current (or any current). For example, if my Pickit3
is plugged into the board, the ammeter shows 3.8ma.

If I disconnect the LED and the Pickit3, I get 20.5 micro-amps, which is
what the 16F1825 data sheet says I should get.

I'm running the PIC at 3.3v and I'm using CCS compiler vs. 5.051.
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 9:59 am     Reply with quote

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.
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 4:04 pm     Reply with quote

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

CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 5:57 pm     Reply with quote

PCM programmer wrote:
Your code will turn on the LED and then go to sleep. The LED remains on
in sleep. Sleep mode does not make the PIC's i/o pins go to high-Z state.
This may be the source of your whole problem.

Also, the programmer must be disconnected from the board before you
measure the sleep current (or any current). For example, if my Pickit3
is plugged into the board, the ammeter shows 3.8ma.

If I disconnect the LED and the Pickit3, I get 20.5 micro-amps, which is
what the 16F1825 data sheet says I should get.

I'm running the PIC at 3.3v and I'm using CCS compiler vs. 5.051.


PCM programmer thanks for your reply. And after trying all the suggestions (removing Pickit3 and turning off LED) my board is still drawing 2.8mA.
I then made a separate breadboard however, I only had a 5V regulator, so now I am drawing 3.1mA. My guess is that its the 5V reg that is drawing so much current from the battery and not the uController. Therefore my conclusion is that sleep(); is working. Could you post your code so I can see how did you get 20.5uA? Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 11, 2015 6:35 pm     Reply with quote

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.
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, 3  Next
Page 1 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