View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
PIC12F683 in SLEEP Mode |
Posted: Tue Jul 27, 2010 5:08 pm |
|
|
hi
I try put this PIC in sleep mode but it don't go.... or I think it...
Code: |
#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, MCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)
#define RAND_MAX 6
#include <STDLIB.H>
void main()
{
output_high(PIN_A5);
delay_ms(2000);
sleep();
}
|
PS: for example in this program after I call SLEEP() function PIN_A5 don't turnoff?
Someone can help me?
best regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 27, 2010 6:05 pm |
|
|
Quote: |
For example in this program after I call SLEEP() function PIN_A5 don't turnoff?
|
Download the 12F683 and read the section on Sleep:
Quote: |
12.7 Power-Down Mode (Sleep)
|
It describes what the i/o pins do in Sleep mode. Read it. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed Jul 28, 2010 7:52 pm |
|
|
Hi
For I make an rand sequence I make some like this:
Code: |
#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)
(...)
while(input(PIN_A3)==1);
do {
if (n==7) n=0;
n=n+1;
if (input(PIN_A3) == 1) aux=1;
} while ((aux != 1));
switch (n)
{
case 1 : output_a(0x01);
break;
case 2 : output_a(0x02);
break;
case 3 : output_a(0x03);
break;
case 4 : output_a(0x06);
break;
case 5 : output_a(0x07);
break;
case 6 : output_a(0x16);
break;
}
delay_ms(10000);
output_a(0x00);
output_low(PIN_A5);
SLEEP();
}
|
But my PIN_A3 is MCLR but on fuse I use NOMCLR.
My problem now is, how I can return from SLEEP mode? is possible use reset switch? (attention on fuses because there I have NOMCLR).
best regards |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Jul 29, 2010 5:51 am |
|
|
don't have other way to return from SLEEP MODE if I have MCLR desactivated?
best regards |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Jul 29, 2010 6:55 am |
|
|
Your motivation for using sleep mode is completely unclear. In my view, sleep mode makes only sense together with any event that wakes up, in most cases either a watchdog timeout or an external interrupt. But you don't enable a possible wake up event in your code. So a reset would be the only way to restart (not to wake up) the processor. I don't see what it's good for. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Jul 29, 2010 12:18 pm |
|
|
Hi
My idea is to save energy.
Can I use PIN_A3 to wake the PIC?
Clicking on PIN_A3 is an event I am doing right?
Best regards |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Jul 29, 2010 2:10 pm |
|
|
Yes, you have to enable the GPIO change interrupt for the respective pin. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Jul 29, 2010 4:58 pm |
|
|
Hi
How I can make this?
You can give an example?
I try this but give an error on compile.
Code: |
#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)
[b]#int_ext
void int_ra3()
{
reset_cpu();
}[/b]
void main()
{
int8 i,aux=0,n=0;
int16 time;
[b]enable_interrupts(GLOBAL);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);[/b]
while(input(PIN_A3)==1);
do {
if (n==7) n=0;
n=n+1;
if (input(PIN_A3) == 1) aux=1;
} while ((aux != 1));
switch (n)
{
case 1 : output_a(0x01);
break;
case 2 : output_a(0x02);
break;
case 3 : output_a(0x03);
break;
case 4 : output_a(0x06);
break;
case 5 : output_a(0x07);
break;
case 6 : output_a(0x16);
break;
}
delay_ms(10000);
output_a(0x00);
output_low(PIN_A5);
SLEEP();
//while(input(PIN_A3)==1);
//reset_cpu();
}
|
best regards |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Jul 29, 2010 5:52 pm |
|
|
hi
Thanks all
Problem is now solve...
Code: |
#int_ra
void int_isr(void)
{
}
void main()
{
int8 i,aux=0,n=0;
int16 time;
enable_interrupts(GLOBAL);
ext_int_edge(H_TO_L);
disable_interrupts(INT_RA3);
(....)
enable_interrupts(INT_RA3);
SLEEP();
|
This syntax stay correct on sleep mode use?
best regards |
|
|
|