Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to handle two interrupts in different modules

Status
Not open for further replies.

romel_emperado

Advanced Member level 2
Joined
Jul 23, 2009
Messages
606
Helped
45
Reputation
132
Reaction score
65
Trophy points
1,318
Location
philippines
Activity points
6,061
Guys I have two modules namely pwm.c and frequency.c.

In pwm.c Im using timer 0 interrupt for my software pwm and in frequency.c Im using the CCP module interrupt..



the code works pretty well if I comment one of the interrupt and compile it..


here is the error..

symbol "int_func" defined more than once

how to deal this issue?

Thanks so much

---------- Post added at 12:37 ---------- Previous post was at 12:36 ----------

this is my software pwm interrupt.


PHP:
void interrupt softPWM()
{


	
	if(TMR0IF) //Check if it is TMR0 Overflow ISR
	{
		
		if(!pwm_flag) //Start of High level
		{ 
                pwm_flag = 1;   //Set flag
                PWMPIN = 1;     //Set PWM o/p pin
                TMR0 = pwm_width;        //Load timer
                
        }
        else  //Start of Low level
		{  
				pwm_flag = 0;   //Clear flag
                
				PWMPIN = 0; //Clear PWM o/p pin
				TMR0 = 255 - pwm_width;  //Load timer
        }	

		TMR0IF = 0; //Clear Interrupt flag
	}

	
}




CCP module interrupt.

PHP:
void interrupt frequency()
{
	static bit pulse_state = 0;


	if(PIR1bits.TMR1IF) //timer1 overflow
	{
		PIR1bits.TMR1IF = 0; //clear flag
		FQ = 0;
	}
	
	if(PIR1bits.CCP1IF) //event captured
	{
		PIR1bits.CCP1IF = 0;
	

		switch(pulse_state)
		{
			case 0:
			pulse_state = 1;
		 	TMR1L = 0;
			TMR1H = 0;
			break;

			case 1:
			counter = TMR1L;            // Get the first 8-bit TIMER0 Counter
        	counter += (TMR1H << 8);    // Get the last 8-bit TIMER0 Counter
			FQ = (unsigned int)(1000.0/(counter * 0.000333));
			pulse_state = 0;
		}
	}
}


---------- Post added at 12:40 ---------- Previous post was at 12:37 ----------

the problem is the whole code works without using two interrupts.. I can only use 1 interrupt

---------- Post added at 12:40 ---------- Previous post was at 12:40 ----------

I tried using two intrrupts before but it is in one module and it works..
 

different in my case.

by the way.. everything is okay now I joined the two interrupts in one file but I just wan't to know the reasons why I can't place interrupt in the other module of my code.. ;)
 

You have reported that you get symbol "int_func" defined more than once and I think is because you have two handlers for the same interrupt as described in the link I have provided.
I may be wrong because I'm not familiar with your mcu.

Alex

---------- Post added at 16:54 ---------- Previous post was at 16:49 ----------

I have also found problem of adc in pic
it is related to PIC16
 
Im confused why Im getting that error because the name of my interrupt is not the same..

yes I have two interrupt handler but why it is working if I joined the two interrupts in a single file.. let say interrupt.c



let's talk with AVR since I know you are familiar with that mcu.

Have tried making two interrupt handler in a separate file like InterruptA.c and interruptB.c
 

Actually I haven't :roll: , I write the main code in a single unit , only libraries like LCD, SPI, etc.are in different files but I don't have interrupts in them.

Alex
 
okay.. got it.. I think the same with PIC18 because Im using PIC18..

I found this reply from your link

A PIC16 can have only one interrupt function. You have to combine timer interrupt and ADC interrupt handling into one interrupt function and check their individual interrupt flags to know which interrupt is pending.


---------- Post added at 16:13 ---------- Previous post was at 16:01 ----------

What I did is the right thing..

I combined the monitoring of the interrupts in single interrupt Handler..


This way worked..! i think we are not allowed to make another Interrupt handler.. I dont know.. I think it's in the manual of the compiler.... lol hehehe
PHP:
void interrrupt MyInterrupt()
{
    if(interruptA)
   {
      //some code here
   }

   if(interruptB)
   {

    //some code here
   }


}
 

Actually I'm reading a couple of articles and they state that PIC16 has only one interrupt vector address 4h

but for PIC18 they say that there is high priority and a low priority

PIC18 microcontrollers have high priority and low priority interrupts. When a high or low priority interrupt occurs, the program counter is loaded with the address of the respective interrupt vector and the program branches to the interrupt vector. The high priority interrupt vector is 8h, and the low priority interrupt vector is 18h.

Alex
 
By the way,ATmega devises have multiple interrupt vectors.
For example mega8

1 0x000 RESET External Pin, Power-on Reset, Brown-out Reset, and Watchdog Reset
2 0x001 INT0 External Interrupt Request 0
3 0x002 INT1 External Interrupt Request 1
4 0x003 TIMER2 COMP Timer/Counter2 Compare Match
5 0x004 TIMER2 OVF Timer/Counter2 Overflow
6 0x005 TIMER1 CAPT Timer/Counter1 Capture Event
7 0x006 TIMER1 COMPA Timer/Counter1 Compare Match A
8 0x007 TIMER1 COMPB Timer/Counter1 Compare Match B
9 0x008 TIMER1 OVF Timer/Counter1 Overflow
10 0x009 TIMER0 OVF Timer/Counter0 Overflow
11 0x00A SPI, STCSerial Transfer Complete
12 0x00B USART, RXCUSART, Rx Complete
13 0x00C USART, UDREUSART Data Register Empty
14 0x00D USART, TXCUSART, Tx Complete
15 0x00E ADC ADC Conversion Complete
16 0x00F EE_RDYEEPROM Ready
17 0x010 ANA_COMP Analog Comparator
18 0x011 TWI Two-wire Serial Interface
19 0x012 SPM_RDY Store Program Memory Ready

this allows nested interrupts when needed.

Alex
 
Im learning AVR.. if you still remember I hve a thread here with my first blinking LEd program. I will update that thread as soon I have enough time.. I will setup my environment for my AVR learning..

setting registers with avr is opposite with PIC and 8051 as I noticed ;)
 

hi alexan e

Thanks for the help..

This is solved I forgot to update the thread.


I did something like this.


PHP:
void interrupt interrupthandler()
{

       //first interupt here

     //second interrupt


    //third interrupt


}

Then I just controlled the priority of interrupts.

The reason is PIC16/18 has has only one interrupt handler..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top