Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC16F88 won't go to sleep

Status
Not open for further replies.

brew

Member level 3
Joined
Mar 4, 2011
Messages
59
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,693
hi, i am trying to put PIC16F88 to sleep but it just won't sleep. i am using a ccx5 compiler by bknd. the controller should sleep when there's an external interrupt on RB0/INT.


#define light PORTA.0

interrupt intHandler(void) //ISR, functions that handle interrupts
{
TMR1ON = 0;
INTCON = 0x00;
GIE = 0;
PEIE = 0;
INT0IE = 0;
TMR1IE = 0;
TMR1IF = 0;
TRISA = 0x11;
TRISB = 0x11;
PR1 = 0x00;

sleep();
nop();
light = 0;
}

void main()
{
initPic(); //initializes PIC TRISA,PORTA,TRISB,PORTB,OSCCON, etc.
light = 1;


}

i tried to turn off all of the possible interrupts and clear their flag bits, but still my controller doesn't want to sleep? i need your help! thanks!

regards, brew.
 

Hi!
In initPic() procedure you make the interrupt enable?

and after light=1 you need to put the pic to running a infinite loop!

light=1;
sleep();

while(1)
{
}
 

Hi!
In initPic() procedure you make the interrupt enable?

and after light=1 you need to put the pic to running a infinite loop!

light=1;
sleep();

while(1)
{
}

hi pmar_kpj,thanks for the reply.

i did enable some interrupt in the initPic() function;GIE,PEIE and INT0IE.
in my ISR function which is interrupt intHandler(), i disabled all the interrupts i enabled during the initPic() function. Also, i cleared all the flag bits that correspond to the interrupts i enabled.

light=1;
sleep();

while(1)
{
}

is this code inside the main program? why did you put the sleep() function inside the main function, this will just put the PIC on sleep if main program is executed. what i want to happen is, the pic should go to sleep when there is an interrupt. and another thing, what is the while(1) code for? thanks, sorry if i have a lot of questions. please bare with me. Thanks!

regards, brew
 

hi!

Your program executes "light = 1;" and finished. Nothing else to execute!

So I put that infinite loop for the application to be always active!
 

hi!

what about the sleep function inside the main program before the infinite loop? what does it do?

regards, brew.
 

If it's any help here's the sleep function I've used for the 16F88:


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
procedure sleep_seconds( byte in x ) is
        var byte local_wdtcon
        var byte local_option
        
        -- make a copy of OPTION
        bank_1
        asm MOVF OPTION_REG, W
        bank_0
        asm MOVWF local_option
        
        -- make a copy of WDTCON
        bank_2
        asm MOVF WDTCON, W
        bank_0
        asm MOVWF local_wdtcon
        
        -- setup OPTION prescaler
        bank_1
        asm bcf OPTION_REG, 0
        asm bcf OPTION_REG, 1
        asm bcf OPTION_REG, 2
        asm bsf OPTION_REG, 3
        -- setup WDTCON prescaler
        bank_2
        WDTCON = 0b_0001_0100
        bank_0
        
        for x loop
                bank_2
                asm bsf WDTCON, 0
                asm clrwdt
                asm sleep
                asm bcf WDTCON, 0
                bank_0
        end loop
        
        -- restore OPTION
        asm MOVF local_option, W
        bank_1
        asm MOVWF OPTION_REG
        bank_0
        
        -- restore WDTCON
        asm MOVF local_wdtcon, W
        bank_2
        asm MOVWF WDTCON
        bank_0
        
end procedure

 

hi !
after initialization is required to enter sleep?
so call sleep function!
 

Hi! thanks for the replies. i did what you guys suggested but i can't seem to make it work. why i try to make an interrupt, the least current consumption that it can come up with is 900uA. the datasheet the sleep current should be around .1uA. i'm still not losing hope.i'l still trying to alter some of my codes. if you have any more suggestions, please please please send them to me.

regards, brew.
 

Hi guys. FINALLY!!!! i've done it!! i used mikroC to compile my code and it's working! i set the timer to sleep after 10 mins, also when RB0 interrupt has been triggered, the pic will also sleep. i'll post the code hoping to help other pic newbies like me.

int timercounter = 0;

void interrupt(void)
{

if(PIR1.B0) //TMR1 interrupt
{
PORTA.B0 = 0;
timercounter++;
PIR1.B0 = 0;
}
else if(INTCON.B1) // interrupt flag on RB0
{
PORTA.B0 = 0;
asm sleep
//INTCON.B1 = 0;
}


}

void main()
{
INTCON.GIE = 1; //enables global interrupt
INTCON.PEIE = 1; //enables peripheral interrupt
INTCON.B4 = 1; // interrupt on RBO is enabled
OPTION_REG.INTEDG = 1; //interrupts on rising RB0
OSCCON = 0x70; //oscillator = 8Mhz, HS
T1CON.B1 = 0; //timer1 clock source is FOSC/4
T1CON.B3 = 0; //timer1 oscillator shut off to eliminate power drain
T1CON.B4 = 1;
T1CON.B5 = 1; //prescalar value = 1:8
T1CON.B0 = 1; //enables interrupt
PIE1.B0 = 1; //enables TMR1 interrupt

PORTA = 0x00;
PORTB = 0x00;
TRISB.B0 = 1;
TRISA = 0xFE;


while(1)
{
PORTA.B0 = 1;
if(timercounter == 2268) //time to sleep = 10 mins, actual timing = 9:58
{
asm sleep
}
}


}

regard, brew.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top