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

Wake up a PIC from sleep using Timer1 Interrupt

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



Joined: 26 Jul 2017
Posts: 2

View user's profile Send private message

Wake up a PIC from sleep using Timer1 Interrupt
PostPosted: Wed Jul 26, 2017 11:52 pm     Reply with quote

Hi,
I tried to wake up a PIC (12F683) from sleep using Timer1 Interrupt without external crystal (using internal oscillator). But it doesn't work. I tested it using watch dog timer and it works. But I want to use Timer1 Interrupt. I have read that Timer1 is working in sleep mode.
Please help me.
Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu Jul 27, 2017 12:56 am     Reply with quote

I'm afraid you are reading incorrectly.

From the data sheet:
Quote:

6.8 Timer1 Operation During Sleep
Timer1 can only operate during Sleep when setup in
Asynchronous Counter mode. In this mode, an external
crystal or clock source can be used to increment the
counter. To set up the timer to wake the device:
• TMR1ON bit of the T1CON register must be set
• TMR1IE bit of the PIE1 register must be set
• PEIE bit of the INTCON register must be set
The device will wake-up on an overflow and execute
the next instruction. If the GIE bit of the INTCON
register is set, the device will call the Interrupt Service
Routine (0004h).


Note the _only_, and the _external_.....

Also look at the clock diagram, where the LFINTOSC, only feeds the PWRT, WDT & FSCM circuits, not Timer1.
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Thu Jul 27, 2017 6:06 am     Reply with quote

There are a few pics out there that have the capability to use the internal to wake from sleep (the PIC24F32KA30x chips for example), however all of the ones I have seen use a very inaccurate timer (up to 15% tolerance!) just like the watchdog timer, which is usually has a very wide tolerance. Generally, if you want to wake up from sleep and have an accurate time, you either need to use an external crystal with an async timer or use some sort of external chip and trigger off the edges.
Hemantha



Joined: 26 Jul 2017
Posts: 2

View user's profile Send private message

PostPosted: Thu Jul 27, 2017 9:23 pm     Reply with quote

Thanks for your help.
I tried using external crystal oscillator. But it doesn't wake up. My code is here.
I used PIC 12F683, 12F675 and 4MHz Crystal.

Code:
unsigned short cnt;

void interrupt() {
  if (TMR1IF_bit) {
    cnt++;                    // increment counter
    TMR1IF_bit = 0;           // clear TMR0IF
    TMR1H = 0x00;
    TMR1L = 0x00;
  }
}

void main() {
  ANSEL  = 0;                 // Configure AN pins as digital
  CMCON = 7;               // Disable comparators
  GPIO=0x00;               // Initialize PORTB
  TRISIO=0x00;                 // PORTB is output
  T1CON = 0b00110111;                  // Timer1 settings
  TMR1IF_bit = 0;             // clear TMR1IF
  TMR1H = 0x00;               // Initialize Timer1 register
  TMR1L = 0x00;
  TMR1IE_bit = 1;             // enable Timer1 interrupt

  cnt =   0;                  // initialize cnt
  INTCON = 0xC0;              // Set GIE, PEIE


  while (1) {
    asm sleep;
    if (cnt >= 1) {
      GPIO  = ~GPIO;        // Toggle PORTB LEDs
      cnt = 0;                // Reset cnt
    }   
  }
}

I test it changing T1CON as 0b00110101. This works without sleep operation. What is wrong in my codes?
Please help me.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 27, 2017 9:51 pm     Reply with quote

Quote:
asm sleep;

I think you're using MikroC. You're on the wrong compiler forum.
This forum is for the CCS compiler. You want the MikroC forum.
mikroC PRO for PIC General
https://forum.mikroe.com/viewforum.php?f=88

You can use Google to search their forums with this search string:
Quote:
site:forum.mikroe.com "asm sleep;"
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Fri Jul 28, 2017 2:00 am     Reply with quote

However as a farewell comment. Not going to work....

The Timer1 oscillator, is a low power oscillator. Specified to run off a 32768Hz crystal (37KHz max). Not 4MHz....
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