Digital Tachometer for Harley Davidson Sportster (Part 3 - Harley Davidson and SAE J1850 VPW)05 Jul 2016 - 0 Comments
The best and shortest way to understand this protocol is to read this document. The longest way is to read directly the SAE J1850 documentation. Nevertheless, in this post I will try to summarize the most relevant concepts of this protocol in order to be able to write the proper code to receive and interpret the ECM messages.
According to the standard SAE J1850 VPW, in our bike we will have 1-wire data bus where the information will be broadcasted based on different voltage levels and tranmission timings. These levels are:
- Passive: 0 - 3,5V (natural state of the data bus)
- Active: 4,25V - 20V (control units can activate the bus through transistors)
Main bus properties are:
- Serial bus: information is sent bit by bit.
- Asynchronous: broadcasted information between nodes is managed by the same emitter instead of beeing synchronized by another clock signal.
- Master-less: there is no node with superiority over the others.
- Peer to peer: All nodes have same capability to transmit.
One important property of the nodes is that when one is transmitting to the data bus, it listens to itself to check if what it says is the same that is in the data bus. In following lines we will understand why.
In this kind of buses everybody will be able to transmit, for this reason it is necessary to set specific rules in order to not have chaos. It can be mainly summarized in 2 rules:
1- The node who wants to transmit first listens to the bus.
- a) If bus is empty during a certain period of time (nobody is transmitting), then this node is allowed to start the transmission.
- b) If someone is already transmitting, then it will wait for the transmission to finish and an additionally specified time before it is allowed to start its own transmission.
Everything is managed by voltage levels. As said before, the bus is passive in natural status and therefore the nodes only have activate o deactivate the transistor in order to change the bus to active or passive mode. If one node is transmitting a passive bit but it reads an active bus, this means that some other node is transmitting at the same time.
Everything lays in the 3 bytes in the message header. There, one of these bytes shows the message priority stablished by the engineer who decided which messages were more important (e.g. RPM message should be more important than a Temperature message because in one second, temperature will not change dramatically, but RPM can vary a lot).
Messages with higher priority will be then those with more active bits at the beginning of the header.
Structure of a Harley Davidson message:
With this format, the maximum number of bytes is set to 11.
The node starting to transmit has to start with an active bit during 200us. After this time, it will proceed with the header.
It can be set from 1 to 3 bytes. In the case of Harley Davidson we will find 3 bytes:
Header byte#1 meaning:
Example (RPM: $28 $1B $10)
- 001: Value close to high priority
- 0: 3 bytes header
- 1: IFR not necessary
- 0: Functional address
- 00:- $1B
- Target address / Primary ID: RPM - Status ID $10
- Source address (ECM: Engine Control Unit)
- Remark: Other source addresses: 40 (Display), 61 (Body Control)
Target address and message body are specified in the SAE 2178-4 (Message Definition for Three Byte Headers).
Primary IDs use to have Secondary ID that allow to have more detailed information. In the RPM example, the Primary ID ($1B) has 3:
The PRN (Paremeter Reference Number) is a reference that is specified in this SAE 2178-4 for all the Secondary ID. With this PRN we will be able to go to the SAE 2178-2 (Data Parameter Definitions) and know how many bytes we will receive, which formula use to have a decimal value and which units we should expect.
For example, if we look for PRN 000C (RPM - High Resolution), it will tell us that the units are RPM and the resoution is 1/4 (1bit=0,25 rpm). Therefore, if we receive the bytes 28 1B 10 02 0A F0 we will have:
DATA BITS:Broadcasted information through the bus is based in 0s and 1s. This protocol has the characteristic that the broadcasted 1s and 0s can be active and passive.
Example using the same 1st byte of the previous header (0x28: 0b00101000): As you can see, the bits alterante every time between active and passive. As the SOF forces the first state (active), the first bit of the header will be passive and the rest will start alternating. All the bits within the bytes of the message will be transmitted starting by the most significant bit, this means bit7, bit6,..., bit0.
Remark: As you can see, a Passive 0 will always win a Passive 1 (0 is temporary shorter and therefore it will change to the next bit (active) sooner and therefore the passive 1 will loose arbitrariety). The same occurs with the Active 0, this is temporary longer than the Active 1.
Physical Layer:- 1-wire bus used to transmit 1s and 0s at a specified speed of 10,4 Kb/s through VPW.
- Cable maximum length: 40m
- Maximum number of nodes (Control Units): 32
- A 0 bit will always rule over a 1 bit
- Maximum number of bytes in the message body: 12