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

interrupt on overflow

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 10, 2006 9:42 pm     Reply with quote

I assume you have a 32 KHz crystal on the Timer1 oscillator pins. Here
is a demo program that will wake-up 2 seconds after it goes to sleep.
It sets Timer1 = 0, so it will take 2 seconds to count up to 0xFFFF and
overflow.

The key to making this program work, is to understand that there is
an additional enable bit that must be set to let Timer1 interrupts
wakeup the PIC. It's the PEIE bit in the INTCON register. CCS doesn't
have a constant defined for this bit in the PIC's .H file. CCS includes
the PEIE bit with the GIE bit when you do "enable_interrupts(GLOBAL)".

Apparently CCS didn't anticipate that anyone would want to wake-up
on just a peripheral interrupt, without having global interrupts enabled.
But anyway, you can add a constant for it as shown below. Then it
works. I tested this with PCM vs. 3.249 on a PicDem2-Plus board.
Code:

#include <16F877.H>
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define INT_PERIPHERAL  0x0B40     // For 16F877
   
//===============================
void main()
{
printf("Start\n\r");   
   
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);

set_timer1(0);

clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_PERIPHERAL);

sleep();

printf("Woke up from sleep\n\r");
     
while(1);     
}     
Guest








PostPosted: Wed Sep 13, 2006 5:16 am     Reply with quote

First of all i must thank all posters ( Ttelmah, jecottrell, PCM Programmer ) on great wish for helping. Becuse of you guys, this compiler is workin and getting better and better.

@ PCM Programmer:
Your code is working perfetcly on 16F877 !! .
After i have switched to 16f917, changed the clock to 8 mhz and changed the INT_AD to 0x8C40, the problem is the same...

I can reach the part before sleep but then again when i reach sleep () ,program gets stuck ( no wakeup ). I dont know ....
Ttelmah
Guest







PostPosted: Wed Sep 13, 2006 5:58 am     Reply with quote

INT_AD???...
The only devices that can wake you up from sleep, are those that run when the unit is asleep. The ADC, will only do so, if it is running off it's RC clock. To sleep while a conversion is being done, you would have to use:
Code:

setup_adc(ADC_CLOCK_INTERNAL); //use RC clock
disable_interrupts(global); //prevent interrupts from calling a handler
enable_interrupts(INT_AD); //Enable the interrupt you want to wake up
clear_interrupts(INT_AD); //Make sure it is clear (otherwise no sleep)
read_ADC(ADC_START_ONLY); //start the ADC
sleep(); //sleep till the ADC conversion completes
delay_cycles(1); //dummy instruction for the pre-fetch


This will wake up and continue when the ADC conversion has completed.

Best Wishes
Mat
Guest







PostPosted: Thu Sep 14, 2006 10:05 am     Reply with quote

Quote:
INT_AD ???

My mistake, wrong thema. Sorry !

Anyway i tried code from Ttelmah and changed code from pcm programmer and both of those codes get freezed when program reaches sleep. There is no problem on the F877... just on F917.

Code:
#include <16F917>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=8000000)
#include "lcd.c"
#define INT_PERIPHERAL 0x0B40   // 2864

#byte T1CON   = 0x10         // timer 1
#byte INTCON  = 0x0B         // Intcon
#byte PIE1    = 0x8C         // PIE

#bit  TMR1ON  = T1CON.0         // 0 Bit --> Timer1 - 1/8
#bit  PEIE     = INTCON.6      // PEIE
#bit  GIE     = INTCON.7      // GIE
#bit  TMR1IE  = PIE1.0         // TMR1IE
//===============================
void main()
{
   TMR1IE = 1;
   GIE    = 1;
   PEIE   = 1;
   
   lcd_init();
   setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);
   set_timer1(0);

   clear_interrupt(INT_TIMER1);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_PERIPHERAL);

   output_high(PIN_B0); delay_ms(300); output_low(PIN_B0);
   printf(lcd_putc,"Sleep...\n\r");
   sleep();
   printf(lcd_putc,"Woked up \n\r");
while(1);     
}     
Mat
Guest







PostPosted: Mon Sep 18, 2006 9:02 am     Reply with quote

I changed bunch of stuff to get this working but again program freezes in sleep part... Now im really out of idea...

Code:
#include <16F917>
#fuses EC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=8000000)
#include "lcd.c"
//===============================
#byte T1CON   = 0x10         // timer 1 control registar
#byte INTCON  = 0x0B         // Intcon
#byte PIE1    = 0x8C         // PIE
#byte PIR1     = 0xC            //

#bit  TMR1IE  = PIE1.0         // TMR1IE
#bit  TMR1IF  = PIR1.0         // Timer1 interrupt flag
#bit  TMR1ON  = T1CON.0         // 0 Bit --> Timer1 - 1/8
#bit  T1SYNC  =   T1CON.2         // Timer 1 sync / async bit   
#bit  PEIE     = INTCON.6      // PEIE
#bit  GIE     = INTCON.7      // GIE
//===============================
void main()
{
   int tick;
   GIE    = 0;         // Global Interrupt Enable bit        --> OFF
   PEIE   = 1;         // Peripheral Interrupt Enable bit     --> ON
   T1SYNC = 1;       // Do not synchronize ext.clock input --> ON
   TMR1IE = 1;         // Timer1 overflow interrupt enable     --> ON

   //---------------
   
   lcd_init();
   setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);
   //---------------

    tick=915;
   printf(lcd_putc,"Sleep...\n\r");  output_high(PIN_B0); delay_ms(300); output_low(PIN_B0);   
    do {
      TMR1IE = 1;         // timer1 interrupt enable         --> ON
      TMR1IF = 0;         // delete timer1 interrupt flag      --> ON
      set_timer1(0);
        sleep();
    } while (tick--);
   printf(lcd_putc,"Woked up \n\r"); output_high(PIN_B1); delay_ms(300); output_low(PIN_B1);
}     

Twisted Evil Twisted Evil
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