Page 1 of 1

Duplicate int handlers

Posted: Wed Jan 27, 2010 2:52 pm
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

Re: Duplicate int handlers

Posted: Wed Jan 27, 2010 3:42 pm
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.

Re: Duplicate int handlers

Posted: Thu Jan 28, 2010 10:21 am
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

Re: Duplicate int handlers

Posted: Thu Jan 28, 2010 12:16 pm
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 296 times
I have also answered your LCD problem in your other topic.

Re: Duplicate int handlers

Posted: Thu Jan 28, 2010 1:54 pm
by jadiflow
Thank you!

Re: Duplicate int handlers

Posted: Thu Jan 28, 2010 2:13 pm
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

Re: Duplicate int handlers

Posted: Thu Jan 28, 2010 4:30 pm
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.

Re: Duplicate int handlers

Posted: Sun Jan 31, 2010 11:40 am
by jadiflow
Yes I downloaded V4.2 that works with the new 886 .fcd.

thanks,

jan didden
Linear Audio