Helpful ReplyHot!Interrupt during interrupt routine

Author
ntendayip
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/10/09 10:09:55
  • Location: 0
  • Status: offline
2017/10/11 13:15:41 (permalink)
0

Interrupt during interrupt routine

Hi I am new to program a MCU, currently I am working on using interrupt to wake pic16lf1619 from sleep mode  I am using xc8 and mplab v3.60 ,below is my attempting code:
void main(void)
{
//
SYSTEM_Initialize;

timer1_init;

PIE1bits.TMR1IE = 1; // enable timer1
INTCONbits.PEIE = 1; // enable peripheral interrupt
TMR1H = 0X00;
TMR1L = 0X00;

INTCONbits.GIE = 1; //enable global interrupt
T1CONbits.TMR1ON = 1; //start timer
TRISC = 0;

//perform main program

while(1)
{

SLEEP();
// LED7_LAT=1;

}

}
void interruptISR(void){

if(TMR1IF==1)
{
LED6_LAT = 1; //perform ISR tasks


TMR1IF = 0;

}
if(ADIF==1){
//... ..
}
}
the LED just stays on.I don't know what I am doing wrong.Can someone help me figure out this please
 
#1
qhb
Superb Member
  • Total Posts : 6209
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Interrupt during interrupt routine 2017/10/11 16:41:36 (permalink)
+2 (2)
This does NOT specify an interrupt service.
void interruptISR(void){

 
try
void interrupt ISR(void){

 
 
 
 
#2
ntendayip
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/10/09 10:09:55
  • Location: 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/12 10:39:45 (permalink) ☄ Helpfulby stumichaels 2017/11/10 21:28:55
0
Hi thank you for replying.When I write:void interrupt ISR(void), I get this :main.c:104:  error: (1506) multiple interrupt functions (_ISR and _INTERRUPT_InterruptManager) defined at interrupt level 1.
#3
1and0
Access is Denied
  • Total Posts : 7087
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/12 11:43:44 (permalink)
+1 (1)
Look like you have two interrupt functions.  Your LED stays on because your code in Post #1 does not turn the LED off.
#4
qhb
Superb Member
  • Total Posts : 6209
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Interrupt during interrupt routine 2017/10/12 12:10:08 (permalink)
+1 (1)
Are you using MCC to write your code?
If so, you should have mentioned it. It appears that MCC has already created an interrupt service routine, and you should be using that.
#5
ntendayip
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/10/09 10:09:55
  • Location: 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/12 13:10:12 (permalink)
0
Is anyone might have solve this issue to help me out.any resources , example will be helpful to learn and solve this.if I can state the issue, again:I am trying to use interrupt(TMR1) to wake up a pic16lf1619 from sleep.and was wondering if I will need an external clock or internal clock will be just fine.Help please
#6
Ewerning
Super Member
  • Total Posts : 77
  • Reward points : 0
  • Joined: 2017/09/08 11:02:31
  • Location: Between 1 and 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/12 14:00:54 (permalink)
+1 (1)
Please read the data sheet. It cleary states in what situations this would work. Remember that during a sleep operation the system clock is turned off. If TMR1 is bonded to this clock source ... It stops counting! Consider using the WDT to wake the processor from sleep.
post edited by Ewerning - 2017/10/12 14:02:31
#7
qhb
Superb Member
  • Total Posts : 6209
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Interrupt during interrupt routine 2017/10/12 14:03:10 (permalink)
+1 (1)
It doesn't matter which clock you use, you can do it either way.
You just have to get an interrupt service routine working correctly.
You ignored my question about MCC.
 
Note, if your only aim is to wake up from sleep, you don't even need to use an interrupt service. Read about how sleep works again. If interrupts are disabled (GIE=0), it will just start running from after the sleep instruction.
See: "7.3 Interrupts During Sleep" in the datasheet.
 
#8
qhb
Superb Member
  • Total Posts : 6209
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Interrupt during interrupt routine 2017/10/12 14:14:10 (permalink) ☄ Helpfulby LightDiodeDesignsUK 2017/10/13 15:25:50
+1 (1)
Ewerning
...
Remember that during a sleep operation the system clock is turned off. If TMR1 is bonded to this clock source ... It stops counting!

+1
I was concentrating on the interrupt problem, and forgot about this.
The code presented is never writing to the TMR1CS bits in the T1CON register.
The default value is 0b00, which selects Fosc/4, which will stop in sleep mode, so the wakeup will never occur.
Try changing them to 0b11 (LFINTOSC) if you want to the timer to count in sleep mode.
 
#9
ntendayip
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/10/09 10:09:55
  • Location: 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/13 04:44:18 (permalink)
0
Just figure out that I had MCC interrupt running as well.I turn off now  there is no more error.This is what I am using now before your new comment:
 
void main(void)
{
//
SYSTEM_Initialize;

PIE1bits.TMR1IE = 1; // enable timer1
INTCONbits.PEIE = 1; // enable peripheral interrupt
TMR1H = 0X00;
TMR1L = 0X00;

INTCONbits.GIE = 1; //enable global interrupt
T1CONbits.TMR1ON = 1; //start timer
TRISC = 0;
TRISA = 0;

//perform main program

while(1)
{

// SLEEP();
LED7_LAT = 1;

}

}

void interrupt ISR(void){

if (PIR1bits.TMR1IF==1) {

PIR1bits.TMR1IF=0;

if ( PIE1bits.TMR1IE==1) {

LED6_LAT = 1; //perform ISR tasks
__delay_ms(10000);
LED6_LAT = 0;
__delay_ms(10000);


TMR1H = 0x80;
TMR1L = 0x00;
}
}





}
 
I just wanted to see first if the interrupt was working , I see it working.I will take ur advice to see when replace the SLEEP(); instruction see if it wakes up if not I will use the watch dog to do the job.Thanks for the reply.Keep status 
#10
qhb
Superb Member
  • Total Posts : 6209
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Interrupt during interrupt routine 2017/10/13 04:47:39 (permalink)
+1 (1)
ntendayip
Just figure out that I had MCC interrupt running as well.
...

I told you that back in post#5.
#11
ntendayip
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/10/09 10:09:55
  • Location: 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/13 05:24:43 (permalink)
0
is there anyway to provide the time to wake up from sleep mode or leave the mcu in sleep and wake up with an instruction
#12
1and0
Access is Denied
  • Total Posts : 7087
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/13 06:12:46 (permalink)
+1 (1)
ntendayip
is there anyway to provide the time to wake up from sleep mode or leave the mcu in sleep and wake up with an instruction

The watchdog timer has a time-out period from 1 ms to 256 seconds (nominal).
 
#13
Ewerning
Super Member
  • Total Posts : 77
  • Reward points : 0
  • Joined: 2017/09/08 11:02:31
  • Location: Between 1 and 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/13 12:44:48 (permalink)
0
ntendayip
is there anyway to provide the time to wake up from sleep mode or leave the mcu in sleep and wake up with an instruction


Hypothetical code to think about what would happen...
Disclaimer: The code contains commands that do not exist and is not intended to run or whatever, the intention is to think about what would happen.

...
SLEEP
Delay_ms (250)
WAKE_UP
...
#14
Gort2015
Klaatu Barada Nikto
  • Total Posts : 1471
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/10/13 18:03:37 (permalink)
+1 (1)
Not much.  WDT will help you.
Look at the datasheet about setting up the WDT since you can't set it like you can with a timer.  You can en/disable it.
It has to be configured as bit/s written into the chip when burning.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#15
ntendayip
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/10/09 10:09:55
  • Location: 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/11/09 08:51:19 (permalink)
0
Hi everyone,
Thanks for the previous reply, it was helpful.
I am working on different project just in order to practice.the idea is to create a countdown or count up clock that will stop counting once the light sensor detect light.I am using pic16lf1619,at this point I am reading the data sheet and putting ideas together.I was wondering if anyone may help on the code set up or any resources beside the data sheet that may help to understand and get this practice accomplish
#16
projector
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2017/11/08 14:13:41
  • Location: 0
  • Status: offline
Re: Interrupt during interrupt routine 2017/11/10 13:07:43 (permalink)
0
To wake up from SLEEP you can only use external interrupt wired to one of the INT ports, this is because the osc is off.
#17
jtemples
Super Member
  • Total Posts : 10278
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Interrupt during interrupt routine 2017/11/10 18:27:38 (permalink)
+4 (4)
To wake up from SLEEP you can only use external interrupt wired to one of the INT ports, this is because the osc is off.

 
No, there are many sources to wake from sleep.  WDT, TMR1 with external clock, comparators, MSSP, UART, etc.
#18
Jump to:
© 2017 APG vNext Commercial Version 4.5