Miac CAN Problem
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Miac CAN Problem
Hi Team.
Please help the old man ,I am on the edge of throwing my toys out of the pram
Not understanding the background workings of the USB slave component I ran in to the following problem with my MIAC and CAN.
Frist is is necessary to say that I can not trigger the CAN send function from the USB Slave firmware(I did and it functions) as from a Windows GUI
the Timing move around and the CAN TX cycle time is not stable enough therefore the Machine sometimes complains CAN Timeout (we see oscillations between 8 and 14mSec with windows controlling the Cycle time ,
Therefore I made a Custom Interrupt with TMR1 (10mSec ) and then CAll a macro to send the CAN message this function spot on cycle time is correct and no issue ! Now the Problem when I now use the the CAN component call inside the macro/Interrupt then the CAN freezes and it seems the USB also
CAN macro called in the TMR1 Interrupt CAN freezed no transmison and also no USB activity in the labVIEW GUI Any Ideas why this would happen or comments to achieve my goal would be appreciated?
another concerns is that I only use the CAN component in the TMR1 interrupt however the compiler is complaining that there are multiple calls and it has duplicated the functions the same is for the USBslave component not sure if this is normal or some sort of issue that will byte me later
Please help the old man ,I am on the edge of throwing my toys out of the pram
Not understanding the background workings of the USB slave component I ran in to the following problem with my MIAC and CAN.
Frist is is necessary to say that I can not trigger the CAN send function from the USB Slave firmware(I did and it functions) as from a Windows GUI
the Timing move around and the CAN TX cycle time is not stable enough therefore the Machine sometimes complains CAN Timeout (we see oscillations between 8 and 14mSec with windows controlling the Cycle time ,
Therefore I made a Custom Interrupt with TMR1 (10mSec ) and then CAll a macro to send the CAN message this function spot on cycle time is correct and no issue ! Now the Problem when I now use the the CAN component call inside the macro/Interrupt then the CAN freezes and it seems the USB also
CAN macro called in the TMR1 Interrupt CAN freezed no transmison and also no USB activity in the labVIEW GUI Any Ideas why this would happen or comments to achieve my goal would be appreciated?
another concerns is that I only use the CAN component in the TMR1 interrupt however the compiler is complaining that there are multiple calls and it has duplicated the functions the same is for the USBslave component not sure if this is normal or some sort of issue that will byte me later
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- 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: Miac CAN Problem
Hi Peter,
Can you post your Flowcode project file. It sounds like there may be a collision happening.
The USB code is driven using an interrupt as is the timer code. If you are inside a CAN function as part of the timer interrupt and then a USB interrupt happens and goes into the CAN code again then this could have unwanted consequences, such as lock ups. Though this is purely a guess.
What about using the timer/usb interrupts to set a flag and then checking that flag in your main loop before calling the CAN code. This way the collision cannot happen.
Can you post your Flowcode project file. It sounds like there may be a collision happening.
The USB code is driven using an interrupt as is the timer code. If you are inside a CAN function as part of the timer interrupt and then a USB interrupt happens and goes into the CAN code again then this could have unwanted consequences, such as lock ups. Though this is purely a guess.
What about using the timer/usb interrupts to set a flag and then checking that flag in your main loop before calling the CAN code. This way the collision cannot happen.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Miac CAN Problem
Ben ThanksBenj wrote:What about using the timer/usb interrupts to set a flag and then checking that flag in your main loop before calling the CAN code. This way the collision cannot happen.
I agree with this and it is as we always do this however with this USBslave firmware from MATRIX there is no main loop to set a flag in ,if this is allowed to Run a main loop I for sure go this way.
I check there is no code that could cause collisions
Just another concern working with the custom interrupts for the first time in FC, I seem to miss how FC handle the High and low priority because
if I could use USB for Priority High and TMR1 for low it could also help.
Any case here is the project I will be great full if you guys can help me out with all of this confusion
Here are the MATRIX Source Main macro in my understanding a main loop is not used or will help as the comment says
this is a blocking function once you start the slave service it always sit in the slave service .
big confusion for the old man here
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Miac CAN Problem
Team.
Just checked the UsbSlave Source (Firmware) Matrix project has this multiple call graph problem in both FC7 and FC 8
Not sure if this is an issue or not just saying
Just checked the UsbSlave Source (Firmware) Matrix project has this multiple call graph problem in both FC7 and FC 8
Not sure if this is an issue or not just saying
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Miac CAN Problem
Hi Ben.
I have tried to add a while loop and do the Flag in the Interrupt and execute the CAN in the main(while) loop however as mentioned above it seems the USB slave RunSlaveService is a blocking function my code never enters the main loop (a bit expected as the comment from MATRIX in the source code shows
I am in big trouble believe me
I have tried to add a while loop and do the Flag in the Interrupt and execute the CAN in the main(while) loop however as mentioned above it seems the USB slave RunSlaveService is a blocking function my code never enters the main loop (a bit expected as the comment from MATRIX in the source code shows
I am in big trouble believe me
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- 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: Miac CAN Problem
Hi Peter,
Yes you're right I hadn't thought of that but yes the RunSlaveService macro is blocking so you can't do a while 1 loop.
So instead can you do this. Take any CAN related calls out of the USB Slave service macro. Instead set global variables to flag that CAN activity needs to happen.
Next using your timer interrupt monitor the variables and service them before clearing them ready for the next request.
This way the CAN SPI should only be being used in one interrupt macro and so shouldn't clash.
Yes you're right I hadn't thought of that but yes the RunSlaveService macro is blocking so you can't do a while 1 loop.
So instead can you do this. Take any CAN related calls out of the USB Slave service macro. Instead set global variables to flag that CAN activity needs to happen.
Next using your timer interrupt monitor the variables and service them before clearing them ready for the next request.
This way the CAN SPI should only be being used in one interrupt macro and so shouldn't clash.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Miac CAN Problem
I afraid the old man lost you here completelyInstead set global variables to flag that CAN activity needs to happen.
Next using your timer interrupt monitor the variables and service them before clearing them ready for the next request.
Where should I place the variables (I need to read the CAN TX buffers take out the 16 data bytes ) then process them and send them to the PC over the USB link ,I also need to take out 9 bytes from the USB slave (send by the PC) load them into the CAN TX and send them out .
Please do me favor and just look at the attached project
Edit.
Ben I checked now and all CAN calls are removed from the USB SlaveService once I place a CAN call in the TMR Interrupt the mulitiple call graph warning comes up.
new project
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- 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: Miac CAN Problem
Hi Peter,
The reentrant warning is because the CAN init is called in the main and the CAN functions are called in the interrupt. Both use the SPI routines but there can be no collision because the init finishes before the interrupt is enabled.
I tested the warnings go away by adding the init to the interrupt on first call.
The reentrant warning is because the CAN init is called in the main and the CAN functions are called in the interrupt. Both use the SPI routines but there can be no collision because the init finishes before the interrupt is enabled.
I tested the warnings go away by adding the init to the interrupt on first call.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Miac CAN Problem
Hi Ben.
Thank you very much however I am still lost for the collision between the TMR1 and the USB interrupts
Thank you very much however I am still lost for the collision between the TMR1 and the USB interrupts
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- 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: Miac CAN Problem
In your timer macro do the check RX and store the return into a variable. If there is a message waiting then also store the ID and data bytes. Access these variables in the USB slave macro.
Similarly in the USB slave macro when you are asked to send a CAN message simply add the ID and data to different variables and check these variables as part of your timer interrupt.
Similarly in the USB slave macro when you are asked to send a CAN message simply add the ID and data to different variables and check these variables as part of your timer interrupt.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Miac CAN Problem
Ben.
Thank you a million ,understood now I am with you
I will give it all ago tomorrow it is already late with us
Thank you a million ,understood now I am with you
I will give it all ago tomorrow it is already late with us
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Miac CAN Problem
Hi Ben.
Slowly we are getting off the hook now implemented what we discussed and the USB and CAN are working now and the CAN cycle time is spot on.
Thank you very much once again you helped me a great deal ,Appreciated
Slowly we are getting off the hook now implemented what we discussed and the USB and CAN are working now and the CAN cycle time is spot on.
Thank you very much once again you helped me a great deal ,Appreciated
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- 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: Miac CAN Problem
Hi Peter,
Brilliant glad you're making progress. Thanks for letting us know.
Brilliant glad you're making progress. Thanks for letting us know.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel