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.

Pic16f88 sleep mode & wake from interrupt

Status
Not open for further replies.

gatoulisss

Junior Member level 2
Joined
Feb 5, 2015
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
193
hello everyone!

I need your help, im using mikro c and trying to use sleep mode on a pic16f88 mcu and wake from a interrupt on RB0 pin
what I want to do is a simple project so I can understand how to use sleep mode for example:

I have a sensor on RB0 pin, when this is '1' then a led will blink, when it goes '0' for more than 3secs then the mcu goes to sleep till RB0 goes '1' again.


can anyone help me with the code? thank you!
 

Hi,

If you want somemone to do jour job, then you should consider to pay for it.

If you don't want others to do your job, you should show your own effort.
Read the datasheets about sleep function, go through code examples. (Use / modify the code for your needs)
Show your flow chart, show your setup, show your code.
What did you understand so far, and where exactly do you need help?

Klaus
 

Klaus is right of course, we can guide your efforts but not do the work for you.

The basics are though:
1. write an ISR so it can recover when the RB0 interrupt triggers.
2. enable RB0 as an interrupt source.
3. read RB0 as a normal input pin and check for how long it has been low, if > 3 secs just use the 'sleep' instruction.

There are many ways to check the pin timing but as you are flashing the LED anyway, I would suggest using a hardware timer and pre-load it to create a 3 second delay every time RB0 is high. Do not pre-load it if RB0 is low so it counts for 3 seconds then overflows. You can poll the timer or use a timer interrupt to tell when the 3 seconds has elapsed and maybe use one of the timer bits to flash the LED as well.

Brian.
 

my code is the one below but I think that mcu never goes to sleep the blinking led is just to undersand if its waken or still sleeping. im doing this project just to understand how to sleep and wake from interrupt


Code C - [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
int k;
 
void main() {
osccon=0x70;                 // set osc
ansel=0;                     //  set analog
intcon.inte=1;               // enable RB0/INT
 
trisb.f0=1;                 //set RB0 as input
trisb.f3=0;                 //set RB3 as output
 
for (;;) {
start:
while (portb.f0==1){         //  led blink till RB0=0
portb.f3=0;
delay_ms(400);
portb.f3=1;
delay_ms(400);}
if (portb.f0==0){
k=1;
delay_ms (3000);
if (portb.f0==0 && k==1){    //check RB0=0 for more than 3secs and then sleep
intcon.gie=0;             //clear GIE before sleep
portb.f3=0;
asm sleep;}
else{
k=0;
goto start;}
}
}
}

 

Hi,

I assume "blinking" and check for "3 seconds" should be done in the same time.
This best is done with interrupts, but also can be done in main loop.

Let's assume blinking should be about: 400ms ON, 400ms OFF,
And let's assume the shortest "key_down_time" you safely want to detect is about 100ms.

Btw: it's your job to draw a flow chart...or any other plan for your software. Picture, chart, diagram, text...
All the professionaks need to do this, too. Even if everyone finds it booring...


pseudo code:
Code:
Init timeout variable 
Init blink variable
Init periferals 
Init periferal that RB0=1 resumes from sleep

Loop:
   Wait 100ms
   Increment blink
   If blink > 3 then (invert LED, blink =0) ; blink 0, 1, 2, 3, 0... every 4 turns (4 × 100ms) it inverts the LED state for blinking
   If RB0= 0 then (increment timeout) else (timeout = 0)
   If timeout > 29 then (sleep) ; 30 × 100ms = 3s
End loop

Klaus
 

I read the initial spec so that the input should be continuously monitored. delay_ms (3000) will ignore any input events during 3 sec, so that's probably not what you want.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top