Ccs _ View Topic - Enable Timer1 Interrupt In Another Isr

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Ccs _ View Topic - Enable Timer1 Interrupt In Another Isr as PDF for free.

More details

  • Words: 1,074
  • Pages: 4
CCS :: View topic - Enable Timer1 interrupt in another ISR?

FAQ

Forum Help Profile

Official CCS Support

http://ccsinfo.com/forum/viewtopic.php?t=28343&highlight=inte...

Search

Register

Log in to check your private messages

Log in

Enable Timer1 interrupt in another ISR? CCS Forum Index -> General CCS C Discussion View previous topic :: View next topic Author pe1icq

Message Enable Timer1 interrupt in another ISR? Posted: Fri Sep 29, 2006 10:41 am

Joined: 29 Aug 2005 Posts: 9

Hi, Can I setup and enable a Timer1 interrupt in another ISR? What I'm trying to accomplish is starting Timer1 in the ISR that handles the PortA change interrupts. I've tried several things but I can't get it to work. This is what I have: Code: #define INTS_PER_MINUTE 114 int8 minutes; int8 int_count;

// (4000000/(4*8*65536)) * 60

// A running minutes counter // Number of interrupts left before a minute has elapsed

#PRIORITY TIMER1,RA #INT_TIMER1 void clock_isr() {

// This function is called every time // timer 1 overflows (65535->0), which is // approximately 1.9 times per second for // this program. output_high(pin_a3); // Green LED if(--int_count==0) { ++minutes; int_count = INTS_PER_MINUTE; } if (minutes==2) { output_high(pin_a5); // delay_ms(1000); // output_low(pin_a5); }

} #INT_RA void porta_change_isr() { delay_us(250); if (!input(PIN_A4)) { disable_interrupts(INT_TIMER1); output_low(pin_a5); // Red LED } if (input(PIN_A4)) { int_count = INTS_PER_MINUTE; minutes = 0; setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); set_timer1(0);

1 от 4

01.3.2007 г. 09:55

CCS :: View topic - Enable Timer1 interrupt in another ISR?

http://ccsinfo.com/forum/viewtopic.php?t=28343&highlight=inte...

enable_interrupts(INT_TIMER1); output_high(pin_a5); // Red LED } #use fast_io(a) input_a(); // dummy read }

I can get in an out of the RA ISR. The LED on pin_a5 goes on and off. However Timer1 does not seem to be running, and I never get into the Timer1 ISR (I.e. the debug LED on pin_a3 never goes on) What am I doing wrong? BR. //Arno newguy

Joined: 24 Jun 2004 Posts: 557 Location: Edmonton AB Canada

Posted: Fri Sep 29, 2006 11:25 am

Stupid question, but did you configure timer 1 to run? ie. Code: setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);

pe1icq

Joined: 29 Aug 2005 Posts: 9

PCM programmer

Joined: 06 Sep 2003 Posts: 6775

pe1icq

Joined: 29 Aug 2005 Posts: 9

PCM programmer

Joined: 06 Sep 2003 Posts: 6775

Posted: Fri Sep 29, 2006 12:28 pm

Yes I did. It is in the #INT_RA ISR. I also tried putting it in main() but that did not make a difference.

Posted: Fri Sep 29, 2006 1:20 pm

What PIC are you using, and what's your compiler version ?

Posted: Fri Sep 29, 2006 1:51 pm

PIC16F684 and PCM compiler version 3.229 (Linux)

Posted: Fri Sep 29, 2006 2:37 pm

Can you post a main() function, with all of your setup code for the timer, and the port i/o pins, comparators, etc., ? Please show the #fuses, #use, and applicable #define statements. In other words, I want to drop the code into MPLAB and have it compile with no errors. Then I can look at it.

2 от 4

01.3.2007 г. 09:55

CCS :: View topic - Enable Timer1 interrupt in another ISR?

pe1icq

Joined: 29 Aug 2005 Posts: 9

http://ccsinfo.com/forum/viewtopic.php?t=28343&highlight=inte...

Posted: Fri Sep 29, 2006 2:39 pm

Well... it would help if I would select a port for the debug LED that actually can be used as an output. RA3 isn't one of those. I swapped RA3 and RA4 and now everything is working fine. I still have one question. Do I explicitely need to clear the interrupt flags, or does the compiler take care of that for me? I now have some clear_interrupt() statements in the ISR as shown below. Are those really needed? Code: #INT_RA void porta_change_isr() { delay_ms(200); if (!input(PIN_A3)) { disable_interrupts(INT_TIMER1); output_low(pin_a5); // Red LED } if (input(PIN_A3)) { int_count = INTS_PER_MINUTE; minutes = 0; setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); set_timer1(0); clear_interrupt(INT_TIMER1); enable_interrupts(INT_TIMER1); output_high(pin_a5); // Red LED } clear_interrupt(INT_RA); }

newguy

Joined: 24 Jun 2004 Posts: 557 Location: Edmonton AB Canada

Posted: Fri Sep 29, 2006 2:41 pm

Clearing the interrupt is absolutely required. The compiler doesn't take care of that for you. If a timer is enabled, it will set its overflow flag when it overflows regardless of whether its interrupt is enabled. Whoops - have to clarify. If you enable the timer interrupt, you must clear any outstanding timer interrupts. As PCM has said, no need to clear the other one - the compiler does that automatically. Last edited by newguy on Fri Sep 29, 2006 3:19 pm; edited 1 time in total

PCM programmer

Joined: 06 Sep 2003 Posts: 6775

Posted: Fri Sep 29, 2006 2:55 pm

You don't need to clear the RA interrupt flag at the end of the isr. The compiler automatically puts in a line of ASM code to do that for you. See the lines shown in bold below. Quote: .................... } .................... clear_interrupt(INT_RA); 0088: BCF 0B.0.................... } .................... .................... 0089: BCF 0B.0 008A: BCF 0A.3 008B: GOTO 02B

rnielsen

Joined: 23 Sep 2003 Posts: 430 Location: Utah

Posted: Fri Sep 29, 2006 5:09 pm

You can turn on/off a timer from anywhere in your code, including an ISR. Simply set/clear the bit that enables the timer. Ronald

3 от 4

01.3.2007 г. 09:55

CCS :: View topic - Enable Timer1 interrupt in another ISR?

Neutone

Joined: 08 Sep 2003 Posts: 1104 Location: Houston

http://ccsinfo.com/forum/viewtopic.php?t=28343&highlight=inte...

Posted: Sat Sep 30, 2006 5:12 pm

pe1icq wrote: Do I explicitely need to clear the interrupt flags, or does the compiler take care of that for me? Code:

set_timer1(0); clear_interrupt(INT_TIMER1); enable_interrupts(INT_TIMER1);

That first line of code will set the counter to zero the second line will clear the interupt flag that may have already been set by an overflow of timer 1 counter. The third line will enable interupt if the timer interupt flag is set. If you dont clear the interupt flag before enabeling the interupt it might jump to the timer 1 interupt routine as soon as it leaves the RA interupt. Display posts from previous: All Posts

Oldest First

CCS Forum Index -> General CCS C Discussion

Go All times are GMT - 6 Hours

Page 1 of 1 Jump to: General CCS C Discussion You can post new topics You can reply to topics You cannot edit your posts You cannot delete your posts You cannot vote in polls

Go in in in in in

this this this this this

forum forum forum forum forum

Powered by phpBB © 2001, 2005 phpBB Group

4 от 4

01.3.2007 г. 09:55

Related Documents