21.10.2016
After a few days, the LIN transceivers arrived. Today I built a protoboard like described on MCP2004 application notes. I also added a diode 1N4001 to avoid polarity problems. I connected an Arduino Nano, but soon changed to an Arduino Leonardo because this board has two hardware Serial ports...and I read that under certain conditions SoftwareSerial is not good (e.g. setting port baudrate to 19200 8E1).
I performed some tests with a LIN slave device which provides sensor data via LIN, and a LIN master simulated by PC + Hardware. I could read some "strange" UART bytes, but never found the sync-byte 0x55.... very strange.
Later I decided to look for the Synchronisation-Break-Field which is 13 to 18 bytes long (up to 40% tolerance)...and also got disturbing results.... I worked on this for at least two days, until I decided to see the signal on an oscilloscope. So I went to the lab at work, and ohh surprise, lab was just moving to another place...and I couldn`t wait ! And at home I also (still) don't have any oscilloscope to view the signal.
Solution: built my own simple oscilloscope...as fast as possible. So I just wrote a simple Arduino code which outputs via UART the LIN signal; "1" for HIGH and "0" for LOW. LIN was set up at 19200 (52µs/bit), and UART on Arduino was set up at 115200 baud, so six times more. At least twice or three times of LIN resolution would be fine to visualice in on PC.
Then I wrote in 10 mins a simple tool on Visual C++ with OpenCV which reads the UART COM port and shows the signal in a simple line-graph. To avoid scrolling of image, I just showed live data on several lines...
and this is what came out...
and this is what LIN shoud look like...
mmm so not exactly the same.... So I thought about this problem, and looked again at PC software tool which controls LIN Master hardware....and I found the problem! System was in a special modus giving out UART signal, and not LIN signal. So I changed from "RealTimeMode" to "LIN_2.1 Mode".
This is the result now:
So looks much better now ! SynchBreakField is visible, LIN signal length is now plausible. The drawing is only inverted, so HIGH is low line, and LOW is high line in the graph.
Now I decided to write my own physical layer LIN decoder by measuring the signal level time on PIN x. First I will look for 52µs +/- tolerance LIN bits, then synch to SynchByte 0x55, and read PID and slave data afterwards. If this works fine, I can go back to cheaper and smaller Arduino Nano. After decoding successfully this data, I will write it on SD card etc...
BTW, I decided Santa Claus will surprise me with a nice gift: a Rigol DS1054Z 4 channel 50 MHz oscilloscope...which can be hacked up to 100 MHz, 24 Mpts recording, LAN, 2xUSB, and I2C/SPI/UART decoding for free ! ( no LIN decoding... :( but this is not a problem now). I can buy this great oscillscope at Conrad for around 395,- EUR.
13.10.2016
The idea to build a LIN datalogger was inspired by a colleague from my company. He told me that there are some customer complaints for a specific function in the car, and that our company is not able to reproduce this problem; also not with real customer car during 4 weeks of testing. So his idea was to connect a LIN datalogger into the car, so when the problem occurs at customers side, customer should remember date and time, or better, use a trigger button if available to set a mark in the logs, and dealers workshop would get back the datalogger with the logs to provide to development/testing team for further analysis.
So he asked development team and other teams for such a simple datalogger, but without success. Of course he would be able to connect other dataloggers from well known brands, but those are very expensive and include many other interfaces and protocols which are not interesting.
So I decided to build my own LIN datalogger, and after investigating for a good LIN transceiver, I decided to use the one from microchip, MCP2004.
Hardware / electronics:
- Arduino Nano, 16 MHz
- MCP2004 LIN transceiver
- RTC
- SD card
- buzzer
- some resistors, condensators & diodes
Housing / connectors:
- small housing (l x w x h 110mm x 55mm x 21mm)
- banana connectors for +12V, GND, LIN
- 1x2 or 2x2 connector for trigger button (via cable to center arm rest)
- Power ON/Status LED (red), LIN LED (green), SD card LED (blue?)
What was done until now:
- circuit diagram drawn
- LIN basic specification read
- 3 x MCP2004 were ordered (ebay/Conrad) and will be shipped on 14.10.2016 (cost EUR 1,30 each :) + EUR 5,95 shipping :(
Next steps:
- build basic circuit on protoboard
- test functionality with real LIN bus
- output all LIN data to serial terminal
- try to identify PIDs and Frame data information, Checksums etc
Further steps:
- add SD card and RTC functionality
- add trigger button
- add buzzer to signalize triggering and some error conditions
- check RTC data consistency (RTC battery low/empty?) with last EEPROM RTC data stored
- generate logging file by filtering required data (PIDs / Data)
- think about configuration file in SD card to set filters there (not hardcoded, user friendly)
- write some relevant data into EEPROM like amount of triggers set, errors codes etc
Possible problems / things to verify:
- Arduino Nano has only one HW serial interface, which is already used by its own to flash the µC and communicate via USB with the outer world. So I will check if Serial communication via Software is possible and fulfills the needs.
- determine best way to store data on SD card. Take into account abrupt power disconnection while SD file still open and writing. Analyse if a bigger Electrolyt condensator at power line is enough to close SD card file and avoid corrupt data.
- check whole system for robustness to reverse polarity (diode), temperature problems, short circuits etc. This is very important if unit will be used in customers car
- check whole system in running conditions in the car (all kind of temperatures, humidity & terrains (shaking) )