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

Retaining OSC1 INT Period w/ Other EXT INTs

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



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

Retaining OSC1 INT Period w/ Other EXT INTs
PostPosted: Wed Feb 03, 2010 10:37 am     Reply with quote

Hello All,

Been out of this for a while and have jumped back in with a project that uses OSC1 w/ a 32.768XTAL and PCM Programmer's code for a periodic wake up using the PEIE bit.

I've also got INT_EXT enabled to capture another event during sleep. I don't want to reset TIMER1 during the INT_EXT wake so my 'regular' TIMER1 wake events remain spaced at the proper times.

So...

My questions are:

Should I just save the TIMER1 value and adjust before going back to sleep?

How do I capture the TIMER1 value upon wakeup from an INT_EXT?

Any good way to WAG a value for the correction to TIMER1 for the few instructions that get executed during a INT_EXT?



Is there a better way to do this?


Thanks,

John
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 03, 2010 10:55 am     Reply with quote

Post a (compilable) test program so we can see what you're talking about.
Ttelmah
Guest







PostPosted: Wed Feb 03, 2010 11:03 am     Reply with quote

Why should timer1, need to be adjusted at all?.
The timer will stay running at the same rate whether or not the processor is running.
The only errors on timing, will be:
1) If the timer interrupt occurs _while the processor is already handling the external interrupt_, then the service will be delayed till after this has completed.
2) If the external interrupt occurs while the timer interrupt is executing, it will be dleayed till the timer interrupt completes.
3) If both occur within a few uSec of one another, whichever is defined firet, or has it's priority set highest, will be executed first, and the other will be delayed.
4) Be aware, that if you are using a crystal oscillator, there is a very large delay, when the chip awakens, before code is executed, while the oscillator stabilises. This could give problems if latency is important on the external interrupt.

Best Wishes
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Feb 03, 2010 11:30 am     Reply with quote

PCM programmer wrote:
Post a (compilable) test program so we can see what you're talking about.


Hope you can see what I'm getting at...

(Compilable, but unknown whether it is functional...)



Code:
#include <18F2620.h>
#fuses HS, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8)
//===============================
#define INT_PERIPHERAL      0xF240  // PEIE for 18F2620
#define TIMER1_CTR_LOAD     4       // Load for the TIMER1 countdown counter (builds the wakeups to desired spacing)
#define INT_OVERHEAD_VALUE  200     // Contrived value to keep Timer1 sleep interrupts spaced correctly
//===============================
int16   gTimer1_Value       = 0;
int16   gINT_EXT_Tick       = 0;
int1    gINT_EXT_FLG        = false;
int8    gTimer1_CTR         = TIMER1_CTR_LOAD;
//===============================
#INT_EXT
void INT_EXT_ISR()
{
    gTimer1_Value   = get_timer1(); // Capture TIMER1 value here to use when we go back to sleep?
    gINT_EXT_FLG    = true;
    gINT_EXT_Tick++;
}
//===============================
void main()
{
    clear_interrupt(INT_TIMER1);
    clear_interrupt(INT_EXT);
    enable_interrupts(INT_TIMER1);
    enable_interrupts(INT_EXT);
    enable_interrupts(INT_PERIPHERAL);
   
    while(true)
    {
        if(gINT_EXT_FLG)    // Wake from INT_EXT
        {
            gINT_EXT_FLG = false;
            set_timer1(gTimer1_Value + INT_OVERHEAD_VALUE);
        }
        else                // Wake from TIMER1
        {
            if(!gTimer1_CTR--)
            {
                gTimer1_CTR = TIMER1_CTR_LOAD;
                // ----------------------------
                // Regularly spaced events here
                // To include a CCP1 / TIMER1 event
                // ----------------------------           
                gINT_EXT_Tick = 0;
                // Reconfigure TIMER1 after CCP1 use
                setup_timer_1(T1_EXTERNAL | T1_DIV_BY_4 | T1_CLK_OUT);
                // Preload timer to adjust wakeups to useable spacing
                set_timer1(4096);                                       
            }
        }
        sleep();
        delay_cycles(1); //dummy instruction for the pre-fetch
    }   
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Feb 03, 2010 11:34 am     Reply with quote

Ttelmah wrote:
Why should timer1, need to be adjusted at all?.
The timer will stay running at the same rate whether or not the processor is running.
The only errors on timing, will be:
1) If the timer interrupt occurs _while the processor is already handling the external interrupt_, then the service will be delayed till after this has completed.
2) If the external interrupt occurs while the timer interrupt is executing, it will be dleayed till the timer interrupt completes.
3) If both occur within a few uSec of one another, whichever is defined firet, or has it's priority set highest, will be executed first, and the other will be delayed.
4) Be aware, that if you are using a crystal oscillator, there is a very large delay, when the chip awakens, before code is executed, while the oscillator stabilises. This could give problems if latency is important on the external interrupt.

Best Wishes



Ahhhhh.... That makes sense. I'll need to dig into the priorities, etc and see how they'll affect what I'm doing. The timing precision isn't important. Really just looking for something to get done every 5 minutes +/- a second or two and also watch for the INT_EXT while asleep.

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