CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help with Sleep and Waking up...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
phased



Joined: 03 Oct 2006
Posts: 17

View user's profile Send private message

Help with Sleep and Waking up...
PostPosted: Mon Oct 09, 2006 12:57 pm     Reply with quote

I'm using the 16F54 in my design.

I have an analog signal (noise from a mic) that I'm Schmitt Triggering. A loud noise, makes it go from 0V to Vdd (like a clapper). Of course this signal will fall back to 0 quickly. Then go back up on the next loud noise: from 0 to Vdd, Vdd to 0, and back quite often - along with the volume of the sound.

I want the PIC to sleep until the first of these 0 to Vdd rises. Then run a function (returning from the function will put it back to sleep). Until it hear's another loud noise....

I guess I'm not sure of a way to get an outside rising signal to wake up the pic without putting it back to sleep when it falls...

I thought of tying my "fluctuating input" to MCLR, but that will just reset the device over and over, right?

Input Signal: _______________-___-_-_-___-___----____

............I want to wake up here ^

Any Ideas would be greatly appreciated!!!
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Oct 09, 2006 1:27 pm     Reply with quote

It doesn't sleep when the signal falls.
It will sleep when you call the sleep() function.


Example Files: ex_wakeup.c


Last edited by treitmey on Mon Oct 09, 2006 1:29 pm; edited 1 time in total
bsodmike



Joined: 05 Aug 2006
Posts: 52

View user's profile Send private message Visit poster's website AIM Address MSN Messenger

PostPosted: Mon Oct 09, 2006 1:28 pm     Reply with quote

I believe that a reset would wake it up from sleep, so couldn't you have...

main(){
do_func();
sleep;
while(1); //should never reach this point.
}
phased



Joined: 03 Oct 2006
Posts: 17

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 1:37 pm     Reply with quote

Thanks for the replies.

I guess I didn't make my problem clear.

I have no problem going to sleep. My issue is with waking up the pic16F54. It only wakes up using the WDT or MCLR.

The problem with using MCLR is that it serves two purposes:

1) clear the pic (restart)

2) wake up from sleep.

Assume the chip is in sleep mode. If I toggle MCLR, I will wake it up. But if I continue to toggle, it will keep reseting.

I guess the only possible solution is to somehow disable MCLR for a time. Is this possible? Is it possible to turn off the MCLR pin or perhaps not allow reseting for a while?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 1:53 pm     Reply with quote

I don't like abusing the reset, even when it would be possible to disable it after waking up as it might have some other unexpected side effects. Another way to wake from sleep is by triggering an interrupt, for example connect the output of the Schmitt-trigger to the PIC's external interrupt pin.

Code:
#int_ext
void ext_handler(void) {
  do_func();
}

main() {
  enable_interrupts(INT_EXT);
  enable_interrupts(INT_GLOBAL);
  while(1)
  {
    sleep;    // Go to sleep until external interrupt is triggered.
  }
}



If there is only one interrupt and execution speed is important this can be optimized to:
Code:
main() {
  enable_interrupts(INT_EXT);
  while(1)
  {
    sleep;    // Go to sleep until external interrupt is triggered.
    do_func();
    clear_interrupts(INT_EXT);
  }
}
This optimized version will not call the interrupt handler, saving about 50 instructions of interrupt overhead. The trick is that the PIC is awakend by the hardware setting the interrupt flag. By not enabling the global interrupt flag the interrupt will be flagged but it will not be executed. When finished you have to clear the interrupt flag yourself where in the first version the compiler will insert this instruction automatically.

Whoops: I should have checked the datasheet first. The PIC16F54 doesn't have interrupts. I didn't know these chips existed.


Last edited by ckielstra on Mon Oct 09, 2006 2:02 pm; edited 1 time in total
phased



Joined: 03 Oct 2006
Posts: 17

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 1:59 pm     Reply with quote

I'm excited to see your solution. Unfortunately I'm new enough to this that I didn't understand it all.

Do you mean to tell me that the reset will be "ignored" when the chip is awake and will function when it is asleep? (for the purpose of waking it up)

Will this work the 16F54?

If so, GREAT! Thank you very much!

I'll try the code now.

Thanks again.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 1:59 pm     Reply with quote

The problem is that he's using an older technology PIC.
It can't wake-up from an interrupt. From 16F54 data sheet.
Quote:
The device can wake-up from Sleep through one of the
following events:
1. An external Reset input on MCLR/VPP pin.
2. A Watchdog Timer time-out Reset
(if WDT was enabled).

I suggest using a different PIC.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 2:08 pm     Reply with quote

This forum is so fast... Even before I could correct my mistake there were already two new posts. Smile

I agree with PCM, if possible have a look at another (newer) chip. The PIC16F54 has more limitations like a hardware stack of only two levels and very little RAM.
phased



Joined: 03 Oct 2006
Posts: 17

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 2:36 pm     Reply with quote

The Microchip website lists the 54 as the cheapest PIC (Low cost will help alot if this thing is made in the thousands). And for my VERY simple project, I don't need much. The 505 is the next step up in cost and also seems to have "wake up on pin change" capability. I may have to switch over but is there really no way to "disable" resetting with the F54?

Thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group