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.

Power saving in PIC18F4520

Status
Not open for further replies.

hez_91

Newbie level 5
Joined
May 21, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Singapore
Activity points
1,340
Hello,

I am working on a Anti-House Breaking System project which operates 24 hour/day surveillance.
I am planning to put it on sleep mode until the PIR sensor or Glass-Break sensor detects a break-in. How can this be done? (if possible)

I am aware of the 7 different operating modes but unsure of whether to use the Sleep or Idle modes and how to implement them.

I am also not sure of whether to use the watchdog timer or PIE interrupt to wake the PIC out of sleep mode.

Any help would be appreciated :D
Code:
#include <p18f4520.h>
#include <delays.h>

void main() {
//Initialisation of Analog and Digital and Port pins

ADCON1 = 0b00001111;	// set as Digital I/O
TRISA = 0b00000011;
TRISB = 0b00000000;	

                                                                                                 
while(1) {
if(PORTAbits.RA0=~PORTAbits.RA0) // Check for PIR Sensor
{
PORTB = 0b00000010; // Activate alarm
}
else
{
PORTB = 0b00000000;

}

if(PORTAbits.RA1=~PORTAbits.RA1) // Check for Glass-Break Sensor
{
PORTB = 0b00000010; // Activate alarm
}
else
{
PORTB = 0b00000000; 
}


}
}
 

firstly, do your program needs something more? or it's just detect input pulse and then bang! output on PORTB...
so to rearm the system just a reset?

does it will have some user interface? (lcd,keypad)
if not,
you can use the PIC INTs inputs, and "wake" from a Sleep() with no more business...(no watchdog no other interrupt) even, yo don't need an interrupt routine, just enable the interrupts but not the global interrupt bit...
 

Thanks for the tips,

I had changed the code to wake up from sleep through a INT input.

However, the interrupt only runs once, with or without sleep.

Can anyone help me with this problem?

Code:
#include <p18f4520.h>
#include <stdlib.h>
#include <delays.h>

void InterruptHandlerLow(void);

#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow(void){

_asm
	goto	InterruptHandlerLow
_endasm

}
#pragma code

#pragma interruptlow InterruptHandlerLow

void InterruptHandlerLow(void){

if(INTCON3bits.INT1IF = 1)
{
	PORTBbits.RB0 = 1; //Turn on Red LED
    Delay10KTCYx(200);
    PORTBbits.RB0 = 0; //Turn off Red LED
	INTCON3bits.INT1IF = 0;
}
}
void main()
{

OSCCONbits.IDLEN = 0;

TRISA = 0xff;
TRISB = 0b11110110;
TRISC = 0xff;
TRISD = 0xff;
TRISE = 0xff;

T0CON = 0b10000010;
PORTA = 0;
PORTB = 0;

INTCONbits.GIEH =0;
INTCONbits.GIEL =0;
RCONbits.IPEN = 1;

INTCON2bits.INTEDG1 = 1;

INTCON3bits.INT1IP = 0;
INTCON3bits.INT1IF = 0;
INTCON3bits.INT1IE = 1;

INTCONbits.GIEL = 1;
INTCONbits.GIEH = 1;

// Sleep();
PORTBbits.RB3 = 1; //Turn on Green LED

while(1);


}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top