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

Questions about SLEEP();[SOLVED]

 
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

Questions about SLEEP();[SOLVED]
PostPosted: Mon Nov 16, 2015 7:53 pm     Reply with quote

Hello Guys,
I am still working on my project. It is working fine, However after further analyses, I found out that the current during the sleep mode is not stable.
The Min is 2.67 uA
The average is 3.43 uA
The Max is 42.04 uA spikes every ~5 seconds. normal around 5.33uA

When everything is running the current is 19.89mA to 19.93mA

My processor is the 18F2685. It uses Timer 1 (with external 32768 crystal) to generate the 1 second, Timer 2 to manage the 8X 7 segments to display time. INT_RB to manage the push button.
All the common on the displays are managed by transistors connected to
C2, C3, C4, C5, C6, C7, B0 and B1 via 4K7
Port A manage the segments via 330 ohms resisters.
MCLR input pulled up via 10k and diode.
B2, B3, B4 and B5 inputs pulled up via 10k.
B6 and B7 floats but I set them as output and low.
I am using .1 uf decoupling capacitor and 47uf/35v bypass capacitor
I followed all microchip guide lines as far as the crystal circuit.

I am driving the processor with 5 v and it is stable.

This is my header and fuses

Code:
#include <18f2685.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT
#use fast_io(b)


and this is my main
Code:
void main()
{
   
   /* Use the internal oscillator block which provides an
      8 MHz clock (±2% accuracy) */
   setup_oscillator(OSC_8MHZ);
   
   /* Use Timer1 external oscillator which provides an
      32768Hz clock */
   setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);
   
   
   RD16 = 0; // Modify T1CON setup to allow r/w of TMR1H
   

   /* Use Timer2 to generate 1mS tick to manage the displays */
   setup_timer_2(T2_DIV_BY_16,124,1);

   set_timer1(0x8000);  // This makes T1 interrupt in 1 second

 
   clear_interrupt(INT_TIMER1);
   
   clear_delta();
   
   /* Use to manage the port B interrupt on pin 4 and 5 only as */
   /* The example EX_PBUTT.C */
   enable_interrupts(INT_RB);
   
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
     
   output_low(PIN_B6);  /* Pin is floating and used for ICSP only! */
   output_low(PIN_B7);  /* Pin is floating and used for ICSP only! */
   
 
   while(true)
   {
   if(dbutton4) {
        ++hour;
        tosleep = 10;
        if (hour == 24)
            {
               hour=0;
            }
        dbutton4=FALSE;
      }
      if(dbutton5) {
        ++minute;
        tosleep = 10;
        if (minute == 60)
            {
               minute=0;
            }
        dbutton5=FALSE;
      }
      if(tosleep == 0)
      {
         output_low(PIN_C2); /* Digit 1 comm */
         output_low(PIN_C3); /* Digit 2 comm */
         output_low(PIN_C4); /* Digit 3 comm */
         output_low(PIN_C5); /* Digit 4 comm */
         output_low(PIN_C6); /* Digit 5 comm */
         output_low(PIN_C7); /* Digit 6 comm */
         output_low(PIN_B0); /* Digit 7 comm */
         output_low(PIN_B1); /* Digit 8 comm */
         output_low(PIN_B6); /* Pin is floating and used for ICSP only! */
         output_low(PIN_B7); /* Pin is floating and used for ICSP only! */
         output_A(0x00);     /* 7 Segments */
         sleep();
         delay_cycles(1);
      }
   }
}


I am using 60mHz oscilloscope and Fluke 189 to measure and monitor what is going on.
I want to note that I am using #use fast_io(b) for port b because I set the trisb to 0X3C to make the interrupt work as per the example.

Is my current reading normal or do I need to do something? I just want my Timer1 and the interrupt on port B and the global variables to keep updating and I want everything else to turn off. My understanding is SLEEP(); instruction will take care of that?

Thanks,


Last edited by Sam_40 on Sun Nov 22, 2015 10:04 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Questions about SLEEP();
PostPosted: Mon Nov 16, 2015 11:19 pm     Reply with quote

Sam_40 wrote:

The Min is 2.67 uA
The average is 3.43 uA
The Max is 42.04 uA spikes every ~5 seconds. normal around 5.33uA

Based on this, we would be looking for something in your code that
happens every 5 seconds. But you didn't show the interrupt routines
or the #use delay() statement. A small complete test program, not code
snippets, would be the most help.
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Tue Nov 17, 2015 8:08 am     Reply with quote

Good morning PCM,
I have nothing in my code that happen around when it spikes. I also have nothing that happen every 5 sec. I did not post the complete code because I believe it is against the forum rule as I am using part of the CCS examples code!
Basically what I have is:
Timer1: interrupt to advance sec, min, hr and to check if tosleep is greater than 0 then it would tosleep. I am using your code that you provided me in the past and I just added the sec++, min++, hr++ and if tosleep > 0 then tosleep--.
Timer2: Only handle the displays using a simple math of % and / to display the time when the PIC is running.
INT_RB: to handle the button press as per CCS example "ex_pbutt.c" the only thing that is different is I added the use fast IO as per manual.
I can post the complete code however my understanding it is against the forum. Or I can PM you the complete code only if it is OK with you. Do you see any problem with my main?
Thanks,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 17, 2015 11:06 am     Reply with quote

My advice is to start stripping out sections of your code and see if you
continue to get the current spiking during sleep. Also remove pieces of
the hardware.

Eventually you may get it down to a program that consists of putting all
the pins in a low power state, and then executing a sleep statement, with
while(TRUE); at the end.

At that point, I would look at:
1. Changing the PIC.
2. Changing to a different PIC family.
3. Changing the power supply, board, etc.
4. Changing your ammeter to a different one.

Somewhere, there is something with a 5-second timer on it. It could be
an RC time constant in your meter, on the low microamp scale.
But by stripping down the program and the hardware, and changing it too,
you will eventually come up with an answer.
Eugeneo



Joined: 30 Aug 2005
Posts: 155
Location: Calgary, AB

View user's profile Send private message

PostPosted: Tue Nov 17, 2015 12:07 pm     Reply with quote

I would reduce the bulk capacitance then connect a resistor inline and scope the surge. Maybe the duration and type of the surge will tell you something.
temtronic



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

View user's profile Send private message

PostPosted: Tue Nov 17, 2015 2:31 pm     Reply with quote

really we need to see a small program that has the same problem. That 'magical' 5 seconds is interesting.
It could be an analog comparator tripping due to it's input not being terminated. Maybe an ADC pin is 'confused'.
Without seeing the whole program or best a small, cut down one that has the problem we can only guess....

Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Tue Nov 17, 2015 4:12 pm     Reply with quote

Guys,
Thanks for the reply, I did what you guys advised. The problem I believe is when I am using the "#use fast_io(b)" and "set_tris_b( the hex value of IOs);". If I comment those 2, this is what I get:
Min 0.08uA
Avg 0.18 uA
Max 0.26uA
Using the MIN/MAX on the ammeter! study no spike with this test code:

Code:
#include <18f2685.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT


void main()
{
   setup_oscillator(OSC_8MHZ);

   while(true)
   {
   output_low(PIN_C0); /* TO TEST */
   output_low(PIN_C1); /* TO TEST */
   output_low(PIN_C2); /* Digit 1 comm */
   output_low(PIN_C3); /* Digit 2 comm */
   output_low(PIN_C4); /* Digit 3 comm */
   output_low(PIN_C5); /* Digit 4 comm */
   output_low(PIN_C6); /* Digit 5 comm */
   output_low(PIN_C7); /* Digit 6 comm */
   output_low(PIN_B0); /* Digit 7 comm */
   output_low(PIN_B1); /* Digit 8 comm */
   output_low(PIN_B6); /* Pin is floating and used for ICSP only! */
   output_low(PIN_B7); /* Pin is floating and used for ICSP only! */
   output_A(0x00);     /* 7 Segments */
 
   sleep();
   delay_cycles(1);
   }
}

If I use "#use fast_io(b)" and "set_tris_b();" My reading will be higher and I see a spike every about 5 seconds. I may miss something in the datasheet? Do I have to manually disable other features that I am not using or do the compiler do it?
Same thing happen on a different processor with the same part number!

I think Jay is on the right track Wink maybe when using the fast IO something else happen? That is over my head Very Happy I may have to change the RB4-RB5 interrupt code to not use the fast IO and the set tris and see. However if you guys have more suggestions please let me know so I can try them.

Thanks,
temtronic



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

View user's profile Send private message

PostPosted: Tue Nov 17, 2015 6:26 pm     Reply with quote

OK silly question but do you have the programmer or an ICD unit attached to the PIC ? Or is it just the PIC,power supply and the measurement equipment?

Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Tue Nov 17, 2015 6:45 pm     Reply with quote

I am using PICKIT3, When it is connected it draw an additional about 5mA. I only take the measurements for the PIC, pull up resister(if any), capacitors(if any), the crystal on timer1(it only requires .1uW) I also have 220k "Serial Resistor" as recommended by this but for the timer 1 "http://ww1.microchip.com/downloads/en/AppNotes/91097A.pdf". I am taking the reading between the power supply and the above. I do not read the power that the PS draw.
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