WinPicProg Forums Forum Index WinPicProg Forums
A forum to support WinPicProg
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sleep mode in PIC16F877

 
Post new topic   Reply to topic    WinPicProg Forums Forum Index -> Questions
View previous topic :: View next topic  
Author Message
micael



Joined: 31 Jul 2006
Posts: 4

PostPosted: Tue Aug 01, 2006 10:17 pm    Post subject: Sleep mode in PIC16F877 Reply with quote

Hi,
Im trying to detect a signal at 433.92MHz from an RRFQ1 receiver( pin13) wich is connected to RB0 pin of PIC16F877. To save power PIC16F877 is set to sleep mode to wake up only when there is a signal at 433.92MHz.

Has anyone done something with sleep mode before? is this the way to wake the PIC using interrupts?(attached program)


//(ID:821401) (PN:1033143)//
#pragma bit RB0 @ 6.0
#pragma bit RB1 @ 6.1
#pragma bit RB2 @ 6.2
#pragma bit RB3 @ 6.3
#pragma bit RB4 @ 6.4
#pragma bit RB5 @ 6.5
#pragma bit RB6 @ 6.6
#pragma bit RB7 @ 6.7

char stim,state;


void initialize()
{
OPTION_REG = 0xff; /*external interrupt i/p pin configured*/
/*using(OPTION_REG<6>)*/
STATUS = 0x3f; /* bank 1 */
TRISB=0b11000001; /*SET RB0=1 to input,RB0=0 output */
STATUS = 0x1f; /* bank 0 */

}


//DELAYS//
void delay_us(int dtime)
{
int a;
for (a=0; a<dtime; a++)
{
nop();
nop();
nop();
nop();
}
}


void delay_ms(int Michalis) //delay upto 200 ms//
{
int c,d;
c = 0;
while (c<=Michalis)
{
d = 0;
while (d<=4)
{
delay_us(200);
delay_us(200);
delay_us(200);
delay_us(200);
delay_us(200);
d++;
}
c++;
}
}

void delay_s (int p) //delay upto 200 s//
{
int c,d;
c = 0;
while (c<=p)
{
d = 0;
while (d<=2)
{
delay_ms(100);
d++;
}
c++;
}
}


void sanity_flasher(int flasher) //LED connected at RB1 pin//
{
char c;
c = 1;
RB1 = 0;
while (c<=flasher)
{
RB1 = 1;
delay_s(1);
RB1 =0;
delay_s(1);
c++;
}
}


// read the input//
void read_stimulus()
{

stim=PORTB;
if (RB2==1) //WAKE UP//
sanity_flasher(5); /*flash LED 3 times*/

}
void main()
{
initialize();
sanity_flasher(1);

while(1) // run forever//
{

read_stimulus(); //read input//
while(RB2!=1)
{
sleep();
}

}/*END WHILE */
}/*END main */
Back to top
View user's profile Send private message
KC



Joined: 05 May 2006
Posts: 99
Location: Victoria BC Canada

PostPosted: Wed Aug 02, 2006 3:48 am    Post subject: Reply with quote

If you don't set the GIE bit in the INTCON REGISTER then the PIC will just wake up and start executing the instruction following the sleep intruction. This seems to be the way your code is setup. But it looks like you forgot to set the INTE bit in the INTCON register. See excerpt from manual below:

This interrupt can be disabled by
clearing enable bit INTE (INTCON<4>). Flag bit INTF
must be cleared in software in the interrupt service routine
before re-enabling this interrupt. The INT interrupt
can wake-up the processor from SLEEP, if bit INTE was
set prior to going into SLEEP. The status of global interrupt
enable bit GIE decides whether or not the processor
branches to the interrupt vector following wake-up.

_________________
KC
Back to top
View user's profile Send private message
micael



Joined: 31 Jul 2006
Posts: 4

PostPosted: Thu Aug 03, 2006 3:35 pm    Post subject: PIC18F452 sleep Reply with quote

Hi,
Is this the way to wake up PIC18F452 using an external interrupt at RBO?

//ID:821401, PN:1033143 ,UMO//

#include "p18f452.h"
#include <STDIO.H>
#include <delays.h>
//#include "math.h"
//#include "stdlib.h"

void initialise()

{
TRISB&=0b00000001; //RB1 output

// configure interrupts
INTCONbits.GIE = 1; // Global Interrupt Enable
INTCONbits.PEIE = 1; // PEripheral Interrupt Enable
RCONbits.IPEN = 1; // Interrupt Priority level Enable
}

void sanity_flasher(int flasher) //LED connected at RB1 pin//
{
char c;
c = 1;
TRISBits.TRISB1 = 0;
while (c<=flasher)
{
TRISBits.TRISB1 = 1;
delay_s(1);
TRISBits.TRISB1=0;
Delay10KTCYx(1000); //1sec delay
c++;
}
}

// external interrupt

void read_stimulus() {

if(TRISBits.TRISB0=1)
{
sanity_flasher(Cool; /*flash LED 8 times*/

}
else
{
Sleep();

}
}

// main program that increments counter every second unless sleeping
void main()
{
initialise();
sanity_flasher(2);


while (1) // run forever//
{

{_asm CLRWDT _endasm} // clear the Watch-Dog Timer (WDT). This is
//recommended before executing a Sleep() instruction.

read_stimulus();

}
}
Back to top
View user's profile Send private message
KC



Joined: 05 May 2006
Posts: 99
Location: Victoria BC Canada

PostPosted: Sat Aug 05, 2006 2:10 am    Post subject: Reply with quote

Quote:
// configure interrupts
INTCONbits.GIE = 1; // Global Interrupt Enable
INTCONbits.PEIE = 1; // PEripheral Interrupt Enable
RCONbits.IPEN = 1; // Interrupt Priority level Enable


I see that you have enabled interupts but you haven't defined a function for servicing the interupt request! Either create this function, or change:
INTCONbits.GIE = 1; // Global Interrupt Enable
to
INTCONbits.GIE = 0; // Global Interrupt disable

I tried compiling your code but am missing the definitions for TRISBits.TRISB1 etc.....
_________________
KC
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WinPicProg Forums Forum Index -> Questions All times are GMT
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