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 support@ccsinfo.com

PIC10f222

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



Joined: 03 Apr 2008
Posts: 2

View user's profile Send private message

PIC10f222
PostPosted: Thu Apr 03, 2008 5:28 pm     Reply with quote

Hi friends
I am trying to wake up PIC10F222 from sleep mode. I am using PCWHD compiler version 4.07 and I am trying to wake him up by a change on input pin B0. Is there any special setting that I need to use or just simply I go to sleep mode by using "sleep()" function and then I will wake up by change on pin B0 status level.
Any help is greatly appreciated
here is the test code that I am using
[void main()
{
int i;

// setup_adc_ports(NO_ANALOGS);
//setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

// TODO: USER CODE!!
input(PIN_B0);
while(1)
{
for(i=0;i<100;i++)
{
output_high(PIN_B2);
delay_ms(100);
output_low(PIN_B2);
delay_ms(100);
}
sleep();
}

}]

it goes to sleep mode, but it doesnt come out whan i change the pin B0 status from high to low.

Thanks
Shahram[/code]
Guest_7068
Guest







PostPosted: Thu Apr 03, 2008 6:38 pm     Reply with quote

Try making a call to this function before entering the while loop:
Code:

setup_counters(WDT_18MS,PIN_CHANGE_FROM_SLEEP);
smomenouns



Joined: 03 Apr 2008
Posts: 2

View user's profile Send private message

PostPosted: Thu Apr 03, 2008 7:00 pm     Reply with quote

Guest_7068 wrote:
Try making a call to this function before entering the while loop:
Code:

setup_counters(WDT_18MS,PIN_CHANGE_FROM_SLEEP);


thank you so much for your reply. I tried it. It did not work out.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Apr 07, 2008 1:58 am     Reply with quote

Not sure about the PIC10F222 without looking at data sheets etc but.

You need to enable interrupts as this is what wakes the pic up.
You may not need to specify an interrupt handler but it may be best to:-

Code:

#int_ext  // b0 interrupt service routine.
void b0_isr(void) {
  int1 bit = input(b0);  // may be required to clear interrupt
}

void main(void) {
  enable_interrupts(int_ext);
  enable_interrupts(global);

  while(true) {
    sleep();
  }
}


insert your code as appropriate.
Ttelmah
Guest







PostPosted: Mon Apr 07, 2008 2:39 am     Reply with quote

No.
There are two ways of using interrupts to wake from sleep:
1) Enable the interrupts.
With this done, operation _will_ branch to the interrupt handler on the next instruction after waking. You absolutely _must_ have an interrupt handler if this is done. However it is not necessary for wake up.
2) Don't enable the interrupts.
With this done, the chip will wake up, but _not_ branch.
The interrupt flag being set, is a hardware event, and _still happens_, even if the interrupt is not enabled. 'Enabling' an interrupt, allows this specific interrupt to be routed to the hardware to trigger the interrupt branch. The global enable, turns on the final output from this hardware. The interrupt branching hardware, is _not_ involved in the wake up, so the interrupt can be left disabled.
Key though, is that a wake event _will not happen_, if the interrupt is already set when you go to sleep. Hence you _must_ clear the interrupt the instruction before the sleep (or verify that it is clear). The chips have a 'neat' feature, that when an interrupt is cleared, it _cannot_ be set again, till after the next instruction. This is deliberately done, so you can execute:
Code:

clear_interrupts(INT_EXT);
sleep();

and the interrupt cannot get set between these two instructions, so _will_ wake the chip.

Clear the interrupt before going to sleep. Remember it is easy for it to have become set accidentally when the chip starts running, and in this case, the code will not awaken on the level change.

Best Wishes
Matro
Guest







PostPosted: Mon Apr 07, 2008 2:44 am     Reply with quote

Have a look at page 17 of the datasheet.
You need to enable the wake-up on change (and eventually pull-ups).
To do so, add in your initialization code :
Code:

#ASM
MOVLW 0x80    //0x0C for pull-up enabled, see datasheet for other settings
OPTION
#ENDASM


Moreover just before going in sleep mode you need to read the port A to avoid an immediate wake-up.
Code:

#ASM
MOVF 0x06,W
#ENDASM


Matro.
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