Dual CANbus monitor and instrumentation cluster

Eagle Schematic and Board design

/media/uploads/TickTock/canaryr5.zip

/media/uploads/TickTock/sch_r4.jpg /media/uploads/TickTock/lcdsch.jpg /media/uploads/TickTock/brd_r4.jpg

Parts List

qtyinstancepart #packagesupplierDescription
1BAT3Vhttp://www.ebay.com/itm/10x-CR2032-SMD-Battery-Holder-for-CR2032-Battery-/180938057979?pt=LH_DefaultDomain_0&hash=item2a20bfa8fbLithium 2032 coin battery holder
4C1-C4ECST1DC106R6032Tantalium capacitor 10uF
3FC1-FC3ZF1-20-01-T-WThttp://www.samtec.com/cable-systems/idc-ffc/ffc/zero-insertion.aspx20 conductor 1mm pitch flex cable connector (optional)
1FJ-20-R-08.00-4http://www.samtec.com/cable-systems/idc-ffc/ffc/zero-insertion.aspx8\" 20 conductor 1mm pitch flex connector, end reversed (optional)
2H1-H4(DON'T populate H1-H4 headers - solder mbed directly)
1H5http://www.ebay.com/itm/221186042943?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l26491x12 .1\" pitch header (optional)
1H62x6 .1\" pitch header (optional)
2IC1,IC2VP230LMDSOP8http://www.ebay.com/itm/130488665247?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649canbus transciever
1IC3LM1117-5VSOT2235V regulator
5JP*2 pin .1\" jumper header
1mbedLPC1768http://www.ebay.com/itm/200830573509?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649mbed uC
2Q1,Q22N2222SOT23General purpose NPN transistor
1R1R392M12063.9K resistor
4R2,R4-R6R102M12061K resistor
1R3R500M120650 Ohm resistor
2TR1-TR5ZJYS81R5-2PL51TG01http://www.digikey.com/product-detail/en/ZJYS81R5-2PL51T-G01/445-2223-1-ND/765232CM Choke
1Z11N5340BGC1702-15http://www.ebay.com/itm/150878122425?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l26496V, 5W Zener Diode
1X1USBhttp://www.ebay.com/itm/New-Vertical-USB-2-0-A-pcb-connector-socket-USB-A-Type-/300553895292?pt=LH_DefaultDomain_0&hash=item45fa687d7cvertical USB connector
2LCD0,LCD1TFThttp://www.mikroe.com/add-on-boards/display/tft-proto/320x240 LCD with touch screen

Assembly

1) LCD Displays

I found ribbon cable is a nice way to organize the wires to the displays. You'll need 12 conductors and I connected them in the following order:

1LED+
2LED-
3RSTB
4MOSI
5SCLK
6CSB
7X+
8X-
9Y+
10Y-
11VDD
12GND

First I connected all the GND connections (IM0, IM1, IM3, & 2 GND). Do not connect the bottom GND until you have the ribbon cable connected. After making all the ribbon cable connections (connecting the GND of the ribbon cable to the bottom GND pad), solder the GND bar from the previous step to the back of the bottom GND connection. Finally, make a connection from the back side 3.3V pin to IM2. Take a break and repeat for the second display. /media/uploads/TickTock/lcdtop.jpg /media/uploads/TickTock/lcdbot.jpg Once the two displays are complete combine all wires except CS0, CS1, X+, X-, Y+, and Y-. Connect X- of the left display to X+ of the right. Similarly connect Y- of the left display to Y+ of the right. Insulate any exposed wires.

2) PCB

Refer to the schematics to place all the components on the board. If you plan to install into the CANary 3D enclosure, DO NOT install the battery holder or the socket for the mbed and, instead, connect two wires to the VB and GND pads nearby. You will have to install the battery holder against the back wall to avoid interfering with the right-hand display and the mbed will have to be directly soldered. I have not found a socket with a low enough profile to fit in the space provided (depth of enclosure is limited by the space behind the center console). Also, I recommend keeping as much lead as possible on the Zener diode (bending it as shown to clear the back wall). Although it is operating well within parameters, the Zener gets quite hot during extended operation and the leads help dissipate the heat and keep it away from the PCB and other components.

/media/uploads/TickTock/pcbtop.jpg /media/uploads/TickTock/pcbbot.jpg

Once the PCB is populated, solder the LCDs to the PCB. CS0 connects to the right display and CS1 connects to the left. /media/uploads/TickTock/brddis.jpg

3) Testing

1)First step is to buzz out all connections from the LCDs to the pins in the main board
2)Next check the touch screen connections. On the main board, place an Ohm meter across X+ and X-. You should read 700 Ohms. Repeat for Y+ and Y-. Then test the resistance from X+ to Y+. With nothing touching the screens, it should read >100K Ohms and <1K when touching either screen.
3)When all connections are checked, solder in the mbed. Download and install the touch2 program http://mbed.org/users/TickTock/code/touch2/ to test the basic operation of the mbed and touch screens.
tips:
Touch screen is sensitive - excess flux on X+,X-,Y+,Y- connection on mbed can result in flakey operation
If touch is not working, double-check the LCD0_CS and LCD1_CS are not swapped. LCD0_CS must connect to the CS of the LCD that has X- & Y- connected to the mbed. LCD1_CS must connect to the CS of the LCD that has X+ & Y+ connected to the mbed.
4)Once touch2 works, it is time to connect to the OBD connector. I highly recommend double checking all connections from the OBD to the PCB with the cable in place before connecting to the Leaf. Buzz out all the pins in the OBS to make sure none are shorting to each other, Check that the 12V goes to the Zener (and nothing else) and the switched 12V to the resistor divider (and nothing else). Test the ground connection properly connects to ground and nothing else.
5)Once you are confident there are no shorts or wrong connections from the OBD connector, take a deep breath and plug it into your leaf. Touch2 program should come up and function. Unplug and install the latest CANary firmware. Test all features before installing into the enclosure (gids, cellpair, menu system, logging) since installing and removing from the enclosure is a PITA.

/media/uploads/TickTock/pcbdone.jpg /media/uploads/TickTock/functioning.jpg

4) Enclosure

The 3D printer leaves a lot of powder behind - I used a strong spray of water to get it out of all the cracks. The enclosure comes with a rather rough finish. I recommend convincing yourself you like it, then simply lightly sand then paint before assembly. Sanding is very difficult - the nylon is very nicely fused and doesn't want to sand. I tried sandblasting and that didn't work either. I had some limited success with filler and then sanding, but only on the outside - it is too difficult to sand the face.

5) Final Assembly

Revision:
48:d1ce92104a1f
Parent:
47:9cc7d876dd6d
Child:
49:a3d2c5bb3cfa
--- a/displayModes.cpp	Tue Apr 02 07:23:46 2013 +0000
+++ b/displayModes.cpp	Sat Apr 06 04:18:49 2013 +0000
@@ -93,38 +93,81 @@
     tt.foreground(Yellow);
     tt.set_font((unsigned char*) Arial28x28);
     if(force) tt.cls();
-    if(force||gids!=lgids){
-        tt.locate(10,10);
-        printf("%4d gids \n",gids);
-        tt.locate(20,40);
-        printf("%4.1f kWh  \n",(float)gids*0.08);
-        tt.set_font((unsigned char*) SCProSB31x55);
-        tt.foreground(Green);
-        tt.locate(60,96);
-        printf("%4.1f mi  \n",(float)(gids-5)*0.31); // Approx for now
-        lgids=gids;
-        tt.foreground(Yellow);
-        tt.set_font((unsigned char*) Arial28x28);
-    }
-    if(force||SOC!=lSOC){
-        tt.locate(200,10);
-        printf("%4.1f%s\n",(float)SOC/10,"% ");
-        lSOC=SOC;
-    }
-    if(force||packV!=lpackV){
-        tt.locate(200,200);
-        printf("%4.1fV \n",(float)packV/2);
-        lpackV=packV;
-    }
-    if(force||accV!=laccV){
-        tt.locate(20,200);
-        printf("%3.1fV  \n",accV);
-        laccV=accV;
-    }
-    if(force||kW!=lkW){
-        tt.locate(180,40);
-        printf("%3.2fkW  \n",kW);
-        lkW=kW;
+    if(skin==ttSkin){
+        if(force||gids!=lgids){
+            tt.locate(10,10);
+            printf("%4d gids \n",gids);
+            tt.locate(20,40);
+            printf("%4.1f kWh  \n",(float)gids*0.08);
+            tt.set_font((unsigned char*) SCProSB31x55);
+            tt.foreground(Green);
+            tt.locate(60,96);
+            printf("%4.1f mi  \n",(float)(gids-5)*0.31); // Approx for now
+            lgids=gids;
+            tt.foreground(Yellow);
+            tt.set_font((unsigned char*) Arial28x28);
+        }
+        if(force||SOC!=lSOC){
+            tt.locate(200,10);
+            printf("%4.1f%s\n",(float)SOC/10,"% ");
+            lSOC=SOC;
+        }
+        if(force||packV!=lpackV){
+            tt.locate(200,200);
+            printf("%4.1fV \n",(float)packV/2);
+            lpackV=packV;
+        }
+        if(force||accV!=laccV){
+            tt.locate(20,200);
+            printf("%3.1fV  \n",accV);
+            laccV=accV;
+        }
+        if(force||kW!=lkW){
+            tt.locate(180,40);
+            printf("%3.2fkW  \n",kW);
+            lkW=kW;
+        }
+    }else {//if(skin==ggSkin){
+        if(force||gids!=lgids){
+            tt.locate(10,10);
+            printf("%4d GIDs \n",gids);
+            
+            tt.locate(40,40); // gg - add GIDs Percent of 281
+            printf("%4.1f%s \n", (float)gids*0.355872, "% ") ;
+            tt.locate(20,70);
+            //printf("%4.1f kWh  \n",(float)gids*0.08); // is input, not usable
+            printf("%4.1f kwh  \n",(float)gids*0.075); // gg - closer to usable
+            
+            tt.set_font((unsigned char*) SCProSB31x55);
+            tt.foreground(Green);
+            //tt.locate(60,96);
+            tt.locate(60,116); // gg - move down a little
+            printf("%4.1f mi  \n",(float)(gids-5)*0.31); // Approx for now
+            lgids=gids;
+            tt.foreground(Yellow);
+            tt.set_font((unsigned char*) Arial28x28);
+        }
+        
+        if(force||SOC!=lSOC){
+            tt.locate(200,10);
+            printf("%4.1f%s\n",(float)SOC/10,"% ");
+            lSOC=SOC;
+        }
+        if(force||packV!=lpackV){
+            tt.locate(200,200);
+            printf("%4.1fV \n",(float)packV/2);
+            lpackV=packV;
+        }
+        if(force||accV!=laccV){
+            tt.locate(20,200);
+            printf("%3.1fV  \n",accV);
+            laccV=accV;
+        }
+        if(force||kW!=lkW){
+            tt.locate(160,40); // gg - move left to keep from wrap
+            printf("%3.2fkw \n",kW); // use small w to save space
+            lkW=kW;
+        }
     }
 }
 
@@ -140,13 +183,28 @@
     static unsigned short ls;
     unsigned char throttle;
     static unsigned char lthrottle;
+    short steerOutBounds = 0 ;
     CANMessage msg;
 
+    //---------------
     msg = lastMsg[indexLastMsg[0x180]]; //Get Throttle position
     throttle = msg.data[5];
+    
+    // ---- steering ----
     msg = lastMsg[indexLastMsg[0x002]]; //Get Steering angle
     steering = (msg.data[1]<<8)+msg.data[0];
-    s= (unsigned short) ((steering/10)+160)%310;
+    
+    if(skin==ttSkin){
+        s= (unsigned short) ((steering/10)+160)%310; // this modulo wraps display
+    }else{// if(skin==ggSkin){    
+        // do not go off screen left or right. gg - steering
+        short ss = (short) ((steering/15)+160); // less gain 10 -> 15
+        if(ss<0) { ss=0; steerOutBounds = 1; }
+        if(ss>310) { ss=310; steerOutBounds = 1; }
+        s = (unsigned short) ss;
+    }
+    
+    //--------------
     msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target and Regen
     regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5);
     targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5);
@@ -172,16 +230,28 @@
         lastPressure[2] = 200;
         lastPressure[3] = 200;
     }
-
+    
+    // display the steering position small square
     if (s!=ls){
-        tt.fillrect(ls,5,ls+9,14, Navy);        
-        tt.fillrect(s,5,s+9,14, White);        
+        // steering position has moved
+        //tt.fillrect(ls,5,ls+9,14, Navy);    // blank old position    
+        
+        //---- gg - steering red
+        // box is blanked by top of Braking bar, so move up 5
+        tt.fillrect(ls,0,ls+9,9, Navy);    // blank old position    
+        if( steerOutBounds != 0 ) // draw out-of-bounds as a red box 
+            tt.fillrect(s,0,s+9,9, Red);     // draw out-of-bounds position 
+        else
+            tt.fillrect(s,0,s+9,9, White);   // draw new in-bounds position 
+            
+        //----
         //tt.foreground(Yellow);
         //tt.set_font((unsigned char*) Arial28x28);
         //tt.locate(10,40);
         //printf("%d %d    \n",s,ls);
         ls=s;
     }
+    
     if (throttle!=lthrottle){
         if (throttle>239) throttle=239;
         if(throttle<lthrottle){
@@ -294,6 +364,132 @@
 }
 
 //----------------
+// gg - cpbars
+void cpBarPlot(bool force, bool showButtons){ 
+    short unsigned max, min, jv, i, bd;
+    unsigned avg;
+    short unsigned nBar[96] ; // bar height over min
+
+    if(force){
+        tt.foreground(White);
+        tt.background(Navy);
+        tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
+        max=0;
+        min=9999;
+        avg=0;
+       
+        // calc each cell-pair voltage, find max and min
+        for(i=0; i<96; i++){
+           bd=(battData[i*2+3]<<8)+battData[i*2+4];
+           nBar[i] = bd; // init to bar height
+           avg+=bd;
+            if(bd>max) max=bd;
+            if(bd<min) min=bd;
+        }
+        avg /= 96;
+        
+        if(min<3713) {
+            jv=avg-(max-avg)*1.5;
+        } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement
+            jv=0;
+        }
+        
+        //------------------
+        tt.cls();
+            
+        // show as vertical bar plot
+        int xWinMin = 26;
+        int xWinMax = 316;
+        int yWinMin = 50;
+        int yWinMax = 150;
+        // draw the Bar Graph Frame, 2 pixels wide
+        tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
+        tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green);
+        
+        // bar heights
+        int height = yWinMax - yWinMin ;
+        int iBarValMax = max - min ; // zero to N
+        
+        //----------------
+        if( iBarValMax == 0 ) {
+            // for testing
+            min = 3501 ; 
+            //max = min + 95*2 ; // for tall values
+            max = min + 95/4 ; // for small values
+            avg = ( max + min ) / 2;
+            iBarValMax = max - min ; // zero to N
+            for(int i=0; i<96; i++) {
+              //nBar[i] = i*2 + min ; // test tall values
+              nBar[i] = i/4 + min ; // test small values
+            }
+        }
+        //---------------
+        float nBarScale = float(height) / iBarValMax ;
+        if( nBarScale < 0.1 ) nBarScale = 0.1 ;
+    
+        // do the Bar-height scaling
+        for(int i=0; i<96; i++){
+          nBar[i] -= min ; // now, 0 to N = iBinValMax
+          nBar[i] *= nBarScale ; // scale, as needed
+        }
+        
+        // values, for now
+        tt.locate( 0, yWinMax+40 );
+        printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",
+                max,min,avg,jv,
+                battData[224+5],battData[224+8],
+                battData[224+11],battData[224+14]);
+        
+        // label the X axis (approximate)
+        tt.locate( 2, yWinMax+5); printf("%04d", min );
+        //tt.locate( 2, yWinMin-14 ); printf("%04d = %04d from %1.4f", max, int( height / nBarScale ) + min, nBarScale );
+        tt.locate( 2, yWinMin-14 ); printf("%04d = (%d) mv range.", max , max - min );
+               
+        //---------------
+        // show the bars
+        int nBarWidth = 2 ;
+        int nBarSpace = 1 ; // 1 for testing
+        
+        int xPos = xWinMin + 2 ; // start one from the left
+         
+        for( int i=0; i<96; i++) {
+            height = nBar[i] ;
+            if( height > 100 ) height = 100 ; // clip tops
+            
+            // draw the bar, is always inside x-window
+            tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green);  
+              
+            // tic mark the y axis each 5
+            if(i%5 == 4){
+               tt.line( xPos,yWinMax+2, xPos,yWinMax+5, White);  // a white tick mark
+               tt.line( xPos+1,yWinMax+2, xPos+1,yWinMax+5, White);  // a white tick mark, to widen
+               //tt.rect( xPos,yWinMax+2, xPos+1,yWinMax+5, White);  // a white 2-wide tick mark is SLOW
+            }
+            // label the y axis each 10
+            if(i%10 == 9){
+               tt.locate( xPos-6, yWinMax+8 );
+               printf("%02d\n", i+1 );
+            }
+            
+            // step to the next bar position
+            xPos += nBarWidth + nBarSpace ; 
+        }
+        
+        showCP=false;
+    }
+    
+    // handle the button
+    if(sMode==1&&showButtons){
+        tt.foreground(Yellow);
+        tt.background(DarkCyan);
+        tt.set_font((unsigned char*) Arial12x12);
+        sprintf(sTemp1," Request");
+        sprintf(sTemp2," CP data");
+        showButton(1,0,sTemp1,sTemp2,3,3);               
+    }
+}
+
+//----------------
 // gg - hist
 void cpHistogram(bool force, bool showButtons){ 
     short unsigned max, min, jv, i, bd;
@@ -330,9 +526,6 @@
         tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
         tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green);
         
-        tt.locate( 0, yWinMax+10 );
-        printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",max,min,avg,jv,battData[224+5],battData[224+8],battData[224+11],battData[224+14]);
-        
         // binning
         short nBin[301] ; // bins to count Min values in nBin[0], etc.
         int height ;
@@ -365,6 +558,10 @@
             }
         }
         
+        // the values, for now
+        tt.locate( 0, yWinMax+40 );
+        printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",max,min,avg,jv,battData[224+5],battData[224+8],battData[224+11],battData[224+14]);
+        
         //---------------
         // show the bars
         int nBarWidth = 3 ;
@@ -399,6 +596,7 @@
     }
 }
 
+//---------------
 void config1(bool force, bool showButtons){
     if (force) {
         tt.background(Black);
@@ -416,6 +614,8 @@
     sprintf(sTemp1,"  Save");
     sprintf(sTemp2,"  Config");
     showButton(2,0,sTemp1,sTemp2,3,3);
+    
+    //------- second row -----
     if (logEn) {
         sprintf(sTemp1," Disable");
     } else {
@@ -423,6 +623,7 @@
     }
     sprintf(sTemp2," Logging");
     showButton(0,1,sTemp1,sTemp2,3,3);
+    
     if (repeatPoll) {
         sprintf(sTemp1," Disable");
     } else {
@@ -430,6 +631,15 @@
     }
     sprintf(sTemp2," Auto CP");
     showButton(1,1,sTemp1,sTemp2,3,3);
+    
+    // add Enable/Disable Batt Log gg - yesBattLog
+    if (yesBattLog) {
+        sprintf(sTemp1," Disable");
+    } else {
+        sprintf(sTemp1," Enable");
+    }
+    sprintf(sTemp2," Batt Log");
+    showButton(2,1,sTemp1,sTemp2,3,3);
 }
 
 void pbScreen(bool force, bool showButtons){
@@ -570,6 +780,9 @@
         case cpHistScreen: // gg - hist
             cpHistogram(changed||showCP,(display==whichTouched));
             break;
+        case cpBarScreen: // gg - cpbars
+            cpBarPlot(changed||showCP,(display==whichTouched));
+            break;
         default:
             if (changed){
                 tt.background(Black);
@@ -628,6 +841,9 @@
                     case cpHistScreen: // gg - hist
                         sprintf(sTemp2," CP Hist");
                         break;
+                    case cpBarScreen: // gg - cpbars
+                        sprintf(sTemp2," CP Bars");
+                        break;
                 }
                 showButton(1,2,sTemp1,sTemp2,3,3);
                 wait_ms(100); //  pause a moment to reduce flicker