PIC12F683 does not wake-up from sleep

General discussion on mikroElektronika development boards.
Author
Message
dan07
Posts: 33
Joined: 14 Aug 2013 06:09

PIC12F683 does not wake-up from sleep

#1 Post by dan07 » 19 Aug 2013 03:06

Hello,

I am quite new to PICs programming and I want to make my PIC12F683 wake-up from sleep if 5 V (+) is feed to Pin 2.

I wrote the code (mikroC PRO v 6.0.0) below but it is not working on my PIC12F683. I am able to compile and write the code to the PIC but it does not wake-up from sleep.

Code: Select all

void main()             // Blink a LED after wake-up from sleep (PIC12F683)
{

int ctr;

 TRISIO.B2 = 0;         // Set Pin 5 as Output
 TRISIO.B5 = 1;         // Set Pin 2 as Input
 
 INTCON.GIE = 1;        // Enable Global Interrupt
 
 IOC.B5 = 1;            // Enable interrupt-on-change on Pin 2
 
asm{sleep};             // Make PIC12F683 sleep
 
                        // When 5v (+) is fed to Pin 2, the PIC should wake up
                        // and run the For Loop
 
                        for(ctr=1;ctr<=5;ctr++)  // Blink a LED
                        {
                         GPIO.B2 = 1;
                         Delay_ms(500);

                         GPIO.B2 = 0;
                         Delay_ms(500);
                        }
 
}
What I am missing on my code?

Thanks.

Dan07

bpislife
Posts: 539
Joined: 11 Jun 2006 21:16
Location: Cumberland, RI

Re: PIC12F683 does not wake-up from sleep

#2 Post by bpislife » 20 Aug 2013 00:44

Let's start with your hardware. Are you using a pull up resistor or a pull down resistor on that pin? Second, does the program run (ie you blink an LED to confirm the MCU is running?

There is barely any MCU initialization commands, which is why I ask.

dan07
Posts: 33
Joined: 14 Aug 2013 06:09

Re: PIC12F683 does not wake-up from sleep

#3 Post by dan07 » 20 Aug 2013 01:06

bpislife wrote:Let's start with your hardware. Are you using a pull up resistor or a pull down resistor on that pin? Second, does the program run (ie you blink an LED to confirm the MCU is running?

There is barely any MCU initialization commands, which is why I ask.
The idea is to use a Reel Magnetic Switch on that pin to wake-up the MCU. But since I am quite new on that I don't know if I will have to associate the Reel Switch with anything else to wake-up the MCU.

If I remove the asm{sleep} from code the led is blinking properly.

Thanks.

Dan07

bpislife
Posts: 539
Joined: 11 Jun 2006 21:16
Location: Cumberland, RI

Re: PIC12F683 does not wake-up from sleep

#4 Post by bpislife » 21 Aug 2013 01:53

Are you using a development board or are you using your own design?

dan07
Posts: 33
Joined: 14 Aug 2013 06:09

Re: PIC12F683 does not wake-up from sleep

#5 Post by dan07 » 21 Aug 2013 05:02

bpislife wrote:Are you using a development board or are you using your own design?
I am using my own design.

bpislife
Posts: 539
Joined: 11 Jun 2006 21:16
Location: Cumberland, RI

Re: PIC12F683 does not wake-up from sleep

#6 Post by bpislife » 22 Aug 2013 02:05

Would you be willing to share you schematic? If so, i could mark it up and send it back to you. It is hard to debug this type of problem without seeing the schematic.

dan07
Posts: 33
Joined: 14 Aug 2013 06:09

Re: PIC12F683 does not wake-up from sleep

#7 Post by dan07 » 22 Aug 2013 02:39

bpislife wrote:Would you be willing to share you schematic? If so, i could mark it up and send it back to you. It is hard to debug this type of problem without seeing the schematic.
The code is written on the first message of this thread. Everything that is below the asm{sleep} option should run after the wake-up of the microchip. I put the code to blink a led because my real application will use do a very similar thing. It will use voltage to stimulate a tissue.

What I need is to modify the code above the asm{sleep} line in order to have the microchip waking up when a pin is stimulated with voltage (5V +).

Thanks.

MicroMark
Posts: 181
Joined: 11 Feb 2011 17:22

Re: PIC12F683 does not wake-up from sleep

#8 Post by MicroMark » 22 Aug 2013 15:26

Dan
Try putting a "asm NOP" after your "asm sleep" line. See if this helps.

This is a good tutorial
http://embedded-lab.com/blog/?p=3237

dan07
Posts: 33
Joined: 14 Aug 2013 06:09

Re: PIC12F683 does not wake-up from sleep

#9 Post by dan07 » 29 Aug 2013 04:58

Hello everyone,

After couple days struggling to solve my issue I am still stuck. I was considering using GP0 (Pin 7) with its "ultra low power wake-up" option to have my PIC12F683 waking after 5 V (+) was feed to Pin 7 but the code does not work. Could someone help me with this issue?

I believe that the solution is pretty simple but since I am a beginner on PICs and MikroC I can't find the solution by my self.

The example code is posted on the first message of the thread.

Thanks.

Dan07.

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: PIC12F683 does not wake-up from sleep

#10 Post by milos.vicentijevic » 29 Aug 2013 13:34

Hello Dan,

since I don't have PIC12F683 at the moment, I'm unable to test it, but I'll try to help you. There is a mistake in firstly written code. PIN2 should be output and PIN5 should be input, since pin5 has interrupt capability. For more information for proper initialization of sleep instruction please consult datasheet of PIC12F683:

http://ww1.microchip.com/downloads/en/d ... 1211d_.pdf (page 100).

Code: Select all

void interrupt() iv 0x0004 ics ICS_AUTO {
intf_bit = 0;
}
void main()             // Blink a LED after wake-up from sleep (PIC12F683)
{

int ctr;

 TRISIO.B2 = 0;         // Set Pin 2 as Output
 TRISIO.B5 = 1;         // Set Pin 5 as Input

 INTE_bit = 1;        // Enable INT

 
 IOC.B2 = 1;            // Enable interrupt-on-change on Pin 5 (GP2)
 
 INTCON.GIE = 0;        // Disable Global interrupts , *for wake up on interrupt 
                                //it will have to be this way

asm{sleep};             // Make PIC12F683 sleep

                        // When level on Pin 5 is different than 
                        // state it has during entering sleep state, the PIC should wake up
                        // and run the For Loop

                        for(ctr=1;ctr<=5;ctr++)  // Blink a LED
                        {
                         GPIO.B2 = 1;
                         Delay_ms(500);

                         GPIO.B2 = 0;
                         Delay_ms(500);
                        }

}
If you are going to use WDT please clear it before entering sleep state.
Best Regards,
Milos Vicentijevic

dan07
Posts: 33
Joined: 14 Aug 2013 06:09

Re: PIC12F683 does not wake-up from sleep

#11 Post by dan07 » 30 Aug 2013 01:05

Thanks for the reply. I replaced some things on lines 11, 12, 30 and 33 because I believe that they should be replaced. Am I right? See code below:

Code: Select all


void interrupt() iv 0x0004 ics ICS_AUTO {
intf_bit = 0;
}


void main()             // Blink a LED after wake-up from sleep (PIC12F683)
{

int ctr;

 TRISIO.B5 = 0;         // Set Pin 2 as Output. I replaced .B2 by .B5
 TRISIO.B2 = 1;         // Set Pin 5 as Input.   I replaced .B5 by .B2

 INTE_bit = 1;        // Enable INT


 IOC.B2 = 1;            // Enable interrupt-on-change on Pin 5 (GP2)

 INTCON.GIE = 0;        // Disable Global interrupts , *for wake up on interrupt
                                //it will have to be this way

asm{sleep};             // Make PIC12F683 sleep

                        // When level on Pin 5 is different than
                        // state it has during entering sleep state, the PIC should wake up
                        // and run the For Loop

                        for(ctr=1;ctr<=5;ctr++)  // Blink a LED
                        {
                         GPIO.B5 = 1;             // I replaced .B2 by .B5
                         Delay_ms(500);

                         GPIO.B5 = 0;             // I replaced .B2 by .B5
                         Delay_ms(500);
                        }

}

In MikroC > Project > Edit Project > Oscillator System, I am using "INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN". Is it right? Is there anything else that I should change on this screen to make my PIC wake up when I need?

I was not able to wake the PIC just by feeding 5V (+) on PIN 5 after the PIC went to sleep. How should I procedure to wake up the PIC?

Thanks a lot.

dan07
Posts: 33
Joined: 14 Aug 2013 06:09

Re: PIC12F683 does not wake-up from sleep

#12 Post by dan07 » 30 Aug 2013 02:23

Find below a screenshot of my settings.
Attachments
Config.jpg
Config.jpg (91.54 KiB) Viewed 10311 times

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: PIC12F683 does not wake-up from sleep

#13 Post by milos.vicentijevic » 30 Aug 2013 12:22

Hello,

you are right! :) You might try also:

Code: Select all

 TRISIO2_bit = 1;         // Set Pin 5 as Input
 TRISIO5_bit = 0;         // Set Pin 2 as Output
When it comes to internal oscillator setting I suggest you to comment your asm line. If your LED blinks (this time on pin2 (GP5) ) your oscillator settings should be fine.

Best Regards,
Milos Vicentijevic

dan07
Posts: 33
Joined: 14 Aug 2013 06:09

Re: PIC12F683 does not wake-up from sleep

#14 Post by dan07 » 30 Aug 2013 18:46

milos.vicentijevic wrote:Hello,

you are right! :) You might try also:

Code: Select all

 TRISIO2_bit = 1;         // Set Pin 5 as Input
 TRISIO5_bit = 0;         // Set Pin 2 as Output
When it comes to internal oscillator setting I suggest you to comment your asm line. If your LED blinks (this time on pin2 (GP5) ) your oscillator settings should be fine.

Best Regards,
Milos Vicentijevic
What is the diffrrence of having _bit following the TRISIO2 and TRISIO5?

I will try this and will keep you posted about that. To wake the PIC by feeding the Pin 5, should I use resistors and capacitors to do that?

Thanks.

MicroMark
Posts: 181
Joined: 11 Feb 2011 17:22

Re: PIC12F683 does not wake-up from sleep

#15 Post by MicroMark » 30 Aug 2013 20:23

I don't see your ANSEL setting

Try adding this above your tris statements

ANSEL = %0000

This will make all inputs digital
Last edited by MicroMark on 30 Aug 2013 22:47, edited 1 time in total.

Post Reply

Return to “Development Boards”