MPC23017 and SimQuadEncoder

A forum where Flowcode v7 user created components can be shared, discussed and reviewed.

Moderator: Benj

Post Reply
jojo31
Posts: 12
Joined: Sun Jan 08, 2017 1:23 pm
Been thanked: 4 times
Contact:

MPC23017 and SimQuadEncoder

Post by jojo31 »

Hello,

I am creating a component with MPC23017 and several encoders (one at this moment).

For the moment I am trying to simulate the behavior of this component.

The first sub component is "SimQuadEncoder" that Benj sent me.
I have modifed it because I cannot use directly pin_a or pin_b so I have added a macro "CheckForChanges()" .
SimQuadEnc.fcfx
(29.57 KiB) Downloaded 241 times
The component "MPC23017_Encoder" include "CAL_i2C + SimQuadEncoder".
Two pins are added in this component INTA and INTB.
INTA is set by the macro "CheckChangesSim" if the encoder is moving.
MCP23017_Encoder.fcfx
(19.17 KiB) Downloaded 254 times
The first file "Test_LCD_MPC23017_CODEUR" use this component without problem : the counter value is writing on LCD and we can see INTA changing of state during simulation.
Test_LCD_MPC23017_CODEUR.fcfx
(13.66 KiB) Downloaded 263 times
After, when I try to use interruption on RB0 implemented in "Test_LCD_MPC23017_CODEUR_INT", I didn't have any modification on INTA.


Please help, Is it a mistake or a bug ?
Last edited by jojo31 on Fri Feb 02, 2018 10:15 pm, edited 2 times in total.

jojo31
Posts: 12
Joined: Sun Jan 08, 2017 1:23 pm
Been thanked: 4 times
Contact:

Re: MPC23017 and SimQuadEncoder

Post by jojo31 »

The source file
Test_LCD_MPC23017_CODEUR_INT.fcfx
(17.04 KiB) Downloaded 287 times

jojo31
Posts: 12
Joined: Sun Jan 08, 2017 1:23 pm
Been thanked: 4 times
Contact:

Re: MPC23017 and SimQuadEncoder

Post by jojo31 »

Hello

After some tests, I saw that INTA (interruption pin on RB0) is set in a macro that I didn't use !

So , I have modified my component "MCP23017_Encoder" and I set variable INTA in MAIN.
MAIN.JPG
MAIN.JPG (62.06 KiB) Viewed 7337 times
MCP23017_Encoder.fcfx
(20.96 KiB) Downloaded 245 times
But no signal on INTA pin in, it's seems that the instructions are not executed in a MAIN of a component
Test_LCD_MPC23017_CODEUR_INT1.fcfx
(16.53 KiB) Downloaded 268 times
Is it normal ? How to set INTA ?

Many thanks for your answer.

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: MPC23017 and SimQuadEncoder

Post by Benj »

Hello,

In a component source project you can see Main as the test routine. You can add code to Main to test out the other various macros and the code in Main will not be included when you export to a component. If you need code as part of your component then you will need to either create a macro to house the code or call the code separately in your project that uses the component.

Currently we don't support callback type interrupts but this would be a nice feature to add for the future.

jojo31
Posts: 12
Joined: Sun Jan 08, 2017 1:23 pm
Been thanked: 4 times
Contact:

Re: MPC23017 and SimQuadEncoder

Post by jojo31 »

Hello Benj

Thank you very much for this explanation.

Is it possible to have an output variable defined in the properties of the component ?
Component.JPG
Component.JPG (26.71 KiB) Viewed 7312 times
The idea is that I can read this variable when the value will change inside the component on a click of the SimQuadEncoder.

Many Thanks

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: MPC23017 and SimQuadEncoder

Post by Benj »

Hello,

It's possible to have a variable that can be written/read using a public macro as part of your component.

It's also possible to specify a macro in your program to be called from the component as we do with the USB Slave component but it's not particularly nice to work with in the current form certainly if there are parameters to the macro.

jojo31
Posts: 12
Joined: Sun Jan 08, 2017 1:23 pm
Been thanked: 4 times
Contact:

Re: MPC23017 and SimQuadEncoder

Post by jojo31 »

Hello Benj,

I found the solution to export a public variable of a component in "Component Configuration" and I am trying to use this first solution :D

But Is it possible that you send me an example of the second solution "specify a macro in your program to be called from the component" ?

Thanks you very much.

Best regards

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: MPC23017 and SimQuadEncoder

Post by Benj »

Hello,

Here is a example of what we do in the USB Slave component.

The Macro Name property allows you to specify the name of the call back macro. The Macro parameters allow you to define the parameter setup of the macro to pass in values. Both properties are setup to generate definitions which triggers the AddProperty event.

The call back macro is called by calling the ComponentMacro macro inside the component. This could either come from an interrupt managed by the component or from something else happening say on a polled event.

The Ev_AddProperty event is called when adding the properties to the C code as defines. We then override the definitions with the C version of the callback macro name.
CallBackDemo.fcfx
(13.44 KiB) Downloaded 245 times
It's a bit complicated but it works, Any questions let us know.

Post Reply