The datafield, the DBC field, scaling and offsets
The CAN Basics Training Course provides a practical approach to understanding how CAN works. By giving real world examples, common practices, and an in-depth look at DBC files, Bryan Hennessy gives a real-world walkthrough of CAN.
Presentation by Bryan Hennessy. Recorded as part of a โliveโ training session in January 2019.
Video Transcript:
Bryan Hennessy: [00:00:01] We got the physical layer. We understand the voltages on the wire. We understand bit-wise arbitration, which is key. Now we understand the CAN frame or the data link layer. We understand, at least in J1939 and some of the others, exactly how the identifier is broken down in the arbitration phase. So we got the data link layer down. Thatโs clear to everybody. Any questions on those two concepts?
So now weโre going to move on to data. We got to know what the data is. The whole purpose of CAN is to get data from Device A to Device B, or more. So we canโt get reliable data that means something. Weโve just explained the overhead at this point, the data is the real value in CAN. So weโre going to talk much more about data now.
When you talk about data, you got to talk about a DBC file because that is the key, that is what explains to the systems what the data is. [00:01:01] So the data field, how is the data represented, as I call it. So CAN frames includes zero to eight data bytes. A classic CAN frame canโt be more than eight data bytes. I covered this, 99% of them, at least in J1939, have eight data bytes. There are some control frames in J1939 that use three data bytes, and Iโll show on.
Hereโs another example of some data similar to what I showed you before captured with a different tool, so it looks a little different, but itโs the same data. So this particular tool that captured this data is called a J1939-84 tool. It was made for the purpose of doing -84 work, which is what I did at PACCAR. But it shows you the same data. The timestamp is on the beginning instead of the end. Big deal. It shows you the channel. Here we call that 1. Before we call it a 0. Big deal. [00:02:01] Shows you the identifier, and this identifier is shorter because the last two bytes arenโt shown because of the source address. We got flag, so it says itโs received. This is just a received byte. We know a DLC code. Each one of these frames has eight bytes of data. Thereโs our data for each frame. Doesnโt mean anything yet. We got our frame counter.
Itโs just a little bit different twist on what I showed you before when it comes to raw data. The common theme here is we donโt know where this is. This is just a bunch of hexadecimal numbers that donโt mean anything to us. Thatโs what weโre going to explain with the DBC file and showing you how to break this down and understanding the data.
[00:03:42] I pulled up CANKing, which is Kvaserโs free bus monitor thatโs on our website to download. You go to our website to the home page, you find the downloads section which is on the right. Where is that, I can actually do it here and show you. So you would go over here and youโd say Support, this is our main home page, Kvaser.com, Support, Kvaser downloads. Iโll let that load. Takes a second to load, weโre not Google yet. Give us time.
First thing you always need with a Kvaser device in your network are the drivers. One driver runs any Kvaser device you can get or plug-in. CANlib SDK, weโll talk about that later. You just probably donโt need that. [00:04:42] If youโre going to do t-programming, you will but for now weโll skip CANlib. So thereโs CANKing, third one down, CANKing. You download that in your download area, you load it. You have a basic bus monitor at that point. Hook up any Kvaser device to any CAN bus, configure it for the right bit rate, set it up over here and go over here and click Start Run and, oh my gosh, I got a CAN data. This is live CAN data. Whereโs it coming from? This is a compass. This is an electronic compass that my first day as a Kvaser employee I realized, โHey, Iโm a hands-on guy, I want to learn this stuff by looking at it.โ So I went to my garage, I saw those in the marine business before, I found this leftover and I grabbed it and made my own CAN bus. So itโs not a J1939 device. I wish it was. But since NMEA 2000 is based on J1939, itโs very similar. I can talk about it as if itโs [00:05:42] J1939, and I will.
Itโs putting this data on the bus. I canโt make any sense of this data. This is just gobbledygook. Thereโs only one device on this bus right now. Itโs the only device. I didnโt bring my other devices. I usually have a GPS and some other devices on the bus. But I had limited packing space because I had to carry ski boots to this trip, so.
First thing I can do to make sense of this data is I can go over here to this data field that I can right click and I got this option, a fixed position right here. Iโll check fixed position. Thereโs only two different CAN frames on this bus right now. What fixed position does in CANKing is, if itโs the same identifier, which we know exactly what that is, 29 bits worth, we understand that, if itโs the same identifier, it just repeats it in the same fixed position. Thatโs what all fixed position mode does. Thereโs the data changes and the timestamp changes.
Each time it [00:06:42] receives that frame, it updates that timestamp and it updates the data. Each time it receives that frame, it updates that timestamp and it updates that data. I can see that data change. I happen to know that this is the heading, and my heading is actually contained in those two bytes, and I can see that data change when I move my compass. Itโs still just hex data, it doesnโt mean anything. Well, Iโm going to show you what exactly it means. Iโm going to use that as an example to show you what a DBC file does and how to take it apart. Iโm going to make that ugly hex data that means nothing into a true meaningful value.
Now, rate of turn, this next byte is rate of turn. I wonโt get into that. Donโt have time to do a bunch of them but itโs the same principle. Thereโs a lot of other information in these frames that I didnโt really take apart. I didnโt even really define in my DBC file. But itโs there. It means other things. You can [00:07:42] research it if you want and learn what that is. Thatโs all defined in a true DBC file. The DBC file Iโm using is a hacked DBC file that I created, that I made in order to understand how would they do and how they do. So itโs a very simple one. It just defines a little bit of the data, not all of it. But truth be known, heading is only two bytes in here and I got eight bytes in one frame. Thereโs a lot of information. At first glance, youโll think, โOh, a CAN frame is only eight bytes, thatโs not very much data.โ Now weโre dealing with gigabytes now in our PCs. Thereโs a lot of information in an eight byte. You could put a lot of information down the tube in eight bytes. You can put a lot of frames down the tube.
This CAN bus is running about 2% full. I can run this CAN bus, and I will today if you want me to because I can do it with a t-program, a little sneaky method I made. I can crank this bus up to 100% full just like that, and it will still get data through.
Now, [00:08:42] you put too much data, there is a limit to how much data that goes on the bus and you will get whatโs called dropped frames. The system is set up so that some frames might not get through, and thatโs kind of a decision thatโs made up of the application. If you just canโt get it through, you just give up after a while. The application gives up. So is my bus is too full, I canโt get that through. Doesnโt cause an error on the CAN frame. It doesnโt cause any problem on the CAN frame. Itโs just frame is too busy. If thereโs too many people in the room talking, nobodyโs going to understand me, so. A frame never gets through in some cases. But we can do that a little bit later.
I just wanted to show you, this is real stuff, this is real data. I have this data right here and weโre going to get more into that in a second.
Let me go back to the presentation. So weโre on this slide when we took a break. This again is representative of some data captured by a different tool. I was getting in it. I explained what each of one [00:09:42] the blocks of data are so thereโs no mysteries here. Now weโre going to talk about the data itself. Weโre going to get into understanding what that data is.
So let me go to the next slide. So the data field, how is the data represented? This is what I call a raw data. It is a difficult thing to interpret. Itโs not made for humans to interpret it or understand it because the text code is made for computers to interpret. They speak that language. Thatโs what computers do. Thatโs their native language, hacks or binary. For J1939, at least the key is the specification. That really tells you what the data is. We specify whatโs called PGNs and SPNs and weโre constantly on the J1939 committee assigning new SPNs for new pieces of data that arenโt yet standardized, that different manufacturers want to put on the data bus, things for automated vehicles or target on the right-hand side [00:10:42] behind the bumper, or whatever. Different companies come to us. The Standards Committee, they say, โI need an SPN for this.โ Well, thatโs the data. Weโre defining different data and weโre defining it by changing the J1939 specification, one of the specifications. Thereโs many of them. Thereโs one or more J1939 specification for each layer of the communications.
So as an example, J1939-11 is the physical layer specification for 250K physical layer. J1939-14 is the physical layer specification for the 500K physical layer, which is different. You go all the way up, J1939 -73 or -71 is a applications layer that defines some of the applications data. Anyway, the spec is the key. How that key is communicated, how that information is [00:11:42] communicated to a computer is by something called a DBC file, a very important file. It describes what the data is and what the CAN is in the DBC file.
Itโs an industrial standard. For those programmers in the room, it is based on an XML format, which is just another standard that just defines how you make a file that different computers understand, write to or read to, whatever. A DBC file is fixed for any given CAN network. It changes as the network revolves but at any given time when itโs running itโs a fixed thing. Boom, youโve got a DBC file. Most computers use the DBC file. They donโt write to it. We actually have a DBC file editor thatโs free on our website. You can download it. You can look at a DBC file. I will use it as an example. You can find meaning and find what the DBC file means. You can change a DBC file, if you want, with our DBC editor. [00:12:42] Thatโs free on our website.
Basically, when it comes to the data, the biggest thing a DBC file does is it labels the data, it defines the data within the data structure of a CAN frame, and then it sets scaling and offsets of that data. It defines what type of data it is, floating-point data, signed integer data, unsigned integer data, whatever, and then none of them tells you where it is, what it is but how to scale it and offset it to get to the number, the meaningful number that you want from that data. Thatโs a DBC file.
Hereโs a graphical representation I made to help explain how a DBC file works. Now, probably the most important thing to understand on this is not all CAN networks even have a computer on them. When I use the term computer, I specifically said are embedded processor or embedded system. [00:13:42] A CAN network, sometimes, itโs a completely closed network that nothingโs monitoring or seeing other than small little smart devices and theyโre communicating data and making decisions and controls based on that data. So this could be an 8-bit processor using a very rudimentary form of a DBC file that we wouldnโt even recognize as a DBC file. In a computer, itโs a dot DBC file, but that doesnโt mean in every application it has to be able to read a file of that type. But in a computer, youโve got a computer application, this may be ATI VISION or one of the other partner softwares that we deal with from other partners, for an application or maybe an industry specific application, itโs going to reference the DBC file when itโs used in that form to understand what the data is.
So, we got a network, we all know what a network looks like now. Weโre all very comfortable with the voltages on that network and how itโs structured. The other Kvaser interface plugs into that network [00:14:42] and we got a USB. This is a simple Kvaser interface and we got a USB cable, in this case coming to a computer. What does the Kvaser interface do? What layers does it handle?
This is the first thing that Troy told me when I got hired on Kvaser about understanding what Kvaser interface is. It delivers CAN frames here. Thatโs all it does. It has no idea whether thatโs J1939 or CANopen or NMEA 2000, itโs just delivering the data here. Everything else thatโs done with the data is done in the application, or the embedded processor or embedded system out here. So itโs really quite simple. Itโs a very reliable device that just delivers the raw data to the USB port.
In the case of a data logger, it stores and saves their all data and itโs much more complicated system because itโs configured from an application and all that. But thatโs the function of it. Deliver that raw data. In this particular example, I threw a display up here, or an instrument or something, just as [00:15:42] generally when you got something out on a CAN bus itโs doing something, controlling something, displaying something, sensing something, itโs got a purpose on the CAN bus, itโs not just there for the hell of it. In this case I just threw a display up there, or an instrument or something, to indicate that, yes, this data is going to be used for something. So thatโs my DBC file explanation graphically.