Home  |  Contents 
Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: Auto CAN Bus Interface via MM? Post ReplyPost New Topic
Page of 2 Next >>
Author
Message << Prev Topic | Next Topic >>
Andrew_G
Senior Member
Senior Member


Joined: 18 October 2016
Location: Australia
Online Status: Offline
Posts: 127
Posted: 14 September 2017 at 5:34am | IP Logged Quote Andrew_G

Hi, I (and my mechanics) have spent months tracking a problem with my beloved car, "the beast" (a 1997 VS Holden Statesman V8 - 250k, barely run in). It would have been easier to diagnose with on-board access to the fault codes via the CAN bus (I think it uses OBD1 but I'm not yet sure).
Are any of you aware of MM and MMBasic projects that would enable me to access the codes (and potentially other data) off the bus?
(there are lot of expensive products for mechanics and workshops (which my mechanics have) but I am more interested in a DIY approach - if possible).

Thanks, Andrew

Edited by Andrew_G on 14 September 2017 at 5:46am



Back to Top View Andrew_G's Profile Search for other posts by Andrew_G
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 718
Posted: 14 September 2017 at 7:43am | IP Logged Quote lew247

ODB2 dignostic tester (click this)
IT's a lot cheaper than anything you can build, works great and you can get software for your android phone that interfaces with it and not only tells you the code problems and other information but you can also clear the faults from the ecu
Works with all OBD-II compliant vehicles I've had one for a few years and it's great

EDIT:
Quote:
I've just done some research and the Holden Statesman was OBD-II complient from 1995 onwards so this WILL work with yours

and its great for anything OBD-II

EDIT 2:
IF you use the car make/model search on the page it says "This item does not fit Holden Statesman 1997 VS [1995-1999] Saloon"
However it will and does work as confirmed HERE

Edited by lew247 on 14 September 2017 at 7:51am
Back to Top View lew247's Profile Search for other posts by lew247
 
CaptainBoing
Guru
Guru
Avatar

Joined: 07 September 2016
Location: United Kingdom
Online Status: Offline
Posts: 340
Posted: 14 September 2017 at 7:56am | IP Logged Quote CaptainBoing

lew247 wrote:
ODB2 dignostic tester (click this)
IT's a lot cheaper than anything you can build, works great and you can get software for your android phone that interfaces with it and not only tells you the code problems and other information but you can also clear the faults from the ecu


+1

Bluetooth to your moby is the way to go. Search your favourite App store for "Torque Lite" (free version) will show the codes etc on the run and gives basic performance graphs etc. there are other options including paid that will give enhanced data but I have never needed anything more. It does allow you to selectively clear fault codes too.

There was a version of MMBasic that supported CAN (V4.something? maybe see here as a thing to get you going? : http://www.thebackshed.com/forum/forum_posts.asp?TID=4702
I think it was for MaxiMite) and you can get CANBUS interface modules cheaply on ebay so if you still want to go down that route it is do-able. I wouldn't recommend using an old version of the language but CAN can be programmed reasonably easily... maybe someone on here has CFunctions for it


Edited by CaptainBoing on 14 September 2017 at 8:03am


__________________

all you need is duct tape and WD40 (if it moves and shouldn't, use duct tape; if it doesn't move and should, use WD40)
Back to Top View CaptainBoing's Profile Search for other posts by CaptainBoing
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 718
Posted: 14 September 2017 at 8:04am | IP Logged Quote lew247

You can also get the full version of Torque off certain sites - and it works great - does everything you'll ever need
The only thing it doesn't do is tell you what the fault codes mean, but you can look that up on google, you'll have your phone with you anyway to run the app
Back to Top View lew247's Profile Search for other posts by lew247
 
JohnS
Guru
Guru


Joined: 18 November 2011
Location: United Kingdom
Online Status: Offline
Posts: 1546
Posted: 14 September 2017 at 9:37am | IP Logged Quote JohnS

+1 on an elm327

You can get BT, WiFi & USB versions - pick which suits you.

If you need help with codes etc post 'em...

Don't just clear them as you'll lose data and may cause further trouble.

Even if / when no codes, at least check fuel trims (LTFTs) parked with a hot engine. Should be near zero.

John
Back to Top View JohnS's Profile Search for other posts by JohnS
 
CaptainBoing
Guru
Guru
Avatar

Joined: 07 September 2016
Location: United Kingdom
Online Status: Offline
Posts: 340
Posted: 14 September 2017 at 11:39am | IP Logged Quote CaptainBoing

OBDII generic fault codes
2017-09-14_113945_OBDII_Generic.zip

you'll probably still end up googling to find more info but this is a quick get-you-going list

Edited by CaptainBoing on 14 September 2017 at 11:41am


__________________

all you need is duct tape and WD40 (if it moves and shouldn't, use duct tape; if it doesn't move and should, use WD40)
Back to Top View CaptainBoing's Profile Search for other posts by CaptainBoing
 
Andrew_G
Senior Member
Senior Member


Joined: 18 October 2016
Location: Australia
Online Status: Offline
Posts: 127
Posted: 16 September 2017 at 3:12am | IP Logged Quote Andrew_G

Many thanks for your replies. Yes the ELM327 looks interesting. Do any of you know if the USB version sends out a usable (eg serial?) data stream?

You helped me change my search to "CANBUS", rather than "CAN BUS", which yielded much more useful results.
The material on here looks a little dated and more complicated than I had hoped eg there is reference to "CANVIEW.BAS" but I couldn't see any BASIC code (but plenty of C - ugh).

Cheers, Andrew

(PS "the beast" is running well now with a new crankshaft position sensor (new distributor) at no charge from the service people (JustService - in Moorrabbin, Melbourne))
Back to Top View Andrew_G's Profile Search for other posts by Andrew_G
 
JohnS
Guru
Guru


Joined: 18 November 2011
Location: United Kingdom
Online Status: Offline
Posts: 1546
Posted: 16 September 2017 at 6:08am | IP Logged Quote JohnS

The common USB elm327 has the DLC (OBD connector) on one end and a USB A on the other. You can plug it into a PC and fire up either specific OBD software or a terminal emulator (e.g. Windows HyperTerminal, Linux minicom or screen or ...) and talk straight to it. (It's what some call a virtual COM port.)

A typical car now has several OBD-style interfaces at the DLC, on the defined and often on the reserved pins. It really helps to have the car's electrical diagrams. E.g. a car I had a while back had ISO-9141 K-line (pin 7), Ford's SCP (pins 2 & 10) and CAN (6 & 14). An elm327 can talk to the standard ones but only one at a time (you can switch between them should you wish to).

Note: you typically need the car's ignition on (or engine on) to power the DLC and thus the elm.

There are excellent data sheets on the elm site Elm Electronics

It's a bit like the modems of old, with AT... commands.

The USB version (elm327) is basically a serial-USB chip connected to the elm chip. You can get the basic elm chip from elm (choice of protocols) or take apart a USB elm327 if you just want direct access to the serial data.

The elm site even has Gerbers (or links to them), schematics, etc.

John

Edited by JohnS on 16 September 2017 at 6:14am
Back to Top View JohnS's Profile Search for other posts by JohnS
 
Andrew_G
Senior Member
Senior Member


Joined: 18 October 2016
Location: Australia
Online Status: Offline
Posts: 127
Posted: 16 September 2017 at 7:39am | IP Logged Quote Andrew_G

John, thanks. That's just what I wanted to hear.
I want to be able to download the fault codes via the ELM327 device (on the rare occasion there is a fault) OR capture and display other data.
The main data I am looking to capture is the speed - I have made a nifty little display of digital speed via a GPS. A button press shows the current and average speed since the last button press. We have several "Point to Point" speed detection sites that measure your average speed over x km - x varies from 2 to 50+ km. They read your number plate and send the fine in the mail (the allowance is only 2kph). The GPS is good except I go through a couple of tunnels and it all drops out. By capturing the vehicle speedometer it adds another check. (I might even go back to Traffic Engineering 101 and look at Space Mean Speed vs Time Mean Speed).

Thanks again, Andrew.
Back to Top View Andrew_G's Profile Search for other posts by Andrew_G
 
JohnS
Guru
Guru


Joined: 18 November 2011
Location: United Kingdom
Online Status: Offline
Posts: 1546
Posted: 16 September 2017 at 8:27am | IP Logged Quote JohnS

Speed is easy. It may well read a bit different to the dash (speedo) as usually those over-read.

Speed is PID 0D (hex) e.g. see OBD PIDs

(That page refers to modes but that's not their official name.)

Any OBD app will typically show it but it's quite easy by hand / by own program.

GPS and OBD speeds may differ not least due to GPS issues but also your wheel (tyre) size varies with wear, pressure etc. Not usually a big issue...

John
Back to Top View JohnS's Profile Search for other posts by JohnS
 
Andrew_G
Senior Member
Senior Member


Joined: 18 October 2016
Location: Australia
Online Status: Offline
Posts: 127
Posted: 03 October 2017 at 7:45am | IP Logged Quote Andrew_G

Hi again, it is NOT a big deal as I only spent less than $20, and the beast is running well, but:

The Elm327 (USB) device arrived a few days ago and has some drivers and software "ScanTool.net v1.21" on a CD. I can't get it to fire up and configure the comm port (it locks in the main menu). At that price the seller is likely to stick to their fine print "all care and no responsibility . . ." for the s/w.

The only Torque s/w I can see is for phones etc. (rather than an old laptop running XP).
I've tried Hyperterminal (which I'm comfortable with) but can't get any response to AT commands.
If I could crack hyperterminal I'd have a chance of reading speed etc.

Any comments/suggestions? (as I say above NOT a big deal)

Cheers, Andrew
Back to Top View Andrew_G's Profile Search for other posts by Andrew_G
 
retepsnikrep
Regular Member
Regular Member
Avatar

Joined: 31 December 2007
Location: United Kingdom
Online Status: Offline
Posts: 76
Posted: 03 October 2017 at 7:54pm | IP Logged Quote retepsnikrep

I think building your own OBDII reader from scratch is more fun.
First of all read the wiki about the OBDII protocol and what to expect.

I used picbasic pro in my projects to program bare 12F683 & 16F886 pics and later 18F2680 can enabled pics for OBDII KLine and later canbus work...

This KLine example below might give you a few clues and will probably translate fairly easily into Maximite basic..

Once you get started and have something working with KLine stuff then you can read up about canbus which is a very different much more complicated beast..

The ELM327 datasheets and example schematics were very useful to build the basic hardware interface to the OBDII port 12v KLine. (You just need an NPN transistor, base current limit resistor and and pull up resistor IIRC) I obviously did not use the elm chip itself but programmed my own microcontroller.


'------- Picbasic Pro  Compiler version PIC12F683 - 040911 - V0.06 Alpha -------
'-------------- Note this software requires the MPASM assembler ----------------
'-------------------------------------------------------------------------------
'**************************** General Information ******************************

'This module carries no warranty or guarantee of any kind! It is used at
'your own risk, and I make no claims as to it's suitability for a particular
'function. Prospective users must evaluate the system before using it, and no
'liability will be entertained by myself in any shape or form whatsoever.
'The modules and software have been produced at low cost for the benefit of
'the EV & electronic community. Be aware that undisclosed vehicle
'modifications can lead to invalidated insurance and warranty issues. You the
'end user remain fully liable for any modifications made to your vehicle.   

'** PIC12F683 Pinouts FLASH 2048 (words) SRAM 128 (bytes) EEPROM 256 (bytes) **

'                                    Top                         
'                                   _____
'(+ VCC Supply)                  +Ve -1|  ^  |8- -Ve                (- GND Supply)
'(H Line Out)                   GP5 -2|  6  |7- GP0           (ICSPD & K Line In)
'(Button In & Logger Out)    GP4 -3|  8  |6- GP1          (ICSPC & K Line Out) 
'(H Line In & MCLR Reset)    GP3 -4|  3  |5- GP2             (Lcd Display Out)
'                                   ----- 

'KLine 12V OBDII I/O 10400 Baud Serin2 Mode = 76, Serout2 Mode = 16460

'***** PIC12F683 ICSP In circuit serial Programming Pinouts 5 Pin Sil 0.1" *****

'1) MCLR
'2) +5V
'3) GND
'4) Data
'5) Clock 

'************************ Display Module Specification *************************

' 0) Sparkfun 16x2 Serial Display White on Black 5V Part Number : LCD-09395

'************************ Gauge Module Specification ***************************

'Board Supply Voltage Max 16V CPU Speed 8mhz with internal resonator 

'*******************************************************************************
'********************** Program Size 1210 out of 2048 Words ********************
'*******************************************************************************

'        _OBD REQUEST_               __ OBD DATA RESPONSE ___        ___  OBD DTC RESPONSE ______
'       /             \             /                        \      /                            \  
'      Header   M  P  C            Header  M  P  DATA BYTES  C     Header  M    DATA BYTES        C
'         |     O  I  R              |     O  I    __|____   R       |     O      __|__________   R
'         |     D  D  C              |     D  D   /       \  C       |     D     /             \  C
'        _| _   E                   _| _   E     A  B  C  D         _| _   E    A  B  C  D  E  F
'       /    \                     /    \                  /    \     
'Send  68 6A F1 01 05 C9    Recd  48 6B 0A 41 05 xx          xx   48 6B 0A 43   xx xx xx xx xx xx xx



'------------------------------ General configuration --------------------------
#config
 __config _FCMEN_ON & _IESO_ON & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTOSCIO
#ENDCONFIG

Define OSC 8               'Set PBP processor speed to 8 Mhz  
INTCON = %00000000               'Clear Interrupts
OSCCON = %01110101          'Sets internal osc to 8 Mhz (Default) and stable
CMCON0 = %00000111                'Comparators off
TRISIO = %00011010               'Set Pin GPIO.1, GPIO.3 & GPIO.4 as Inputs
ANSEL  = %01011000              'Set AN3 as Analog Input fosc / 16
ADCON0 = %00001101          'Turns A/D on, A/D reads (AN3), left justify and Vref=Vdd

'T1CON  = %00110000          '$30 = Prescaler 1:8, TMR1 OFF          

'Debug is used as it is the fastest and smallest serial routine to drive the Lcd display
 
DEFINE DEBUG_REG GPIO          'Set Debug pin port
DEFINE DEBUG_BIT 2          'Set Debug pin bit for Lcd Display GPIO.2
DEFINE DEBUG_BAUD 9600          'Set Debug baud rate 9600 approx 960 cps
DEFINE DEBUG_MODE 0          'Set Debug mode: 0 = true, 1 = inverted (T=True Idle High)(N=Inverted Idle Low)

Define ADC_BITS         8       'Set number of bits in result
Define ADC_CLOCK        3       'Set Clock source (3 = rc)
DEFINE ADC_SAMPLEUS     50      'Set sampling time in uS


'*******************************************************************************

'Variables Constants and I/O definitions

'------------------------ Variables 16bit --------------------------------------

Result       var WORD          'Returned Data from PID request

'------------------- Variables 8bit --------------------------------------------


Dtc       var BYTE[5]        'Array for DTC codes display 5 bytes i.e. "P1447" as ASCII
D       var BYTE[5]          'OBDII Rxd Data 6 Bytes Array 0-5 D[0] to D[5]     

H1       var BYTE          'OBDII Rxd Header Byte 1
H2       var BYTE          'OBDII Rxd Header Byte 2
H3       var BYTE          'OBDII Rxd Header Byte 3
M1       var BYTE          'OBDII Rxd Mode Byte           
P1       var BYTE          'OBDII Rxd Pid Byte
     

C1       var BYTE          'OBDII Rxd Checksum Byte

Pid       var BYTE          'OBDII Txd PID Request Byte 0-255 Pids (Parameter ID's)
ChkSum    var BYTE          'OBDII Txd Checksum Byte 
 
Key        var BYTE           'Returned Button Value (0-5) 5 = No key pressed
Gen       var BYTE          'Gen is a General Use Byte variable (0-255)
Lcd       var BYTE          'Lcd Type EEprom Address (0 = SparkFun) (10 = TextStar)
HighB       var BYTE          'DTC HighB Byte
LowB       var BYTE                   'DTC Low Byte

L01       VAR BYTE              'Lcd Serial Control Code  Clear
L02            VAR BYTE              'Lcd Serial Control Code  Clear

L11         VAR BYTE              'Lcd Serial Control Code  Line 1
L12       VAR BYTE              'Lcd Serial Control Code  Line 1
L13       VAR BYTE              'Lcd Serial Control Code  Line 1
L14       VAR BYTE              'Lcd Serial Control Code  Line 1

L21           VAR BYTE              'Lcd Serial Control Code  Line 2
L22       VAR BYTE              'Lcd Serial Control Code  Line 2
L23       VAR BYTE              'Lcd Serial Control Code  Line 2
L24       VAR BYTE              'Lcd Serial Control Code  Line 2 

'------------------- Variables 1bit --------------------------------------------

'Config Byte (Bit Assingment) Note * (Default for all bits is 1 after program download)
 
'ErrorFlag VAR Config.Bit0       'BCM Data Error Flag   (1 = Data error) (0 = Data ok)

'--------------------- Constants -----------------------------------------------

'------------------ Pins used for I/O and designations -------------------------

'---------------------- Digital high/low Inputs/Outputs ------------------------

KLineIn         var GPIO.0     'K Line In & ICSP Data Line 
KLineOut     var GPIO.1     'K Line Out & ICSP Clock Line
LcdPin          var GPIO.2     'Serial Lcd Display
HLineIn          var GPIO.3     'H Line In & Master Clear line MCLR
'Button          var GPIO.4     'Joy Button Input & Data Logger Output
HLineOut     var GPIO.5     'H Line Out

'------------------------------ Main Program -----------------------------------

'Load EEPROM with Text Data & Lcd Control Data (256 bytes) Area above Addr 240 reserved for gauge data

'If PID = $04 then TextStart = 0  : Result = (D[0]*100)/255     'Engine Load 0 to 100%
'If PID = $05 then TextStart = xx : Result = D[0]-40          'Engine Water Temp -40 to +215C
'If PID = $0A then TextStart = xx : Result = D[0]*3          'Fuel Pressure 0 to 765 kPa
'If PID = $0B then TextStart = xx : Result = D[0]          'Intake MAP 0 to 255kPa
'If PID = $0C then TextStart = xx : Result = ((D[0]*256)+D[1])/4'Engine Rpm 0 to 16,383 rpm
'if PID = $0D then TextStart = xx : Result = D[0]          'Vehicle Speed 0 to 255 kmh
'If PID = $0E then TextStart = xx : Result = (D[0]/2)-64     'Timing Advance -64 to +63.5
'If PID = $0F then TextStart = xx : Result = D[0]-40          'Air Intake Temp -40 to +215C
'If PID = $10 then TextStart = xx : Result = ((D[0]*256)+D[1])/100'MAF Air Flow Rate 0 to 655.35g/s     
'If PID = $11 then TextStart = xx : Result = (D[0]*100)/255     'Throttle 0 to 100%
'If PID = $15 then TextStart = xx : Result = D[0]/2             'O2 Sensor Bank1 Voltage 0 to 1.28V
'If PID = $2C then TextStart = xx : Result = (D[0]*100)/255     'Commanded EGR 0 to 100%
'If PID = $33 then TextStart = xx : Result = D[0]          'Barometric Pressure 0 to 255kPa

'           L  O  A  D  W  T  E  M  P  M  A  P  R  P  M  M  P  H  A  D  V  A  T  E  M  P  M  A  F
'EEPROM 0, [76,79,65,68,87,84,69,77,80,77,65,80,82,80,77,77,80,72,65,68,86,65,84,69,77,80,77,65,70]


EEPROM 246, [254,1,254,128,254,128,254,192,254,192]     'SparkFun Lcd Control Codes

'**************************************************************************************************************     

'OBDII Gauge Main Program 


Start:                                         'Start of Program 

     Low KLineOut                                 'Set K Line High (1) Default Condition
     Low HLineOut                                 'Set H Line High (1) Default Condition
     high LcdPin                                 'Set LcdPin high for later data transfer 
     Clear                              'Clear All Variables
     Lcd = 246                         'Set EEprom Address Default Lcd As Sparkfun
     PID = 5                              'Set Start Up PID to Engine Temp $05
     
     Read Lcd,L01,L02,L11,L12,L13,L14,L21,L22,L23,L24     'Load Lcd Control Codes from EEprom
     
     pause 3000                                   'Pause for 3 seconds wait for lcd

ModeSelect:
     
     DEBUG L01,L02,"Mode OBD=D"     'Display 
     
     pause 2000

ModeLoop:

     'Check if a button is pressed Push = 0 Up = 1 Right = 2 Down = 3 Left = 4 No Key = 5

     Gosub KeyPress                         'Gosub KeyPress Routine 5 = No Key Pressed 
     if Key = 3 then ObdiiInit               'If Key = 3 (Down) goto OBDII INIT
     goto ModeLoop                         'Goto ModeLoop


'************** OBDII MODE ***********   

ObdiiInit:                                            'Initialise OBDII Bus with Bit Bang Routine 

         DEBUG L01,L02,"Starting OBDII"
               
     'Slow Init Send 0x33 (00110011) at rate of 5 baud (LSB) with a Start Bit and a Stop bit. (200ms per bit)

     High KLineOut                                'Set K line low (0)
     Pause 200                                    'Pause 200ms (1 bit)
     low KLineOut                                 'Set K line high (1)
     pause 400                                        'Pause 400ms (2 bits)
         High KLineOut                                'Set K line low (0)
     pause 400                                    'Pause 400ms (2 bits)
        low KLineOut                                 'Set K line high (1)
     pause 400                                    'Pause 400ms (2 bits)
        High KLineOut                                'Set K line low (0)
     pause 400                                    'Pause 400ms (2 bits)
         low KLineOut                                 'Set K line high (1)
         Pause 400                                    'Pause 400ms used if not going to rxd init bytes $55 $08 $08
         SEROUT2 KLineOut, 16460,[$F7]               'Send 1 data byte on K Line Inverted Mode
        SERIN2 KLineIn, 76, 100, ModeSelect, [Gen]     'Receive 1 data byte on K Line. Starts 35ms after end of txd above

            if Gen <> $CC then ModeSelect                 'If OBDII Bus initialisation failed then ret to Mode Menu

ObdiiMode:                                      'ODBIIMODE Menu
   
        DEBUG L01,L02,"OBD DTC=U       CDTC=D MO=P"     'Display 
        pause 2000                              'Pause 2000ms 

'************** PID Routine Displays 4 OBDII Parameters ***********    
      
ObdiiLoop:                              'OBDII Loop Label

     'Check if a button is pressed Push = 0 Up = 1 Right = 2 Down = 3 Left = 4 No Key = 5              
     
     Gosub KeyPress                         'Gosub KeyPress Routine 5 = No Key Pressed

     if Key = 0 then ModeSelect                       'If Key = 0 (Press) goto ModeSelect
     if Key = 1 then gosub ReadObdDtc                    'If Key = 1 (Up) gosub ReadObdDtc
     if Key = 3 then gosub ClearObdDtc                    'If Key = 3 (Down) gosub ClearObdDtc

     Debug L11,L12,L13,L14                    'Set Display to Line 0, Column 0

     PID = $05                         'Set Coolant Temp PID
     gosub PidDisplay                    'Gosub PIDDISPLAY Routine
     PID = $0F                         'Set Intake Temp PID
     gosub PIDDISPLAY                    'Gosub PIDDISPLAY Routine
     
     Debug L21,L22,L23,L24                    'Set Display to Line 1, Column 0
     
     PID = $04                         'Set Engine Load PID
     gosub PIDDISPLAY                    'Gosub PIDDISPLAY Routine
     PID = $15                         'Set O2 Sensor PID
     gosub PIDDISPLAY                    'Gosub PIDDISPLAY Routine
    
      goto ObdiiLoop                         'Goto ObdiiLoop

PIDDISPLAY:                              'PID Data Retrieval & Display Routine     
     
     ChkSum = $68 + $6A + $F1 + $01 + PID          'Calculate Mode 1 CheckSum Byte

     SEROUT2 KLineOut, 16460,[$68,$6A,$F1,$01,PID,ChkSum]     'Txd PID Request on K Line Inverted Mode
     SERIN2  KLineIn, 76, 100, EndPid,[H1,H2,H3,M1,P1,D[0],D[1],D[2],D[3],C1]     'Rxd OBDII Data          

EndPid:                                   'Jumps when data missing or stops for 100ms
     
     Result = 0                         'Clear Data Word
     
     If PID = $04 then                    'Engine Load 0 to 100%
     Debug "Lod"
     Result = (D[0]*100)/255     
     endif

     If PID = $05 then                    'Engine Water Temp -40 to +215C
     Debug "WdC"
     Result = D[0]-40
     endif          

'     If PID = $0A then                    'Fuel Pressure 0 to 765 kPa
'     Debug "Ful"
'     Result = D[0]*3
'     endif

'     If PID = $0B then                    'Intake MAP 0 to 255kPa
'     Debug "Map"
'     Result = D[0]          
'     endif

'     If PID = $0C then                    'Engine Rpm 0 to 16,383 rpm
'     Debug "Rpm"
'     Result = ((D[0]*256)+D[1])/4     
'     endif

'     if PID = $0D then                    'Vehicle Speed 0 to 255 kmh
'     Debug "Mph"
'     Result = D[0]          
'     endif

'     If PID = $0E then                    'Timing Advance -64 to +63.5
'     Debug "Ign"
'     Result = (D[0]/2)-64
'     endif     

     If PID = $0F then                    'Air Intake Temp -40 to +215C
     Debug "IdC"
     Result = D[0]-40          
     endif

'     If PID = $10 then                    'MAF Air Flow Rate 0 to 655.35g/s
'     Debug "Maf"
'     Result = ((D[0]*256)+D[1])/100
'     endif

'     If PID = $11 then                    'Throttle 0 to 100%
'     Debug "Thr"
'     Result = (D[0]*100)/255
'     endif     
     
     If PID = $15 then                    'O2 Sensor Bank1 Voltage 0 to 1.28V
     Debug "O2V"
     Result = D[0]/2
     endif             

'     If PID = $2C then                    'Commanded EGR 0 to 100%
'     Debug "Egr"
'     Result = (D[0]*100)/255
'     endif          

'     If PID = $33 then                    'Barometric Pressure 0 to 255kPa
'     Debug "Bar"
'     Result = D[0]          
'     endif
     
     DEBUG 32,#Result,32                    'Display PID Evaluation Result      
    
     Return                              'Return    

'************** Display OBDII DTC Routine ***********

ReadObdDtc:                              'Gets upto 3 DTC Codes and displays them
    
         for Gen = 0 to 5                           'Start 6 Byte Loop
         d[Gen] = 0                                 'Clear DTC store bytes
         next                                       'Repeat Loop

     SEROUT2 KLineOut, 16460,[$68,$6A,$F1,$03,$C6]     'Txd DTC Request on K Line Inverted Mode
     SERIN2  KLineIn, 76, 500, EndObdDtc,[H1,H2,H3,M1,D[0],D[1],D[2],D[3],D[4],D[5],C1]     'Rxd DTC Data
     
EndObdDtc:                              'Jumps when data missing or stops for 500ms

     DEBUG L01,L02                         'Clear LCD
     
     if M1 <> $43 then 
         DEBUG "No DTC's Set"                    'Display
     pause 3000                                    'Pause for 3 seconds
     return                              'Return to main program
     endif

     Debug "DTC  "                         'Display
                  
     HighB = 0                         'Set High Byte for first DTC
     LowB = 1                         'Set Low Byte for first DTC
     Gosub EvaluateObdDtc                    'Gosub Evaluate first Dtc
          
     DEBUG L21,L22,L23,L24                    'Set Display to 2nd line  

     HighB = 2                         'Set High Byte for Second DTC
     LowB = 3                         'Set Low Byte for Second DTC
     Gosub EvaluateObdDtc                    'Gosub Evaluate second Dtc
     
     Debug 32                         'Display one space               
     
     HighB = 4                         'Set High Byte for Third DTC
     LowB = 5                         'Set Low Byte for Third DTC
     Gosub EvaluateObdDtc                    'Gosub Evaluate Third Dtc

     pause 5000                         'Pause for 5 seconds 

     DEBUG L01,L02                         'Clear LCD     
     
     return                              'Return to main program

EvaluateObdDtc:                              'Evaluate and extract Dtc from returned Data Bytes (2)

     Gen = (D[HighB] & %11000000) >> 6            'Gen now 0-3 (borrow Diag[1] for this op)
     Lookup Gen, [32,19,18,37], Dtc[0]          'Now extract the next four "digits" in the same way.
     Dtc[1] = D[HighB] & %00110000             'Isolate bits 4,5
     Dtc[1] = Dtc[1] >> 4                          'Shift down to bits 0,1
     Dtc[2] = D[HighB] & %00001111             'Isolate bits 0-3
     Dtc[3] = D[LowB] & %11110000              'Isolate upper four bits
     Dtc[3] = Dtc[3] >> 4                          'Shift down
     Dtc[4] = D[LowB] & %00001111              'Isolate lower four bits

     For Gen = 0 to 4                    'Start Loop to Display 5 characters of Dtc 
     Debug (Dtc[Gen] + 48)                    'Sends Ascii Value
     Next 

     return                              'Return to Main Program 

'************** CLEAR OBDII DTC Routine ***********

ClearObdDtc:                              'Clear OBDII DTC's Routine

     DEBUG L01,L02                         'Clear LCD

     SEROUT2 KLineOut, 16460,[$68,$6A,$F1,$04,$C7]     'Clear DTC's Request on K Line Inverted Mode
     SERIN2  KLineIn, 76, 500, EndClearObdDtc,[H1,H2,H3,M1,C1]     'Clear DTC Response

EndClearObdDtc:                              'Jumps when data missing or stops for 500ms     

     If M1 = $44 then                     'If M1 = $44 then DTC's Cleared OK
     DEBUG "DTC Cleared OK"               'Display
     else
     DEBUG "No DTC or Fail"               'Display
     endif

     pause 3000                         'Pause for 3 seconds
     
     DEBUG L01,L02                         'Clear LCD     

     return                              'Return to Main Program 

'************* Get Key Press ************

'Check if a button is pressed Push = 0 Up = 1 Right = 2 Down = 3 Left = 4 No Key = 5

KeyPress:                              'Evaluate Key Pressed 

     ADCIN 3, Gen                         'Read Button ADC input
     if Gen > 234 then key = 5                  'If No key pressed then key = 5
     if Gen < 235 then key = 4               'Test if button 4 pressed 
     if Gen < 192 then key = 3               'Test if button 3 pressed 
     if Gen < 150 then key = 2               'Test if button 2 pressed 
     if Gen < 107 then key = 1               'Test if button 1 pressed 
     if Gen < 64  then key = 0               'Test if button 0 pressed      

     return                              'Return to Main Program  
     


'Mode 3: (no PID required) A request for this mode returns a list of the DTCs that have been set.
'The list is encapsulated using the ISO 15765-2 protocol.

'If there are two or fewer DTC's (4 bytes) they are returned in an ISO-TP Single Frame (SF).
'Three or more DTCs in the list are reported in multiple frames,
'with the exact count of frames dependent on the communication type and addressing details.

'Each trouble code requires 2 bytes to describe.
'The text description of a trouble code may be decoded as follows.
'The first character in the trouble code is determined by the first two bits in the first byte:

'A7 A6    First DTC character
'-- --    -------------------
' 0  0    P - Powertrain
' 0  1    C - Chassis
' 1  0    B - Body
' 1  1    U - Network

'The four following digits are BCD encoded.

'The second character in the DTC is a number defined by

'A5 A4    Second DTC character
'-- --    --------------------
' 0  0    0
' 0  1    1
' 1  0    2
' 1  1    3

'The third character in the DTC is a number defined by

'A3 A2 A1 A0    Third DTC character
'-- -- -- --    -------------------
' 0  0  0  0    0
' 0  0  0  1    1     
' 0  0  1  0    2
' 0  0  1  1    3
' 0  1  0  0    4
' 0  1  0  1    5
' 0  1  1  0    6
' 0  1  1  1    7
' 1  0  0  0    8
' 1  0  0  1    9

'The fourth and fifth characters are defined in the same way as the third,
'but using bits B7..B4 and B3..B0. The resulting five-character code should
'look something like "U0158" and can be looked up in a table of OBD-II DTCs.


'Diag VAR BYTE[5]   ' Array for complete message

'DTC_High VAR Byte  ' Upper byte of message
'DTC_Low VAR Byte   ' Lower byte of message

'i VAR BYTE         ' General purpose

'Get the top two bits of the high byte and shift it down so
'it becomes 0-3. Then convert to the correct character.
'i = (DTC_High & %11000000) >> 6  ' Temp now 0-3 (borrow Diag[1] for this op)
'Lookup i, [32,19,18,37], Diag[0]

'Now extract the next four "digits" in the same way.
'Diag[1] = DTC_High & %00110000   ' Isolate bits 4,5
'Diag[1] = Diag[1] >> 4           ' Shift down to bits 0,1
'Diag[2] = DTC_High & %00001111   ' Isolate bits 0-3
'Diag[3] = DTC_Low & %11110000    ' Isolate upper four bits
'Diag[3] = Diag[3] >> 4           ' Shift down
'Diag[4] = DTC_Low & %00001111    ' Isolate lower four bits


'Now, if Diag[0] is 32 we add 48 to it and it becomes 80 which
'is the ASCII code for "U". If Diag[1] is 2 we add 48 to that
'so it becomes 50 which is the ASCII code for "2" and so on.
'HSEROUT["Error code: "]
'For i = 0 to 4
'HSEROUT[Diag + 48]
'Next 


Edited by retepsnikrep on 04 October 2017 at 5:21am


__________________
Check my website www.150mpg.co.uk for details of my Li-Ion Gen1 Honda Insights.
Back to Top View retepsnikrep's Profile Search for other posts by retepsnikrep Visit retepsnikrep's Homepage
 


Page of 2 Next >>
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1250 seconds.
Privacy Policy     Process times : 0, 0, 0, 0.12