Page 1 of 1

MPC23017 and SimQuadEncoder

Posted: Fri Feb 02, 2018 9:28 pm
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 250 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 263 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 273 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 ?

Re: MPC23017 and SimQuadEncoder

Posted: Fri Feb 02, 2018 9:29 pm
by jojo31
The source file
Test_LCD_MPC23017_CODEUR_INT.fcfx
(17.04 KiB) Downloaded 294 times

Re: MPC23017 and SimQuadEncoder

Posted: Sun Feb 04, 2018 7:38 am
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 7566 times
MCP23017_Encoder.fcfx
(20.96 KiB) Downloaded 255 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 277 times
Is it normal ? How to set INTA ?

Many thanks for your answer.

Re: MPC23017 and SimQuadEncoder

Posted: Mon Feb 05, 2018 11:43 am
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.

Re: MPC23017 and SimQuadEncoder

Posted: Mon Feb 05, 2018 5:28 pm
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 7541 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

Re: MPC23017 and SimQuadEncoder

Posted: Mon Feb 05, 2018 6:31 pm
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.

Re: MPC23017 and SimQuadEncoder

Posted: Tue Feb 06, 2018 9:55 pm
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

Re: MPC23017 and SimQuadEncoder

Posted: Thu Feb 08, 2018 11:47 am
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 255 times
It's a bit complicated but it works, Any questions let us know.