CAN Bus Programming

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

CAN Bus Programming

Post by JohnCrow »

Hi
Ive tried one of the simple example programs to read the ADC value and send it over the can bus and display on the LCD.
Ive now tried to extend it.

I have
A switch board on port d on TX
A led board on port d on RX

I want to be able to read the ADC value on the LCD and also show on the LED board which switch is pressed.
Ive tried the following mods

TX Side
Changed data_cnt from 1 to 2
Added variable SWITCH to d1
Added a normal read icon for port d

RX Side

Get RX DATA
Buffer 0
Index 1 = switch

Im totally new to can and not been able to see how to read more than on set of data.
Would appricate if someone could tweak my flowcharts to point me in the right direction.
Thanks
ADC-Switch TX.fcf
(15.63 KiB) Downloaded 302 times
ADC-Switch RX.fcf
(33.48 KiB) Downloaded 291 times
1 in 10 people understand binary, the other one doesn't !

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: CAN Bus Programming

Post by Enamul »

Hi John,
I have made here in 4th page what you exactly want..I have been working with internal CAN last couple of months excessively..
http://www.matrixmultimedia.com/mmforum ... 5&start=75

I have posted schematic for CAN bus structure as well...You can have a look on that or knock me if you stuck anywhere.. :)

The idea of the codes is to check bi-directional communication between two chip which can be used for multiple..ADC sense from Master with some pre-defined data is sent to slave and slave returned that back to Master..that's how I become confirmed about bi-directional communication..I have used here internal CAN using PIC18f4580 and MCP 2551 CAN transceiver.

If you want to use external CAN chip (MCP2515 or MM CAN board)..these programmed can be used just little change need to be done! Please let me know..
Attachments
CAN_BD_Receive_SEND_Slave.fcf
(19.64 KiB) Downloaded 293 times
CAN_BD_Send_Receive_Master.fcf
(19 KiB) Downloaded 315 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: CAN Bus Programming

Post by Enamul »

Hi John,
I have been through your program. You are using Matrix CAN board I am sure..I am changing some issues in your code..
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: CAN Bus Programming

Post by JohnCrow »

Hi Enamul
Yes, I got a pair of Matrix Can boards, arrived at the weekend so just trying to get to grips with the basics :)
1 in 10 people understand binary, the other one doesn't !

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: CAN Bus Programming

Post by Enamul »

Hi John,
I have changed few things in the code..you can check those now..Let me know how it's behaving..
Attachments
ADC-Switch RX.fcf
(34.28 KiB) Downloaded 317 times
ADC-Switch TX.fcf
(15.45 KiB) Downloaded 294 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: CAN Bus Programming

Post by JohnCrow »

Thanks Enamul

Great :)
The program is now doing what I initally was trying to do.
Will study your example now and try to expand it a bit further.

Got a few ideas for projects with E-Blocks, CAN and the MIAC
1 in 10 people understand binary, the other one doesn't !

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: CAN Bus Programming

Post by Enamul »

Hi John,
Thanks for letting me know. I am busy with my master project otherwise I have some ideas to test as well...I guess we will see some nice tutorials from you soon.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: CAN Bus Programming

Post by JohnCrow »

Ive a lot to learn about CAN before I can do that :lol:
But I do find writing up my notes I make along the way can be useful as a basic tutorial.

Ive got a PLC board I built from Elektor using the ECIO40 which has a CAN bus connection, I'll try and connect that to the network as well, once I get time.
1 in 10 people understand binary, the other one doesn't !

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: CAN Bus Programming

Post by Mikat »

Hi guys...
I have used CANbus at my boat about 1,5 year now (if interested, there is some story at the teell us your projects thread), and the experience has been very positive, the bus is very reliable, some day when I was fishing I checked the status of the CANbus and it shows something like 3000000 messages and not even one bus error..
If you have some question about the bus, messaginn,interrupts, filterin etc. ,contact me via PM or write here, I'll try to help as much I can...

Mika

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: CAN Bus Programming

Post by Mikat »

Hi all.

I put this in here too, maybe it serves all here.
Enamul asked via pm at the CAN hardware.
At the hardware, be aware at the count of termination resistors, I think I broke 2 MCP2551 because my network has 3 120 ohm resistor..
The MCP2551 seems to broke quite easily sometimes, sometimes it seems to be very robust.
The MCP2551 needs AT LEAST 4,4 -4,5V VCC voltage, below that it don't work, so in the 3,3-3,6V systems it need separated supply (I haven't found CAN transceiver which works reliably at 3,6V and high speed).
The MCP2551 can broke the way that spotting it is very hard. I had broken MCP at my trolling engine remote servo controller, it seems to working ok, but the remote works somehow strange. After more investigating, I figured out that only maybe 1 of 20-500 messages was received correctly, so no wonder that the remote work was slow and "jumpy" ( the reason for the broke was probably blown 5V VCC regulator at the servo control board)...
At the design the CAN network, I don't have anything special, I have no resistors between the PIC and MCP, the whole network has one termination resistor, and the cables are regular Samtec 4-16 wire cable (length 1- 5m), no "CAN spec", no shielding, just regular multiwire, with IP68 connectors, and there goes relay control etc. at the same cable...

Mika

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: CAN Bus Programming

Post by beambase »

Hello
during the years I have developed some practical knowledge about CAN bus cabeling in industral systems focused on safety and there are some rules that should be folloed:

1
Cabeling
I normaly use a cable with one data pair for the CAN bus and one pair to supply 24V bus power to the nodes. By using cable like http://www.alephlighting.com/files/Cabl ... _Cable.pdf this you get a reliable power bus and a ground that is essential for the CAN bus to work over long distances. Dont just connect Can_High and Can_Low, you MUST also provide a good ground reference to get reliable data transmissions between the nodes if intend to move them out in the real world outside the workbench.

2
Termination
Always use termination at BOTH ends. Anything alse is asking for trouble and I have found that MCP2551 and probably most other CAN drivers will respond better to a "split termination resistor" ham just a single 120Ohm resistor.
The CAN bus will get more reliable if you include a capacitor in the middle of the termination connected to a GOOD ground, preferably the ground of the 24V power bus.

3
I always include some sort of TVS (Transient Voltage Supressors) to protect the MCP2551. I have found that AVX Transguard works very well. http://www.avx.com/docs/catalogs/canbus.pdf
BUT if you use Transguard TVS ALWAYS connect termination resistors at BOTH ends of the CANbus since you need to draw some current through the bus or the TVS will affect the edges of the CAN signals.

4
I have found that optoisolation between the MCP2551 and the PIC is essential in the real world. Use a separate isolated DC/DC converter to power the PIC and a separat regulator to power the MCP2551 and everything on this side of the optocouplers. Doing so will save you from the PIC in a node resetting when you connect nodes to the bus or switching large relays, starting/stopping motors etc.

There are probably a lot more to be said about this but I hope this is a starting point for a trouble thing CAN network.
Attachments
CANbus3.JPG
(34.75 KiB) Downloaded 1422 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: CAN Bus Programming

Post by Enamul »

Thanks for the great tips..I will test those.. :)
Enamul
University of Nottingham
enamul4mm@gmail.com

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: CAN Bus Programming

Post by Mikat »

Ok, here was some information, quite lot more experience than I had...
It's very nice to have people to share their information..
In my case, the difference is that the CANbus don't transfer power, its just databus, and the cables are short, just over 5m..
Just in curiosity, how the CANbus is worked in the industrial? I have seen many times people that says that the CAnbus is "straight form hell" and it has problem all the time, but the problem is the broken/badly dedsigned devices in the bus and the people that don't understand the CAN), not the bus itself.. In the car industry, the CANbus is "like" a strandard nowdays, and it transfers very important data between the safety equipment...

T:Mika

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: CAN Bus Programming

Post by beambase »

The list of applications for a CAN bus is pretty impressive. Trucks and buses, passenger cars, off road vehicles, passenger and cargo trains, maritime electronics, aircraft and aerospace electronics, factory automation, lifts and escalators, industrial machine control, building automation. CAN is also quite common in all kinds of medical applications and devices that are controlled by computers. Things like PET cameras, X-rays machines, life support systems etc.
Just look at this machine: http://healthcare.siemens.com/molecular ... eon-pet-ct

I think that comment like a "bus from hell" could apply to anything that you don't understand. The good thing about CAN is the level of knowledge that is out there since it is so widley used. I rather use something that is well documented and "hard" than something that is maybe only supported by one company or have been invented by some unknown university and never been widely adopted by commercial users. If you want to learn about CAN you can always look at http://www.can-cia.org/
Lots of information and inspiration there.

I don't claim to be a CAN expert but please feel free to ask and I'll try to help if I can.

Post Reply