Page 1 of 1
MIAC with CAN
Posted: Tue Apr 05, 2011 11:04 am
by Jacks0nxD
Good day,
Currently I am on my trainee ship for 6 months at a company that automates sunscreens. Now they work with Moeller PLC's but they would like to know if the MIAC in combination with a touchscreen on the CAN-bus works better. That's my assignment for this period.
I've played around with Flowcode 4 and am able to send a message via the CAN module but I can't get the second MIAC to respond on it. What I want to try is use the first MIAC as a kind of master module that only sends CAN messages, and the second MIAC as a slave module that responds when a certain message is received via the CAN-bus.
So if the master sends out: "20010001" the slave module has to make Output 1 high or something like that; just that I know he received the message and can respond/react on it.
Could someone lead me in the right direction?
Thank you in advance!
P.s.
I've added the master and slave programs so you can see how I've build it up.
Master module
- master.JPG
- Master module code
- (110.81 KiB) Downloaded 2371 times
Slave module
- slave.JPG
- Slave module code
- (115.65 KiB) Downloaded 2371 times
Re: MIAC with CAN
Posted: Tue Apr 05, 2011 12:01 pm
by Benj
Hello,
Here is a quick example that should get you up and running.
Re: MIAC with CAN
Posted: Tue Apr 05, 2011 2:56 pm
by Jacks0nxD
Hi Benj,
I've downloaded those files and edited them a bit so it will send an 8 bit message via the CAN-bus and that the MIAC enables relay1 (just an extra control for me)
Now when I make I1 high relay1 comes in but the software doesn't send any message over the CAN-bus, we have a CAN-logger in our office and the only message that comes by is the predefined heartbeat from the logger itself.
Just to get things clear for myself:
- To sent a message via the CAN-bus I have to initialize the CAN module, just put a box before the WHILE loop with the parameters: CAN > INIT.
- In the WHILE loop define the channel where the MIAC has to send on, in this case I've taken ID5.
- Then a simple routine, check if I1 is high, is it high then turn relay1 on and set the following parameters:
*CAN > SetTxID: 5, 1, 0
*CAN > SetTxData: 0, 8, 0, 1, 0, 1, 0, 1, 0, 1 (just so that it is easy to see on the laptop between the heartbeat messages)
*CAN > SendBuffer: 0
- After that a 50ms delay so the bus doesn't get flooded.
- If I1 is not high just keep relay1 low
Are these settings/parameters correct of did I make a mistake somewhere?
Hope to get a reply soon!
Re: MIAC with CAN
Posted: Tue Apr 05, 2011 4:33 pm
by Benj
Hello,
No your thinking looks correct to me
Could your logger be operating at a different frequency? The Flowcode CAN component defaults to running at 125KHz.
Re: MIAC with CAN
Posted: Tue Apr 05, 2011 5:41 pm
by Jacks0nxD
No the logger is at the same frequency. I've tried an old logger that is on an old laptop and a new USB logger on a Windows XP PC and they both don't see the CAN messages...
Re: MIAC with CAN
Posted: Wed Apr 06, 2011 9:55 am
by Benj
Hello,
Do you have the terminating resistors connected (TA & TB) as shown on page 11 of the operation guide?
http://www.matrixmultimedia.com/datashe ... 0Guide.pdf
Is the other MIAC responding to the messages or are no messages being sent at all?
Re: MIAC with CAN
Posted: Wed Apr 06, 2011 10:13 am
by Jacks0nxD
I didn't make that bridge, just did but still no results. And the first MIAC isn't sending anything at all according to the loggers. The other one is also not responding so he doesn't understand it or the message isn't sent.
Re: MIAC with CAN
Posted: Wed Apr 06, 2011 11:03 am
by Sean
There are some issues with the parameters being used for the SetTxID macro:
The first parameter is the TX buffer identification. The CAN controller in the MIAC has three TX buffers identified as 0, 1 and 2.
The other two parameters are the high and low bytes of a 16-bit integer which is used to hold the 11-bit ID. To make matters a little more complicated, the ID must be left shifted by 5 bits (multiplied by 32).
Note: This applies to IDs set or read using the Flowcode macros. ID values entered into the property pages of the Flowcode component do not require the left shift to be applied because the component handles this operation.
To load a message ID = 5 into TX buffer 0, the SetTxID command should be:
SetTxID: 0, 0, 160
The conversion might be simpler using the hexadecimal conversion of the ID value.
To set ID = 10 (10 x 32 = 320 = 0x0140):
SetTxID: 0, 0x01, 0x40
The other commands seem to be correct. This should allow the transmitted messages to be observed using the logger.
Reception of the message by the second MIAC will depend on the correct setup of the masks and filters.
The message ID used in the CAN component RX buffer property should be 5 (not 160 - the component will handle the conversion as explained).
Re: MIAC with CAN
Posted: Wed Apr 06, 2011 11:22 am
by Jacks0nxD
Hello Sean,
thank for the information. I've edited my software (see attachment) but the loggers still don't see the message...
Part of the software is in Dutch, if you have questions please ask!
Re: MIAC with CAN
Posted: Wed Apr 06, 2011 11:49 am
by Sean
The CAN init macro should be outside the main loop. Possibly better to make it the first command in the program.
Also, in addition to selection of the MIAC and CAN components, the target device must also be selected as MIAC (View -> Project Options -> Target).
Termination (as mentioned in a previous post) must be applied by linking the TA terminal to the TB terminal on each MIAC.
The CAN-H and CAN-L connections must be made correctly to both MIACs and the logger.
Re: MIAC with CAN
Posted: Wed Apr 06, 2011 12:35 pm
by Jacks0nxD
Now it works!
Is was indeed that the "CAN Init" was in the wrong loop... stupid mistake... Now both loggers see my message!
Logger 1 - Old laptop
Identifier: 0x005
Type: Std
Length: 8
Data: 00 01 00 01 00 01 00 01
Logger 2 - PC
Identifier: 5
Data: 00 01 00 01 00 01 00 01
Thank you very much for your help Benj and Sean! Now letting the other MIAC respond on the message and connecting it to a touchscreen that has to be accessible via ethernet... Enough to do haha
Re: MIAC with CAN
Posted: Mon Apr 11, 2011 2:47 pm
by Jacks0nxD
Sending messages over the CAN-bus works perfect now. But is there some kind of manual, instruction list of something for the CAN module available?
The probem I now have is that I can send messages but I can't get the second MIAC to respond on a certain message.
Re: MIAC with CAN
Posted: Mon Apr 11, 2011 3:12 pm
by Sean
Does the second MIAC respond to some messages?
If the second MIAC responds to some, but not all, messages, the basic settings and connections must be correct. The problem could be with the filter and mask settings in the component.
Are you using the advanced settings for the receive buffers ('simple settiings' checkbox unchecked)?
Information is available from the CAN component help menu, and from our website. A link to the bundle manuals (including Easy CAN) is provided below.
Note: Both of these sources provide general Flowcode component information and are relevant, but not specific, to MIAC.
http://www.matrixmultimedia.com/lc_index.php
Re: MIAC with CAN
Posted: Mon Apr 11, 2011 3:18 pm
by Jacks0nxD
The second MIAC does respond to some messages, when I but a component with the parameters "If Data>0" en then at the TRUE branch RelayON(1) and at the FALSE branch RelayOFF(1). When I send a message on the CAN the relay goes on for a fraction of a second and then it goes back to rest (logically)
But where can I change those settings? So that I see the "simple settings"?
Re: MIAC with CAN
Posted: Mon Apr 11, 2011 4:57 pm
by Sean
In the property pages (tabs) of the CAN component for RX Buffer 0 and RX Buffer 1 there is a checkbox in the top left-hand corner marked 'Simple settings'.
The pages default to the simple option, but if the checkbox is unchecked , more advanced mask and filter settings are displayed.
The can component 'CheckRx' macro only indicates the reception of data once for each message received, and reads the data into internal memory.
If your program is continually checking for messages in a loop, it will probably return 0 in most cases.
The relay might be turning on when a message is received, but if the test is repeated, without another message being received, the next result will be false and the relay will turn off again.
Re: MIAC with CAN
Posted: Tue May 17, 2011 9:42 am
by Jacks0nxD
Good morning Sean,
When I first started Flowcode I disabled the Panel view because I thought it was annoying and I didn't need it. Now I see that it can be useful, definitely for more information via the HELP function.
I'll try reading the HELP files to see if that makes more clear.
Thanks a lot!
Re: MIAC with CAN
Posted: Tue May 17, 2011 9:47 am
by Jacks0nxD
Good morning again,
after some hard and long weeks working I went back to my MIAC problem...
I can't get the MIAC to respond on a certain message, from a certain ID.
Example:
Code: Select all
ID: 2
MESSAGE: 00 13 F2 0F 11 00 10 10
ACTION: turn some relay or so on
ID: 2
MESSAGE: 00 13 F2 0F 11 00 10 00
ACTION: turn some relay or so off
ID: 3
MESSAGE: 00 13 F2 0F 11 00 10 10
ACTION: wrong ID, only respond to instructions from ID 1 and 2
ID: 3
MESSAGE: 00 13 F2 0F 11 00 10 00
ACTION: wrong ID, only respond to instructions from ID 1 and 2
I can't get it working, could someone put me in the right direction?
Re: MIAC with CAN
Posted: Tue May 17, 2011 9:51 am
by Benj
Hello,
Please can you attach your programs to the forums and I will see if I can spot what the problem is.
Re: MIAC with CAN
Posted: Tue May 17, 2011 9:55 am
by Jacks0nxD
here you go!
Re: MIAC with CAN
Posted: Tue May 17, 2011 5:48 pm
by Benj
Hello,
I would start by looking at the CAN examples as part of the Flowcode v4 examples pack.
There are working CAN programs there that should show you how to use the CAN component.
The CAN component help file should also help you to get up and running.
Basically your program is not calling the CheckRx Macro which is used to check for incoming CAN messages.
The Vnet simulation mode can be used to test multiple Flowcode programs communicating together over CAN.
Re: MIAC with CAN
Posted: Wed May 18, 2011 12:17 pm
by Jacks0nxD
Got it working better now, only other problem that I run in to is: How do I set my transfer ID?
Code: Select all
Component Macro
-SetTxID
- buffer: 0
- hi: 0
- lo: 0
result: 0
Code: Select all
Component Macro
-SetTxID
- buffer: 0
- hi: 0
- lo: 1
result: 0
Code: Select all
Component Macro
-SetTxID
- buffer: 0
- hi: 0
- lo: 5
result: 0
Code: Select all
Component Macro
-SetTxID
- buffer: 0
- hi: 1
- lo: 0
result: 8
Code: Select all
Component Macro
-SetTxID
- buffer: 0
- hi: 1
- lo: 1
result: 8
I don't get the logic behind it... When I change the value from HI it increases with 8 but LO has nu influence...
Re: MIAC with CAN
Posted: Wed May 18, 2011 1:49 pm
by Benj
Hello,
The CAN ID is shifted so that the lower 5 bits of the ID Low are not used.
The CAN help file will explain this better.
Select the CAN component on the panel and then click the help link on the properties pane.
Therefore to get ID1 you have to pass the following parameters.
IDHigh = 0
IDLow = 32
You can also do it like this using an INT variable.
INT ID = 1
IDlow = ID << 5
IDHigh = ID >> 3
If you want to recombine the ID's from a receive then you will have to repeat the process in reverse.
ID = IDLow >> 5
ID = ID | IDHigh << 3