PIC16F1847.fcd PORTB on change IRQ parameters are wrong

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

User avatar
mytekcontrols
Posts: 89
Joined: Sun Aug 19, 2007 6:38 pm
Location: Santa Rosa, California
Has thanked: 3 times
Been thanked: 6 times
Contact:

PIC16F1847.fcd PORTB on change IRQ parameters are wrong

Postby mytekcontrols » Thu Jun 23, 2016 7:38 pm

I'm trying to use the PortB on change interrupt and got the following errors when compiling...

Code: Select all

TK-II-OS_V1_6.c(540:23): error: unknown identifier 'RBIE'
TK-II-OS_V1_6.c(540:23): error: invalid operand 'RBIE'
TK-II-OS_V1_6.c(540:18): error: failed to generate expression
TK-II-OS_V1_6.c(540:18): error: invalid operand '<<'
TK-II-OS_V1_6.c(540:12): error: failed to generate expression
TK-II-OS_V1_6.c(578:24): error: unknown identifier 'RBIE'
TK-II-OS_V1_6.c(578:24): error: invalid operand 'RBIE'
TK-II-OS_V1_6.c(578:19): error: failed to generate expression
TK-II-OS_V1_6.c(578:15): error: invalid operand '~(1 << ( RBIE))'
TK-II-OS_V1_6.c(578:12): error: failed to generate expression
TK-II-OS_V1_6.c(6217:26): error: unknown identifier 'RBIF'
TK-II-OS_V1_6.c(6217:26): error: invalid operand 'RBIF'
TK-II-OS_V1_6.c(6217:21): error: failed to generate expression
TK-II-OS_V1_6.c(6217:21): error: invalid operand '<<'
TK-II-OS_V1_6.c(6217:16): error: failed to generate expression
TK-II-OS_V1_6.c(6217:57): error: unknown identifier 'RBIE'
TK-II-OS_V1_6.c(6217:57): error: invalid operand 'RBIE'
TK-II-OS_V1_6.c(6217:52): error: failed to generate expression
TK-II-OS_V1_6.c(6217:52): error: invalid operand '<<'
TK-II-OS_V1_6.c(6217:47): error: failed to generate expression
TK-II-OS_V1_6.c(6217:16): error: invalid operand '& '
TK-II-OS_V1_6.c(6217:47): error: invalid operand '& '
TK-II-OS_V1_6.c(6217:34): error: failed to generate expression
TK-II-OS_V1_6.c success


So apparently the definitions in the FCD file are incorrect for the PIC16F1847, since the enable bit for the IRQ should have been INTCON.3 not RBIE. And the IRQ Flag bits are actual located at IOCBF not RBIF. This looks like code that came from an earlier PIC series chip.

So here's what I see in the FCD file at this time. Can someone describe how I would modify this to reflect the 1847's needs as pertaining to the PortB interrupt on change?

Code: Select all

[PORTB]
Name="PORT"
FlagReg=
FlagBit=
HandlerCode="#ifndef MX_INTHANDLER_intcon_RBIF\n#define MX_INTHANDLER_intcon_RBIF\nchar mxtmp;\nif (ts_bit(intcon, RBIF) && ts_bit(intcon, RBIE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\t\n\tFCM_%n();\n\tmxtmp=portb;\n\tcr_bit(intcon, RBIF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"
UseExplicitHandlerCode=1
UseExplicitEnableCode=1
EnReg=
EnBit=
EnableCode="st_bit(intcon, RBIE);\n"
DisableCode="cr_bit(intcon, RBIE);\n"
OptCnt=0


Thank you,

Michael
Michael St. Pierre
FlowCode V3&V4 Pro Registered User
Manufacture: Heat Load Controllers,
and a variety of other widgets.

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

Re: PIC16F1847.fcd PORTB on change IRQ parameters are wrong

Postby Benj » Mon Jun 27, 2016 11:14 am

Hi Michael,

It is this line in the definition file that will need changing.

Code: Select all

HandlerCode="#ifndef MX_INTHANDLER_intcon_RBIF\n#define MX_INTHANDLER_intcon_RBIF\nchar mxtmp;\nif (ts_bit(intcon, RBIF) && ts_bit(intcon, RBIE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\t\n\tFCM_%n();\n\tmxtmp=portb;\n\tcr_bit(intcon, RBIF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"


This should hopefully work,

Code: Select all

HandlerCode="#ifndef MX_INTHANDLER_intcon_RBIF\n#define MX_INTHANDLER_intcon_RBIF\nchar mxtmp;\nif (ts_bit(intcon, IOCF) && ts_bit(intcon, IOCE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\t\n\tFCM_%n();\n\tmxtmp=portb;\n\tcr_bit(intcon, IOCF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"


These lines will also need updating.

Code: Select all

EnableCode="st_bit(intcon, RBIE);\n"
DisableCode="cr_bit(intcon, RBIE);\n"


to something like this.

Code: Select all

EnableCode="st_bit(intcon, IOCE);\n"
DisableCode="cr_bit(intcon, IOCE);\n"
These users thanked the author Benj for the post:
mytekcontrols (Tue Jun 28, 2016 6:07 pm)
Rating: 5.56%
 

User avatar
mytekcontrols
Posts: 89
Joined: Sun Aug 19, 2007 6:38 pm
Location: Santa Rosa, California
Has thanked: 3 times
Been thanked: 6 times
Contact:

Re: PIC16F1847.fcd PORTB on change IRQ parameters are wrong

Postby mytekcontrols » Tue Jun 28, 2016 6:12 pm

Hi Ben,

Thank you for taking the time to try to help me with this problem :)

I made the changes you suggested, and we are probably getting close, but I think there are some definitions that need to be added to the 1847.fcd to fully implement it. Here's what I get when trying to compile after the changes, and by simply adding an Enable Port IRQ and a Disable Port IRQ to my flowcode program...

Code: Select all

TK-II-OS_V1_6.c(581:24): error: unknown identifier 'IOCE'
TK-II-OS_V1_6.c(581:24): error: invalid operand 'IOCE'
TK-II-OS_V1_6.c(581:19): error: failed to generate expression
TK-II-OS_V1_6.c(581:15): error: invalid operand '~(1 << ( IOCE))'
TK-II-OS_V1_6.c(581:12): error: failed to generate expression
TK-II-OS_V1_6.c(671:23): error: unknown identifier 'IOCE'
TK-II-OS_V1_6.c(671:23): error: invalid operand 'IOCE'
TK-II-OS_V1_6.c(671:18): error: failed to generate expression
TK-II-OS_V1_6.c(671:18): error: invalid operand '<<'
TK-II-OS_V1_6.c(671:12): error: failed to generate expression
TK-II-OS_V1_6.c(5577): error: left operand must be l-value
TK-II-OS_V1_6.c(5577:9): error: failed to generate expression
TK-II-OS_V1_6.c(7267:26): error: unknown identifier 'IOCF'
TK-II-OS_V1_6.c(7267:26): error: invalid operand 'IOCF'
TK-II-OS_V1_6.c(7267:21): error: failed to generate expression
TK-II-OS_V1_6.c(7267:21): error: invalid operand '<<'
TK-II-OS_V1_6.c(7267:16): error: failed to generate expression
TK-II-OS_V1_6.c(7267:57): error: unknown identifier 'IOCE'
TK-II-OS_V1_6.c(7267:57): error: invalid operand 'IOCE'
TK-II-OS_V1_6.c(7267:52): error: failed to generate expression
TK-II-OS_V1_6.c(7267:52): error: invalid operand '<<'
TK-II-OS_V1_6.c(7267:47): error: failed to generate expression
TK-II-OS_V1_6.c(7267:16): error: invalid operand '& '
TK-II-OS_V1_6.c(7267:47): error: invalid operand '& '
TK-II-OS_V1_6.c(7267:34): error: failed to generate expression
TK-II-OS_V1_6.c success

failure

........
Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


Probably just needs to have IOCE and IOCF defined somewhere, but I'm not sure of how to do that :?

- Michael
Michael St. Pierre
FlowCode V3&V4 Pro Registered User
Manufacture: Heat Load Controllers,
and a variety of other widgets.

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

Re: PIC16F1847.fcd PORTB on change IRQ parameters are wrong

Postby Benj » Wed Jun 29, 2016 9:48 am

Hello Michael,

They are already defined by the compiler just slightly differently than what I was expecting from the datasheet.

Here is the correct interrupt code for the FCD.

Code: Select all

HandlerCode="#ifndef MX_INTHANDLER_intcon_IOCIF\n#define MX_INTHANDLER_intcon_IOCIF\nchar mxtmp;\nif (ts_bit(intcon, IOCIF) && ts_bit(intcon, IOCIE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\t\n\tFCM_%n();\n\tmxtmp=portb;\n\tcr_bit(intcon, IOCIF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"



Code: Select all

EnableCode="st_bit(intcon, IOCIE);\n"
DisableCode="cr_bit(intcon, IOCIE);\n"
These users thanked the author Benj for the post:
mytekcontrols (Wed Jun 29, 2016 4:50 pm)
Rating: 5.56%
 

User avatar
mytekcontrols
Posts: 89
Joined: Sun Aug 19, 2007 6:38 pm
Location: Santa Rosa, California
Has thanked: 3 times
Been thanked: 6 times
Contact:

Re: PIC16F1847.fcd PORTB on change IRQ parameters are wrong

Postby mytekcontrols » Wed Jun 29, 2016 5:03 pm

Hi Ben,

I implemented your latest changes and my program compiled without even a hiccup. So now I'll just need to set up a flowchart to run a complete test. Basically what I am doing is adding a 2nd PS2 keyboard to an existing program that already deciphers one by utilizing the INT0 interrupt (RB0=PS2 CLK, RB1= PS2 DATA). The 2nd keyboard will be attached to RB2=PS2 CLK and RB3=PS2 DATA, so I'll be setting up an additional PORTB interrupt-on-change for the 2nd CLK line. And just like the first one, it'll be a negative edge going interrupt. Also to facilitate the PS2 open collectors I have PORTB pull-ups set to ON.

Here's the specific initialization C-code block at the start of my program...

Code: Select all

clear_bit(option_reg , 7);   // Enable weak pull-ups
wpub = 0xFF;            // PortB weak pull-ups ON
osccon = 0xF0;            // 32 Mhz Internal Oscillator
iocbp = 0x00;            // No PortB positive edge IRQ
iocbn = 0x04;            // PortB.2 negative edge IRQ


Wish me luck :wink:

- Michael
These users thanked the author mytekcontrols for the post:
Benj (Wed Jun 29, 2016 7:08 pm)
Rating: 5.56%
 
Michael St. Pierre
FlowCode V3&V4 Pro Registered User
Manufacture: Heat Load Controllers,
and a variety of other widgets.

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

Re: PIC16F1847.fcd PORTB on change IRQ parameters are wrong

Postby Benj » Wed Jun 29, 2016 7:09 pm

Thanks and good luck, let us know how you get on.

User avatar
mytekcontrols
Posts: 89
Joined: Sun Aug 19, 2007 6:38 pm
Location: Santa Rosa, California
Has thanked: 3 times
Been thanked: 6 times
Contact:

Re: PIC16F1847.fcd PORTB on change IRQ parameters are wrong

Postby mytekcontrols » Thu Jun 30, 2016 6:51 pm

Ok I got it working with my flowcode program. At first I kept getting constant interrupts even without changing anything on the PortB input that I had setup as my interrupt-on-change pin (bit 2). But then I remembered seeing something about a register for independent flags representing each pin, which makes perfect sense when multiple pins are setup to produce interrupts, giving you a way to know which one was responsible. So the deal is you need to clear the flag in your interrupt macro, otherwise it'll just keep thinking a change has occurred and keep re-entering your interrupt handler macro.

So first thing I did was add a line to my initialization c-code block to clear all of the flags...

Code: Select all

clear_bit(option_reg , 7);   // Enable weak pull-ups
wpub = 0xFF;            // PortB weak pull-ups ON
osccon = 0xF0;            // 32 Mhz Internal Oscillator
iocbp = 0x00;            // No PortB positive edge IRQ
iocbn = 0x04;            // PortB.2 negative edge IRQ
iocbf = 0x00;            // Clear PortB IRQ Flags


Then I added a c-code block to my PS2 key handler interrupt routine to grab the value of the flag I was interested in (bit 2), save it to a flowcode variable, and then immediately clear the flag.

Code: Select all

FCV_IRQ2=iocbf.2;         // Retrieve Port 2 IRQ Flag
iocbf.2 = 0;            // Clear Flag


Following this I just added a flowcode decision 'If IRQ2' to see if the interrupt was coming from PortB.2 (interrupt-on-change) or from my original PortB.0 (INT0), and then processed the appropriate data depending on which PS2 port was active (key pressed).

In the process of getting all of this to work, at first I thought there were problems with the FCD changes that you gave me Ben, and proceeded to investigate this while referencing the INT0 code which I knew was working correctly. In this investigation, I discovered a difference that I subsequently eliminated, although as I discovered later this wasn't the problem for the constant interrupts occurring. But my FCD changes also didn't seem to cause any problem, so I have left it as is. Here is what I did...

Code: Select all

HandlerCode="#ifndef MX_INTHANDLER_intcon_IOCIF\n#define MX_INTHANDLER_intcon_IOCIF\nif (ts_bit(intcon, IOCIF) && ts_bit(intcon, IOCIE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\t\n\tFCM_%n();\n\tcr_bit(intcon, IOCIF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"


And here is what you had given me...

Code: Select all

HandlerCode="#ifndef MX_INTHANDLER_intcon_IOCIF\n#define MX_INTHANDLER_intcon_IOCIF\nchar mxtmp;\nif (ts_bit(intcon, IOCIF) && ts_bit(intcon, IOCIE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\t\n\tFCM_%n();\n\tmxtmp=portb;\n\tcr_bit(intcon, IOCIF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"


Notice that I eliminated: \nchar mxtmp; -and- \n\tmxtmp=portb;

Like I said this was done when I was initially trying to troubleshoot a problem, and my thinking at the time was that the INT0 handler appeared to be very similar in purpose to what I needed the interrupt-on-change handler to be, and so I eliminated what was different. Of course not really knowing what this code is doing, I had taken a shot in the dark. However with that said it seems to work just fine. Any thoughts?

- Michael
These users thanked the author mytekcontrols for the post (total 2):
kersing (Thu Jun 30, 2016 7:33 pm) • dazz (Fri Jul 01, 2016 11:01 am)
Rating: 11.11%
 
Michael St. Pierre
FlowCode V3&V4 Pro Registered User
Manufacture: Heat Load Controllers,
and a variety of other widgets.