Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] How to design a CAN BUS Network from scratch

Status
Not open for further replies.

TekUT

Full Member level 6
Joined
Jun 17, 2008
Messages
323
Helped
39
Reputation
78
Reaction score
15
Trophy points
1,298
Location
Italy
Activity points
3,557
Intro
Hi all,
is now long time from writing the last tutorial on this great forum, now is time to start again with, I think, an interesting thematic about CAN bus network with PIC18F4680 microcontroller. This is a step-by-step design because I'm just starting now with this argument, the time needed to complete this project might be short or long it will depend from my spare time, my progress and the contribute from others user who may be happy to participate and cooperate together.

The idea
The idea behind this design is to connect several node each other trough the aid of a CAN bus network.
Starting from a bridge node connected to a PC we can send and receive data over the CAN network.
The purpose of this design is to overcome the limit of the classical RS232 interface in order to connect several nodes, with the aid of a CAN bus network will be more simple add others node to a existing network and a network of such type is intrinsically safe because every defective node will be automatically excluded from the network without having a negative impact on the overall operation of the network.
The last goal will be to have for each node of the network a bootloader programming feature, hence we will can easily update the nodes firmware through the network without the need to reprogramming it directly on board of the single node. With this feature we are also able to do the remote updating of the firmware inside each node without the need to reach physically the network itself.

System description
To start we can develop a simple network with two slave nodes on a breadboard adding also a bridge node used to get in communication with a PC, that will act as a master by means of the serial RS232 port, with the nodes inside the network.
In attachment you can see a simple schematic of the overall system.

Bye for now
Powermos
 

Attachments

  • FIG-1-SYSTEM-SETUP.jpg
    FIG-1-SYSTEM-SETUP.jpg
    64.7 KB · Views: 158


Why have you decided to use RS232? In my opinion you should use USB. Every computer is equipped with USB.

Thank you bzznxlad for your question, in the final release the bridge will be changed in order to act as a USB to CAN converter, but for starting this is not the main focus of the design. Anyway we need to use a bridge from PC and the CAN network and for this reason I've decided to start with the serial port, more simple to set up in a PIC and get it working in few minutes, after that, when all the network is properly working the further step will be make the necessary change to the bridge firmare in order to add the USB behaviour through the HID class.

Thank you to have pointed this argument.

Bye
Pow
 

I have written an USB service on my own for my microcontroller. I have applied PIC18F2550. It works as an HID class device. Nevertheless, it has took some of time and I spent approximately three months to create that code. Generally, Microchip provides stack for USB application so you can use it and deploy. On the other hand, there is an environment https://www.mikroe.com/mikroc/ which has HID library but it's unavailable through DEMO version limitations.
 

Thank you bzznxlad.

I've written some time ago a code using the Microchip USB stack, this is a very simple task, just fill the processio function and the work is done, I've used the PICDEM FS USB demo board and to do it I've simply changed few line of code to adapt the code to my application (was a USB voltmeter), but as I've written, this will be a further step on the design, now the main goal is get a properly working CAN network and before to do this there are some aspects to define.

As you probably know CAN network is based upon messages is not a addressable protocol then we have to found a suitable way to address some command to the specific node.

As you probably know the CAN network is based upon messages, then is not a protocol based on the addresses philosophy. All the nodes inside the network, potentially, can read the messages travelling over the network. For this reason I have to found a suitable way to address some command to the specific node (e.g. when I will need to update the firmware on a determined node or when I've to read some data from a specific node).

For example, suppose to have two or more nodes able to read the temperature, I've to found a way to address messages to some node instead to another one. A first way may be to use the messages filtering feature that is available on the controller chip, hence only the messages related to the temperature aspect will be taken in consideration. But the problem is not solved completely because into the set of these messages we have to choose only the one that is related to a specified node.

Like into the DeviceNET approach we can use a dip-switch and then set with this one the node address, then into the message that will be send from the master over the bus, we will have to define a sort of "address strategy" or "address logic" to use.

I think that operating in this way only the message that is able to match the node function (achieved by the hardware filtering of the CAN engine) and the subsequent software filtering (based on the hardware address set by the dip-switch), will be accepted and all the others rejected: I'm thinking about a sort of post-filtering added to the one provided by the CAN engine implemented on the PIC microcontroller hardware.

Hope to have explained in a clear way my approach, but if you or anyone like to discuss about it I'm here, I think this is the main issue that has to to be defined before go into the next step.

Bye
Pow
 

I haven't even worked with CAN, I must admit. Nevertheless, I have two PIC18F66K80 which I am going to use in the nearest future, they are equipped with ECAN.
 

@bzznxlad
if you like to cooperate you're welcome!

Bye
Pow
 

Dear all,
here below a first update, the demo board that will be used to perform the test.
Into the bottom of the image, into the separate small bread board, there is the CAN bus.
Into the big bread board you can see on the top the two slave node and into the bottom left the RS232/CAN converter (into the bottom right there is the MAX202 transceiver), the DIP8 chip are the CAN transceiver MCP2551.
Near every microcontroller there is a small header used to perform the ICSP programming.
To perform some debug there are also two small led for every PIC, one green and one yellow.

FIG-2-TEST-BOARD-WEB.jpg

Bye for now
Pow
 

So here it's version 1.0. It's a beautiful moment when hardware is already done and it's time for software testing.
I wish you good luck.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top