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

PIC16f1825 wakeup from Comparator

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



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PIC16f1825 wakeup from Comparator
PostPosted: Tue Jun 18, 2019 7:53 am     Reply with quote

CCS 5.076

Trying to get the PIC to wake up from comparator interrupt without success.
Comparator works perfect when not in sleep.
Here are the code
Code:
#include <16F1825.h>
#device ADC=10

#FUSES NOMCLR
#use delay(internal=32000000)


#define LED PIN_A2
#include <stdint.h>
#byte CM2CON0 = getenv("SFR:CM2CON0")

void main() {
  uint16_t Cnt;
  output_high(LED);
  delay_ms(500);
  output_toggle(LED);
  delay_ms(500);
  output_toggle(LED);
  delay_ms(500);
  output_low(LED);
  setup_timer_2(T2_DIV_BY_1,252,8);      //126 us overflow, 1.0 ms interrupt

  setup_comparator(CP2_C2_C0 | CP2_INVERT | CP2_INT_L2H);

  enable_interrupts(INT_COMP2);
//  enable_interrupts(GLOBAL);

   while(TRUE) {
    //This are to prove that the comparator are actually working by toggling a LED when an interrupt occurs
    if (interrupt_active(INT_TIMER2)) {
     clear_interrupt(INT_TIMER2);
     if (interrupt_active(INT_COMP2)) {
       clear_interrupt(INT_COMP2);
         output_toggle(LED);
     }
    }
    Cnt = CM2CON0;   
    clear_interrupt(INT_COMP2);
    sleep();
    //To check when it comes out of sleep
    delay_cycles(1);
    output_toggle(LED);
    delay_ms(500);
    output_toggle(LED);
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 18, 2019 9:33 am     Reply with quote

Here is part of the interrupt list from the 16F1825.h file.
The one you need is shown in bold. Enable it. This one
acts as a gate for the comparator interrupt and others.
Quote:

#define GLOBAL 0x0BC0
#define PERIPH 0x0B40
#define INT_EXT_L2H 0x50000B10
#define INT_EXT_H2L 0x60000B10
#define INT_EXT 0x300B10
#define INT_TIMER0 0x300B20
#define INT_TIMER1 0x309101
#define INT_TIMER2 0x309102
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Tue Jun 18, 2019 9:51 am     Reply with quote

Well done PCM.
Armed with this info I looked through the datasheet again and noticed it, probably won't forget this one in a while, and even then I probably would have used the getenv to locate the bit.

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