View previous topic :: View next topic |
Author |
Message |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
PIC16f1825 wakeup from Comparator |
Posted: Tue Jun 18, 2019 7:53 am |
|
|
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
|
|
Posted: Tue Jun 18, 2019 9:33 am |
|
|
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
|
|
Posted: Tue Jun 18, 2019 9:51 am |
|
|
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 |
|
|
|