Duplicate int handlers

Moderator: Benj

Post Reply
jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Duplicate int handlers

Post by jadiflow »

Hi, me again....

If you use the Port B interrupt-on change in your program, and you enable that interrupt at two (or more) places, the compiler generates two interrupt handler subroutines. Since each int handler uses the same variables (here: char mxtmp), you get an error: 'variable already exists' and compile fails.

See attached fragment which results when both PortB int on change and TMR0 int are enabled in two places. The duplicate TMR0 does not cause an error as there is no duplicate symbol...

Code: Select all

void interrupt(void)
{
	//Handler code for [PORTB]
	char mxtmp;
	if ((intcon & (1 << RBIF)) && (intcon & (1 << RBIE)))
	{
		FCM_enc_int_service();
		mxtmp=portb;
		clear_bit(intcon, RBIF);
	}

	//Handler code for [TMR0]
	if ((intcon & (1 << T0IF)) && (intcon & (1 << T0IE)))
	{
		FCM_clk_int_service();
		clear_bit(intcon, T0IF);
	}

	//Handler code for [PORTB]
	char mxtmp;
	if ((intcon & (1 << RBIF)) && (intcon & (1 << RBIE)))
	{
		FCM_enc_int_service();
		mxtmp=portb;
		clear_bit(intcon, RBIF);
	}

	//Handler code for [TMR0]
	if ((intcon & (1 << T0IF)) && (intcon & (1 << T0IE)))
	{
		FCM_clk_int_service();
		clear_bit(intcon, T0IF);
	}
}
jan didden
Linear Audio

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Duplicate int handlers

Post by Benj »

Hello Jan

We have taken steps to fix this code duplication in the next update release of Flowcode. Let me know which chip you are using and I will provide you with a FCD file that should fix your problem until the update is released.

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Duplicate int handlers

Post by jadiflow »

Thanks Ben, I'm using the 16F886 for this. There is a workaround though; just create a macro with a single block that enables the interrupt, and call that macro everytime you want to enable it. The macro only generates a single handler, of course.

While I'm at it, have you or anyone else ever experienced problems writing to an LCD when that writing is/may be interrupted by a clock int or a ioc interrupt? I'm seeing erratic lcd behaviour (jumping cursor, non-alphabetic characters) after a few minutes of running my program, where this happens. I'm tracking an encoder with ioc and then start a clock for debouncing. Any of those interrups may occur while writing to the lcd, and I have a hunch that upsets it, but so far no hard evidence. I've cut the program down to just the encoder stuff and the lcd writing. Does it sound familiar?

jan didden

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Duplicate int handlers

Post by Benj »

Hi Jan

Ok I have included the latest version of the v4 FCD for the 886 it should get around any problems with the interrupt enable being called any number of times in your program.
16F886.fcd
(11.44 KiB) Downloaded 250 times
I have also answered your LCD problem in your other topic.

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Duplicate int handlers

Post by jadiflow »

Thank you!

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Duplicate int handlers

Post by jadiflow »

The new 886 fcd has another issue: apparently there are some definitions missing, if I use it I get the linker/assembler error:

TX control 4800bd-2.c(3666:2): error: unknown identifier 'cr_bit'
TX control 4800bd-2.c(4471:2): error: unknown identifier 'st_bit'

These are variables used in the enable interrupt routines.


jan didden

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Duplicate int handlers

Post by Benj »

Hi Jan

Ok I guess you are not using v4.2 of Flowcode. The cr and st functions are part of the changes that were put in place for the HITECH modifications that were part of v4.2. I would recommend going back to your normal component code file or updating to the latest version of Flowcode 4.

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Duplicate int handlers

Post by jadiflow »

Yes I downloaded V4.2 that works with the new 886 .fcd.

thanks,

jan didden
Linear Audio

Post Reply