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

Pic18f87k22 wakeup

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



Joined: 08 Aug 2016
Posts: 5

View user's profile Send private message

Pic18f87k22 wakeup
PostPosted: Mon Aug 08, 2016 8:04 pm     Reply with quote

Hi,
How do I start the timer4 interrupt to fire after wakeup via serial input?
This is what I have and timer4 does not fire:
Code:

disable_interrupts(INT_TIMER4);
clear_interrupt(INT_TIMER4);
setup_timer_4(T4_DIV_BY_4, xxxx, 16);
enable_interrupts(INT_TIMER4);

The same lines of code work on startup (before initiating sleep()).


Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 08, 2016 11:48 pm     Reply with quote

Are global interrupts enabled ? The program won't jump to the Timer4
interrupt routine if global interrupts are disabled.

Also, post your sleep() setup code. I want to see if you are putting the
PIC into full sleep or sleep idle mode .
aria



Joined: 08 Aug 2016
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 09, 2016 4:54 am     Reply with quote

enabling global interrupts did not help; I used this:
Code:
   enable_interrupts(GLOBAL);

after enabling the timer4.


Here is my sleep steps:
Code:

   shutdown();
   clear_interrupt(INT_EXT);
   set_usart_int();
   kill_wd();
   sleep();
   delay_cycles(1); // pre-fetched NOP
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 09, 2016 10:16 am     Reply with quote

Quote:
shutdown();
clear_interrupt(INT_EXT);
set_usart_int();
kill_wd();
sleep();
delay_cycles(1); // pre-fetched NOP

You're putting the PIC into full sleep mode. You need to use SLEEP_IDLE
mode. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=46111
Also read the thread for an alternate method.
aria



Joined: 08 Aug 2016
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 09, 2016 1:09 pm     Reply with quote

Thanks for your response,

I do wake-up from sleep via serial data.
How do I get the timer 4 running again after wake-up from deep sleep?
aria



Joined: 08 Aug 2016
Posts: 5

View user's profile Send private message

PostPosted: Wed Aug 10, 2016 9:25 am     Reply with quote

Does anyone have an idea of how to start timer 4 after wake-up from a deep sleep?



Thanks
temtronic



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

View user's profile Send private message

PostPosted: Wed Aug 10, 2016 9:48 am     Reply with quote

You really need to post a small, compilable program that shows what you're doing AND your compiler version. If possible, post the listing file as well.
You may have a compiler 'bug' that only showing the code and listing will tell.

Jay
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Wed Aug 10, 2016 11:53 am     Reply with quote

Just as a point of interest in why this is important:
We have found that for some PIC24 parts, that version 5.049 of the compiler has a bug when generating sleep commands. Later versions fix this bug. It is very important to supply the data requested in the forum posting guidelines.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 10, 2016 2:38 pm     Reply with quote

Quote:
Does anyone have an idea of how to start timer 4 after wake-up from a deep sleep?

The following test program will wake-up from sleep and run Timer4
interrupts. Start the program, press a push-button on Pin B0 (see
schematic below) and the LED on pin D0 will start blinking at a 1 Hz rate.
This program was compiled with CCS compiler version 5.061.
I didn't have an 18F87K22, so I used a 46K22 instead.

The INT0 pin defaults to interrupting on the rising edge. I left it at the
default, so the interrupt will actually occur when the pushbutton is pushed
and then released.
Code:
#include <18F46K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS, stream=HW_UART)

#define LED_PIN  PIN_D0

//------------------------
// Blink an LED at a 1 Hz rate

#int_timer4
void timer4_isr(void)
{
static int i = 0;

if(i == 30)
  {
   output_toggle(LED_PIN);
   i = 0;
  }

i++;
}

//======================================
void main(void)
{

output_low(LED_PIN);

clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);

sleep();   // Wake-up when pushbutton on Pin B0 is pressed
delay_cycles(1);

disable_interrupts(INT_TIMER4);
clear_interrupt(INT_TIMER4);
setup_timer_4(T4_DIV_BY_4, 255, 16);
enable_interrupts(INT_TIMER4);
enable_interrupts(GLOBAL);

while(TRUE);
}


Circuit on Pin B0:
Code:
           +5v
            |
            <
            > 4.7K       
            <         ___  Switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
B0                            --- GND
                               -   
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Aug 11, 2016 12:39 am     Reply with quote

Only 'caveat' to PCM_programmer's code, is that you should disable INT_EXT, after the sleep, before enabling 'INT_GLOBAL'. Otherwise, the code will try to call a non-existent INT_EXT handler.

Key point to understand, is that at the start, 'GLOBAL' is disabled. INT_EXT, can therefore trigger and wake the chip, without a handler ever being called/needed. However the flag for this interrupt is then set, so if you enable the 'GLOBAL' interrupt bit, INT_EXT will attempt to be called. So this interrupt needs to be disabled before this is done....
You could clear the INT_EXT bit, but there would still be the potential to call an INT_EXT handler, if the button triggered again. So better to disable this interrupt after it is used.

Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 11, 2016 12:48 am     Reply with quote

Thank you for pointing that out. I missed it but I should have seen it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Aug 11, 2016 1:30 am     Reply with quote

You spot my mistakes often enough. Smile

Be interesting to hear whether it works.
aria



Joined: 08 Aug 2016
Posts: 5

View user's profile Send private message

PostPosted: Thu Aug 11, 2016 4:22 pm     Reply with quote

Many thanks guys; I'll give it a try.
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