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

Can't wake up from sleep on Timer 1 interrupt

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



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

Can't wake up from sleep on Timer 1 interrupt
PostPosted: Thu May 11, 2017 8:32 am     Reply with quote

I make a silly program to wake up the PIC16f627 from sleep, the timer OSC is working, I can see the 32768KHz waveform in the oscilloscope, but the PIC refuses to wake up.

Can somebody tell me what I'm doing wrong?

Code:
#include <16F627.h>
#FUSES PROTECT,NOWDT,INTRC_IO,NOBROWNOUT,NOLVP
#use fast_io (ALL)

#define mosfet PIN_A4

void main(void)
{
   set_tris_a(0b00100000);
   set_tris_b(0b11011111);
   SETUP_TIMER_0(T0_INTERNAL|T0_DIV_256|T0_8_BIT);
   
   output_high(mosfet);
   
   clear_interrupt(INT_TIMER1);
   set_timer1(0);
   setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_1);//Two seconds.
   enable_interrupts(INT_TIMER1);
      
   while(1)
   {
      output_toggle(mosfet);
      output_toggle(PIN_A1);
      
      sleep();
      clear_interrupt(INT_TIMER1);         
   }      
}


Another thing is that RA4 doesn't toggle even with the proper pull up resistor but work ok if I use output_high and output low instruction.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Thu May 11, 2017 8:55 am     Reply with quote

Your chip does not support this....

Devices where he timer can wake from sleep have to keep it's oscillator running. Yours doesn't.
Quote:

"The device can wake-up from SLEEP through one of"
"the following events:"
"1. External RESET input on MCLR pin"
"2. Watchdog Timer Wake-up (if WDT was enabled)"
"3. Interrupt from RB0/INT pin, RB Port change, or the Peripheral Interrupt (Comparator)."


Is timer1 there?....

When a pin is 'toggled', it is the level on the pin that is read, and inverted. If (for instance) the load is such that the pin doesn't reach the voltage seen as Vih, then it won't toggle.
Whatever you have as a pullup on A4, is not getting it high enough, or the circuit attached it preventing it getting high enough. The input on that pin is a Schmitt type, so has to get to 4v (with a 5v supply) to be seen as 'high'....
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Thu May 11, 2017 9:50 am     Reply with quote

I'm looking the figure 14-16 from page 107 and TMR1IF is in the schematic, also the timer 1 is not synchronized and the oscillator keeps running even in sleep mode.

The text that you remark is opposed with that graphic, as far I understand.

Also in the same page that you remark says

If the global interrupts are disabled (GIE is
cleared), but any interrupt source has both
its interrupt enable bit and the corresponding
interrupt flag bits set, the device will
immediately wakeup from sleep
_________________
Electric Blue
temtronic



Joined: 01 Jul 2010
Posts: 9104
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu May 11, 2017 10:26 am     Reply with quote

I don't see an 'enable-global command......
but then again I'm hungry...
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Thu May 11, 2017 11:11 am     Reply with quote

temtronic wrote:
I don't see an 'enable-global command......
but then again I'm hungry...


I enabled PEIE but get the same result.
GIE is not needed, as in the datasheet says.

Quote:
If the global interrupts are disabled (GIE is cleared), but any interrupt source has both bits interrupt enable bit and the corresponding interrupt flag bits set, the device will immediately wakeup from sleep

_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Thu May 11, 2017 11:28 am     Reply with quote

temtronic wrote:
I don't see an 'enable-global command......
but then again I'm hungry...


You never need to enable the global interrupt to wake from sleep.
If you do, then you need to have a handler.

The instruction after the sleep should always be a 'nop' (delay_cycles(1)). Otherwise this may not execute correctly (this is 'prefetched' when you go to sleep). However that isn't the problem here.

I agree the data sheet disagrees with itself on this....

I'd say it ought to work provided the timer is running in async mode.
If you look, the logic is reversed. The SYNC bit has to be set to run in ASYNC mode. I wonder if your compiler has it wrong (you don't tell us the version). The current compilers do default to setting this bit.
So:
Code:

#bit T1SYNC=getenv("BIT:T1SYNC")

   SETUP_TIMER_0(T0_INTERNAL|T0_DIV_256|T0_8_BIT);
   T1SYNC=TRUE; //set the bit to run asynchronous
   output_high(mosfet);
   
   clear_interrupt(INT_TIMER1);
   set_timer1(0);
   setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_1);//Two seconds.
   enable_interrupts(INT_TIMER1);
     
   while(1)
   {
      output_toggle(mosfet);
      output_toggle(PIN_A1);
     
      sleep();
      delay_cycles(1);
      clear_interrupt(INT_TIMER1);   
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

Re: Can't wake up from sleep on Timer 1 interrupt
PostPosted: Thu May 11, 2017 2:04 pm     Reply with quote

On the wakeup issue. I noticed there was an errata on the timer 1 control register. it isn't related to your sleep issue, but you might want to be safe and dump out the contents of the register to a serial terminal (or out the ICD-U64 if you have one of those) and verify.

E_Blue wrote:

Another thing is that RA4 doesn't toggle even with the proper pull up resistor but work ok if I use output_high and output low instruction.


How are you toggling the output for the pull up? it'll need to be something similar to
Code:

static BOOLEAN laststate = 0;
...

if(lastState){
   output_float(PIN_A4);
}else{
   output_drive(PIN_A4);
}
lastState = !lastState;
   


Though I never use fast_io, so I don't know if that will interfere at all. You also need to make sure it doesn't toggle too fast relative to the pullup value you are using.
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Fri May 12, 2017 7:20 am     Reply with quote

@Ttelmah Yes, I check T1SYNC, I have 0x0F on T1CON.
I get bored of trying with sleep command so I change to a main external oscillator of 32.768KHz and now I'm using TMR0 interrupt and waiting in a loop.


@jeremiah
I was using output_toggle CCS instruction.

I had 4.22V and the supply was 5V, so seems to be a voltage level problem as Ttelmah said.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Fri May 12, 2017 7:34 am     Reply with quote

It is interesting that the main part about interrupts doesn't mention waking from Timer1. Almost looks as if the connection is in some way disabled when asleep. Unusual to find an oddity on such an old chip. Except if perhaps it is an old version (they don't actually have the errata for chips pre RevC any more on the site).
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Fri May 12, 2017 8:09 am     Reply with quote

Yes, is an old chip, I know, but we have several of this chips and now we need a simple timer and a PIC16F627 is more than enough for that job.

To bad that the errata is no longer on Microchip web site. Sad
_________________
Electric Blue
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