Jump to content

Recommended Posts

Hello, I need to set my PIC into sleep mode.

 

This is a bit of main.....

 

as you can see I have a loop that basically waits for a switch to be pressed, however I would like to put the PIC in sleep mode at this stage, as the PIC will setup and be put into this state initially.

 

This loop works fine until i stick the sleep() function in.

 

void main( void )

{

 

SYS_Init();

 

do {

sleep(); SYS_OnIdle(); UI_Idle();

} while ( !UI_Proceed() );

 

more code etc...

 

}

 

 

I set my #pragma DATA _CONFIG, 0x01CC //0000 0001 1100 0100

 

I am using the PIC12F629, and the above pragma enables watch dog timer etc...

 

 

Any ideas ???

Link to post
Share on other sites

ayeung,

 

The "sleep();" function places a PIC "SLEEP" opcode inline in your C program.

 

The "SLEEP" opcode stops most of the clocks and crystal oscillators.

 

Depending on your PIC there may be not clocks running at all.

 

You may ask why do you need to know this?

 

Well I am glad you asked.

 

For the PIC to wake up from SLEEP some "external" event must occur like:

 

1 - Unmasked interrupt occurs.

1a - ADC using clocked using FRC as the clock source.

1b - INT0 input asserted.

1c - TMR1 using low power oscillator.

1d - Interrupt on change.

(Note: Interrupt must not depend on system oscillator)

(TMR0 internal clock depends on the system oscillator)

 

2 - Watch dog timer times out.

 

3 - Reset input asserted.

 

There are other possible way to exit sleep.

Read the datasheet for your specific PIC.

 

---

 

Your code fragment suggests that you are using some RTOS.

 

Many RTOS for the PIC use TMR0 as a system tick interrupt and when you execute a SLEEP opcode this source is stopped.

 

This means your RTOS will run very slowly, if at all because the only time the PIC wakes up is after a WDT timeout.

 

If you have turned off the WDT then it may never wake up.

Link to post
Share on other sites
ayeung,

 

The "sleep();" function places a PIC "SLEEP" opcode inline in your C program.

 

The "SLEEP" opcode stops most of the clocks and crystal oscillators.

 

Depending on your PIC there may be not clocks running at all.

 

You may ask why do you need to know this?

 

Well I am glad you asked.

 

For the PIC to wake up from SLEEP some "external" event must occur like:

 

1 - Unmasked interrupt occurs.

1a - ADC using clocked using FRC as the clock source.

1b - INT0 input asserted.

1c - TMR1 using low power oscillator.

1d - Interrupt on change.

(Note: Interrupt must not depend on system oscillator)

(TMR0 internal clock depends on the system oscillator)

 

2 - Watch dog timer times out.

 

3 - Reset input asserted.

 

There are other possible way to exit sleep.

Read the datasheet for your specific PIC.

 

---

 

Your code fragment suggests that you are using some RTOS.

 

Many RTOS for the PIC use TMR0 as a system tick interrupt and when you execute a SLEEP opcode this source is stopped.

 

This means your RTOS will run very slowly, if at all because the only time the PIC wakes up is after a WDT timeout.

 

If you have turned off the WDT then it may never wake up.

 

 

Thanks for the reply.

 

My system is not a RTOS, I dont think that I have turned off the WDT, I enable the WDT so am presuming that it runs constantly, need to check this.

 

TMR0 is used in places so I will investigate if this is screwing things up.cheers!

Link to post
Share on other sites

All good, solved the problem.

 

Forgot to set the prescaler value in the option register>> therfore the WDT was continually timing out before I could reset it with the hard to find reference to command ....clear_wdt()

 

now I have slapped clear_wdt in where needed...nice 1. :blink:

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...