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

low current consumption problem

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



Joined: 04 Jun 2008
Posts: 23

View user's profile Send private message

low current consumption problem
PostPosted: Tue Sep 27, 2011 1:35 pm     Reply with quote

Hello!
I tried to reduce the power consumption on 16f1939 microcontroller.
First I tried to use sleep function and wake-up using interrupt on change on falling edge:
Code:

#BYTE INTCON = 0x00B
#BIT GIE = INTCON.7
#BIT IOCIE = INTCON.3
#BIT IOCIF = INTCON.0

#BYTE IOCBN = 0x395
#BIT IOCBN3 = IOCBN.3
#BIT IOCBN2 = IOCBN.2
#BIT IOCBN1 = IOCBN.1
#BIT IOCBN0 = IOCBN.0

#BYTE IOCBF = 0x396
#BIT IOCBF3 = IOCBF.3
#BIT IOCBF2 = IOCBF.2
#BIT IOCBF1 = IOCBF.1
#BIT IOCBF0 = IOCBF.0

#define ROW1        PORTB0   //digital input
#define ROW2        PORTB1   //digital input
#define ROW3        PORTB2   //digital input
#define ROW4        PORTB3   //digital input

     
   IOCBN3 = 1;IOCBN2 = 1;IOCBN1 = 1;IOCBN0 = 1;//activate falling                     //edge

the program was:
   while(1)
  {
         if (timer_unpressed == 100)
         {
            sleep_flag = 1;
            IOCIE = 1;//activate interrupt on change
            sleep();
         }
    if (sleep_flag)
         if((!ROW1) || (!ROW2) || (!ROW3) || (!ROW4))
         {
            unpressed_tmr = 0;
            sleep_flag = 0;//go out of sleep
         }
   if(!sleep_flag)
   {
    //.... program functions - writing to a I2c rheostat
   }

After entering on sleep if I press a key of row1..4 is doing reset.

-----------------------------------------------------------------------------
A second way was to reduce the internal clock speed from 4 MHz to 32KHz:
Code:

      if(sleep_flag)
      { 
         if((!ROW1) || (!ROW2) || (!ROW3) || (!ROW4))
         {
            #use delay(int=4000000)
         }
      }     
      if (unpressed_tmr > 100 && (!sleep_flag))  //
      {
         sleep_flag = 1;
         #use delay(int=32000)         
      }

but the consumption is not decrease. I think that is not go to low speed clock.

Can anyone help me?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 2:06 pm     Reply with quote

Quote:
A second way was to reduce the internal clock speed from 4 MHz to 32KHz:

if(sleep_flag)
{
if((!ROW1) || (!ROW2) || (!ROW3) || (!ROW4))
{
#use delay(int=4000000)
}
}
if (unpressed_tmr > 100 && (!sleep_flag)) //
{
sleep_flag = 1;
#use delay(int=32000)
}


but the consumption is not decrease. I think that is not go to low speed clock.

Putting #use delay() statements in the middle of the program does not
generate code to change the internal oscillator frequency. You need to
use the setup_oscillator() function to do that.

The #use delay() statement only tells the CCS compiler what the current
oscillator frequency is.

Also, #use delay() only affects code that occurs after the #use delay()
statement in the file. (Going from top to bottom in the file).
If your program jumps back up to an earlier line in the file, then it delays
such as delay_us(), will run at the rate of the previous #use delay()
statement.

This thread has sample code for switching oscillator frequencies and
setting #use delay():
http://www.ccsinfo.com/forum/viewtopic.php?t=32758
lboghy



Joined: 04 Jun 2008
Posts: 23

View user's profile Send private message

Problem solved
PostPosted: Wed Sep 28, 2011 2:26 pm     Reply with quote

Dear PCM,
Thank you for your prompt response.
Is working, the power consumption is less 40 times using low oscillator frequnecy.
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