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

drawing 2mA doing nothing

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

drawing 2mA doing nothing
PostPosted: Tue Feb 14, 2006 3:32 pm     Reply with quote

I'm using a 16F688 part and am having some issues getting the power consumption down when it is running, but not necessarily doing anything. I have a 10 sec delay and during that time it is drawing 2mA. The wierd thing is, that I have some chips that I programmed a couple of weeks ago (exact same hardware slightly different code) that are drawing a few hundred uA. I did a diff on the two versions and didn't see anything that should cause the change in current.

I am using a 32kHz crystal for Timer1 and 500kHz internal oscillator. I've shut everything off that I am not using and looked over the fuses a number of times with no luck seeing what I am doing wrong.

Any extra set of eyes would be helpful.

Thanks,

jspencer



Code:

#include <16F688.h>
#use delay(clock=500000)

// Will need to change to code protect
#fuses INTRC_IO
#fuses NOWDT
#fuses PROTECT
//#fuses NOPROTECT
#fuses NOMCLR
#fuses NOCPD
#fuses NOBROWNOUT
#fuses PUT
#fuses NOIESO
#fuses NOFCMEN

// External interrupt routine.  PIN_A2 is the I/O line and is used for
// activation of the device
#int_EXT
EXT_isr() {
   z = 0;

   // This is bad and will need to be changed, but functional for now.
   for (y=0;y<50;y++) {
      if (input(PIN_A2)) {
         z++;
         if (z > 20) {
            activated_flag = TRUE;
            break;
         }
         delay_ms(5);
      }
   }
}

// Timer1 interrupt routine.  Used for sleeping X amount of time and for
// counting how much time has elapsed while processing.
#int_TIMER1
TIMER1_isr() {

}

void main() {
   init_routine();
// do rest of program.

}


void init_routine() {
   int i_cnt;
   // initialization of features

   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_8|T1_CLK_OUT);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_wdt(WDT_OFF);
   setup_adc(ADC_OFF);
   setup_adc_ports(NO_ANALOGS);
   setup_oscillator(OSC_500KHZ);
   port_a_pullups(FALSE);
   //setup_low_volt_detect(FALSE);

   init_ext_eeprom();
   TCN75_init();
   setup_one_shot();

   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT);
   enable_interrupts(global);
   // Sets up INT_EXT to watch for the rising edge
   ext_int_edge(L_TO_H);

   SET_TRIS_A(0x04);
   // A0    OUTPUT
   // A1    OUTPUT
   // A2    INPUT
   // A3    OUTPUT
   // A4    OUTPUT
   // A5    OUTPUT

   SET_TRIS_C(0x00);
   // C0    OUTPUT
   // C1    OUTPUT
   // C2    OUTPUT
   // C3    OUTPUT
   // C4    OUTPUT
   // C5    OUTPUT

   // initial flashing sequence
   for (i_cnt=0; i_cnt<2; i_cnt++) {
      flash(0x04, 5);
      delay_ms(150);
      flash(0x02, 5);
      delay_ms(150);
      flash(0x01, 5);
      delay_ms(150);
   }
   // reading 2mA during this delay.
   delay_ms(10000);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 3:51 pm     Reply with quote

1. Is this for the PIC only, or the entire board ?

2. Is there a voltage regulator ? If so, what is the part number ?

3. Are all i/o pins set to a state such that no power will be drawn
by external circuits ? i.e., if you have a pull-up resistor on
a pin, set the pin to be an input, or a high-level output.
Don't set it to be a low-level output.

4. You've got a flashing routine in there. I would remove that
code for this test. Who knows what state those pins are left in ?

5. You're ending the code with a 10 second delay. As soon as the
delay ends, the PIC will execute a hidden SLEEP instruction
(put there by the compiler) and go to sleep.
I think you should either explicitly test it in sleep mode, or
test it in non-sleep mode. The test should not have a temporary
delay.

Either put this at the end of main():
Code:

  sleep();


or this:
Code:

  while(1);
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 4:09 pm     Reply with quote

I only cut and pasted part of the code, so there is quite a bit that is not shown.

Quote:

1. Is this for the PIC only, or the entire board ?


It is for the entire board, but the other components when not in use are only drawing 6-7 uA and when in use it is really low.
Quote:


2. Is there a voltage regulator ? If so, what is the part number ?


There is no regulator, we are using a 3V coin cell.
Quote:


3. Are all i/o pins set to a state such that no power will be drawn
by external circuits ? i.e., if you have a pull-up resistor on
a pin, set the pin to be an input, or a high-level output.
Don't set it to be a low-level output.


Only have one pull-up and it is a input.
Quote:


4. You've got a flashing routine in there. I would remove that
code for this test. Who knows what state those pins are left in ?


The flashing routine always leaves the output pins in a low state, but this maybe where my problem is, as i have leds on 3 output pins on the port, but I just noticed that I am doing this: ouput_c(0x07) to flash all leds on the port, but it is also setting the other port pins to a low state.
Quote:


5. You're ending the code with a 10 second delay. As soon as the
delay ends, the PIC will execute a hidden SLEEP instruction
(put there by the compiler) and go to sleep.
I think you should either explicitly test it in sleep mode, or
test it in non-sleep mode. The test should not have a temporary
delay.

Either put this at the end of main():
Code:

  sleep();


or this:
Code:

  while(1);


Again, just didn't paste all of the code, my bad. I do have a never ending while loop in main. In sleep mode I am drawing between 10 and 20 uA which is where I need to be.

I'll try the output thing, as that is one thing that I did change between revisions. I'm pretty sure that this is the problem.

Thanks for the extra eyes!

jspencer
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 5:42 pm     Reply with quote

Well, I've reduced it to this.

Code:

#include <16F688.h>

#use delay(clock=500000)

// Will need to change to code protect
#fuses INTRC_IO
#fuses NOWDT
#fuses PROTECT
//#fuses NOPROTECT
#fuses NOMCLR
#fuses NOCPD
#fuses NOBROWNOUT
#fuses PUT
#fuses NOIESO
#fuses NOFCMEN

//********************************************************************
// VARIABLE DECLARATIONS/INITIALIZATION
//********************************************************************

// loop counter variable
int i, x, y, z;


short ut1_flag = FALSE;
short ot1_flag = FALSE;
short b4_alert_flag = FALSE;
short memory_full_flag = FALSE;
short activated_flag = FALSE;
short tti_flag = FALSE;



//********************************************************************
// INTERRUPT SERVICE ROUTINES
//********************************************************************

// External interrupt routine.  PIN_A2 is the I/O line and is used for
// activation of the device
#int_EXT
EXT_isr() {
   z = 0;
   for (y=0;y<50;y++) {
      if (input(PIN_A2)) {
         z++;
         if (z > 20) {
            activated_flag = TRUE;
            break;
         }
         delay_ms(5);
      }
   }
}

// Timer1 interrupt routine.  Used for sleeping X amount of time and for
// counting how much time has elapsed while processing.
#int_TIMER1
TIMER1_isr() {

}

//********************************************************************
// Function that initializes the PIC and takes care of all the house
// keeping and setup
// Parameters: 0
// @ returns - nothing
//********************************************************************

void init_routine() {
   int i_cnt;
   // initialization of features

   //setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_8|T1_CLK_OUT);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_wdt(WDT_OFF);
   setup_adc(ADC_OFF);
   setup_adc_ports(NO_ANALOGS);
   setup_oscillator(OSC_500KHZ);
   port_a_pullups(FALSE);

   //SET_TRIS_A(0x04);
   //SET_TRIS_C(0x00);

   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT);
   enable_interrupts(global);
   // Sets up INT_EXT to watch for the rising edge
   ext_int_edge(L_TO_H);

}

//********************************************************************
// Main function
//********************************************************************

void main() {

   // initialization of all the PIC features that are needed
   init_routine();
   while (1) {
      output_high(PIN_C0);
      delay_ms(200);
      output_low(PIN_C0);
      delay_ms(3000);
   }
}


Now this will work and draw only 200uA, but if I uncomment the SET_TRIS_A(0x04) and the SET_TRIS_C(0x00) statements the circuit draws 2mA.


EDIT***
There is something flaky going on as now it will work just fine. Getting stumped as to the issue.
***

Thanks,
jspencer
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Wed Feb 15, 2006 3:56 pm     Reply with quote

Well, it was the output_c() call that I was making. The I2C lines are also on that port and I don't think it liked that much.
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