View previous topic :: View next topic |
Author |
Message |
Hemantha
Joined: 26 Jul 2017 Posts: 2
|
Wake up a PIC from sleep using Timer1 Interrupt |
Posted: Wed Jul 26, 2017 11:52 pm |
|
|
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: 19504
|
|
Posted: Thu Jul 27, 2017 12:56 am |
|
|
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: 1345
|
|
Posted: Thu Jul 27, 2017 6:06 am |
|
|
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
|
|
Posted: Thu Jul 27, 2017 9:23 pm |
|
|
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
|
|
Posted: Thu Jul 27, 2017 9:51 pm |
|
|
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: 19504
|
|
Posted: Fri Jul 28, 2017 2:00 am |
|
|
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.... |
|
|
|