Browse Source

More changes

Per Mårtensson 1 year ago
parent
commit
aab528c115

File diff suppressed because it is too large
+ 197 - 132
Electronic_DC_Load.kicad_pcb


+ 1 - 1
Electronic_DC_Load.kicad_prl

@@ -1,6 +1,6 @@
 {
   "board": {
-    "active_layer": 31,
+    "active_layer": 0,
     "active_layer_preset": "",
     "auto_track_width": true,
     "hidden_netclasses": [],

+ 42 - 9
Electronic_DC_Load.kicad_pro

@@ -3,6 +3,9 @@
     "3dviewports": [],
     "design_settings": {
       "defaults": {
+        "apply_defaults_to_fp_fields": false,
+        "apply_defaults_to_fp_shapes": false,
+        "apply_defaults_to_fp_text": false,
         "board_outline_line_width": 0.15,
         "copper_line_width": 0.19999999999999998,
         "copper_text_italic": false,
@@ -34,9 +37,9 @@
         "other_text_thickness": 0.15,
         "other_text_upright": false,
         "pads": {
-          "drill": 1.0,
-          "height": 1.8,
-          "width": 1.8
+          "drill": 0.6,
+          "height": 1.2,
+          "width": 1.2
         },
         "silk_line_width": 0.15,
         "silk_text_italic": false,
@@ -67,6 +70,7 @@
         "duplicate_footprints": "warning",
         "extra_footprint": "warning",
         "footprint": "error",
+        "footprint_symbol_mismatch": "warning",
         "footprint_type_mismatch": "ignore",
         "hole_clearance": "error",
         "hole_near_hole": "error",
@@ -75,8 +79,8 @@
         "item_on_disabled_layer": "error",
         "items_not_allowed": "error",
         "length_out_of_range": "error",
-        "lib_footprint_issues": "warning",
-        "lib_footprint_mismatch": "warning",
+        "lib_footprint_issues": "ignore",
+        "lib_footprint_mismatch": "ignore",
         "malformed_courtyard": "error",
         "microvia_drill_out_of_range": "error",
         "missing_courtyard": "ignore",
@@ -88,7 +92,7 @@
         "shorting_items": "error",
         "silk_edge_clearance": "warning",
         "silk_over_copper": "ignore",
-        "silk_overlap": "warning",
+        "silk_overlap": "ignore",
         "skew_out_of_range": "error",
         "solder_mask_bridge": "error",
         "starved_thermal": "error",
@@ -126,9 +130,6 @@
       },
       "teardrop_options": [
         {
-          "td_allow_use_two_tracks": true,
-          "td_curve_segcount": 5,
-          "td_on_pad_in_zone": false,
           "td_onpadsmd": true,
           "td_onroundshapesonly": false,
           "td_ontrackend": false,
@@ -137,34 +138,66 @@
       ],
       "teardrop_parameters": [
         {
+          "td_allow_use_two_tracks": true,
           "td_curve_segcount": 0,
           "td_height_ratio": 1.0,
           "td_length_ratio": 0.5,
           "td_maxheight": 2.0,
           "td_maxlen": 1.0,
+          "td_on_pad_in_zone": false,
           "td_target_name": "td_round_shape",
           "td_width_to_size_filter_ratio": 0.9
         },
         {
+          "td_allow_use_two_tracks": true,
           "td_curve_segcount": 0,
           "td_height_ratio": 1.0,
           "td_length_ratio": 0.5,
           "td_maxheight": 2.0,
           "td_maxlen": 1.0,
+          "td_on_pad_in_zone": false,
           "td_target_name": "td_rect_shape",
           "td_width_to_size_filter_ratio": 0.9
         },
         {
+          "td_allow_use_two_tracks": true,
           "td_curve_segcount": 0,
           "td_height_ratio": 1.0,
           "td_length_ratio": 0.5,
           "td_maxheight": 2.0,
           "td_maxlen": 1.0,
+          "td_on_pad_in_zone": false,
           "td_target_name": "td_track_end",
           "td_width_to_size_filter_ratio": 0.9
         }
       ],
       "track_widths": [],
+      "tuning_pattern_settings": {
+        "diff_pair_defaults": {
+          "corner_radius_percentage": 80,
+          "corner_style": 1,
+          "max_amplitude": 1.0,
+          "min_amplitude": 0.2,
+          "single_sided": false,
+          "spacing": 1.0
+        },
+        "diff_pair_skew_defaults": {
+          "corner_radius_percentage": 80,
+          "corner_style": 1,
+          "max_amplitude": 1.0,
+          "min_amplitude": 0.2,
+          "single_sided": false,
+          "spacing": 0.6
+        },
+        "single_track_defaults": {
+          "corner_radius_percentage": 80,
+          "corner_style": 1,
+          "max_amplitude": 1.0,
+          "min_amplitude": 0.2,
+          "single_sided": false,
+          "spacing": 0.6
+        }
+      },
       "via_dimensions": [],
       "zones_allow_external_fillets": false
     },

+ 28 - 235
Electronic_DC_Load.kicad_sch

@@ -5,7 +5,10 @@
 	(uuid "c0dab339-7200-490f-9e31-c88351ec25c5")
 	(paper "A4")
 	(title_block
-		(date "29 apr 2017")
+		(title "ELECTRONIC DC LOAD (Nextion Version)")
+		(date "2024-03-16")
+		(rev "9.4")
+		(company "Sweproj")
 	)
 	(lib_symbols
 		(symbol "Connector:Conn_01x04_Pin"
@@ -10151,16 +10154,6 @@
 		)
 		(uuid "0962cb1b-7b7f-4aec-a3b6-708209a0ee8c")
 	)
-	(wire
-		(pts
-			(xy 21.59 44.45) (xy 25.4 44.45)
-		)
-		(stroke
-			(width 0)
-			(type default)
-		)
-		(uuid "096f1527-4c4f-4c33-97ad-a99a53d4c4c0")
-	)
 	(wire
 		(pts
 			(xy 46.99 17.78) (xy 58.42 17.78)
@@ -12981,16 +12974,6 @@
 		)
 		(uuid "9490d8b1-6361-4951-926a-2ab522ab89ae")
 	)
-	(wire
-		(pts
-			(xy 99.06 68.58) (xy 95.25 68.58)
-		)
-		(stroke
-			(width 0)
-			(type default)
-		)
-		(uuid "94d573ad-7396-491a-942b-090db458291c")
-	)
 	(wire
 		(pts
 			(xy 104.14 100.33) (xy 109.22 100.33)
@@ -14031,16 +14014,6 @@
 		)
 		(uuid "c48aa24b-c740-4de3-9e3c-cfc8eb8e4e80")
 	)
-	(wire
-		(pts
-			(xy 99.06 76.2) (xy 99.06 68.58)
-		)
-		(stroke
-			(width 0)
-			(type default)
-		)
-		(uuid "c4eb8749-7a61-463f-b383-d63de5739a9d")
-	)
 	(polyline
 		(pts
 			(xy 256.54 165.1) (xy 256.54 132.08)
@@ -14481,16 +14454,6 @@
 		)
 		(uuid "da5cd3c5-c431-4b91-b819-5e4904dce0d8")
 	)
-	(wire
-		(pts
-			(xy 99.06 76.2) (xy 96.52 76.2)
-		)
-		(stroke
-			(width 0)
-			(type default)
-		)
-		(uuid "daab9d5b-16c6-49aa-b602-a1ae59e2821c")
-	)
 	(wire
 		(pts
 			(xy 276.86 53.34) (xy 274.32 53.34)
@@ -14851,16 +14814,6 @@
 		)
 		(uuid "ed9c67a8-e2a0-42a3-ac42-0e0dec1910f8")
 	)
-	(wire
-		(pts
-			(xy 21.59 43.18) (xy 21.59 44.45)
-		)
-		(stroke
-			(width 0)
-			(type default)
-		)
-		(uuid "ede5d4d3-43d6-4971-965c-953f32caa300")
-	)
 	(wire
 		(pts
 			(xy 106.68 68.58) (xy 106.68 72.39)
@@ -15301,19 +15254,6 @@
 		)
 		(uuid "ff85e086-fbe7-4536-aa61-1858400c2f87")
 	)
-	(text "ELECTRONIC DC LOAD (Keypad Version)"
-		(exclude_from_sim no)
-		(at 187.96 190.5 0)
-		(effects
-			(font
-				(size 1.524 1.524)
-				(thickness 0.3048)
-				(bold yes)
-			)
-			(justify left bottom)
-		)
-		(uuid "0959d4b5-6d16-430a-9885-a7036c8cf9e8")
-	)
 	(text "_"
 		(exclude_from_sim no)
 		(at 280.5938 40.8432 0)
@@ -15327,19 +15267,6 @@
 		)
 		(uuid "111c6515-18a9-4656-a9a4-b6ce9fb69a7c")
 	)
-	(text "XXXXXXXXXXXXXX"
-		(exclude_from_sim no)
-		(at 200.66 194.31 0)
-		(effects
-			(font
-				(size 1.524 1.524)
-				(thickness 0.3048)
-				(bold yes)
-			)
-			(justify left bottom)
-		)
-		(uuid "154a327e-1bdb-446f-8b27-a6e365df2fa7")
-	)
 	(text "Pulse Width"
 		(exclude_from_sim no)
 		(at 134.62 45.72 0)
@@ -15520,19 +15447,6 @@
 		)
 		(uuid "668dabf8-3a63-41ef-ae9b-f7bc389d717b")
 	)
-	(text "9.2 updated"
-		(exclude_from_sim no)
-		(at 269.24 194.31 0)
-		(effects
-			(font
-				(size 1.524 1.524)
-				(thickness 0.3048)
-				(bold yes)
-			)
-			(justify left bottom)
-		)
-		(uuid "6fa85f90-c029-48be-8cfb-c32942ef3ce6")
-	)
 	(text "Tant."
 		(exclude_from_sim no)
 		(at 190.5 24.13 0)
@@ -15585,19 +15499,6 @@
 		)
 		(uuid "8068d67a-1c1f-4edd-973f-52c7bfff9c20")
 	)
-	(text "26th April 2018"
-		(exclude_from_sim no)
-		(at 228.6 194.31 0)
-		(effects
-			(font
-				(size 1.524 1.524)
-				(thickness 0.3048)
-				(bold yes)
-			)
-			(justify left bottom)
-		)
-		(uuid "8261d7fd-bf04-40da-994a-721cf0369da0")
-	)
 	(text "If LTC1046 used then C3 is removed\nand C4 & C26 are 10uF tantalum"
 		(exclude_from_sim no)
 		(at 186.69 55.88 0)
@@ -15650,7 +15551,7 @@
 		)
 		(uuid "8bcc0bfe-51ed-4b56-8f18-dba9c8755227")
 	)
-	(text "VERSION 9.3 updated 26-04-2018"
+	(text "VERSION 9.4 updated 2024-03-16"
 		(exclude_from_sim no)
 		(at 228.6 185.42 0)
 		(effects
@@ -15947,6 +15848,28 @@
 		)
 		(uuid "ffe2278d-0b61-47c6-9354-5cf968a89f27")
 	)
+	(label "A0"
+		(at 96.52 76.2 0)
+		(fields_autoplaced yes)
+		(effects
+			(font
+				(size 1.524 1.524)
+			)
+			(justify left bottom)
+		)
+		(uuid "086b684e-99ad-47fa-a432-89bd45aa371a")
+	)
+	(label "A0"
+		(at 25.4 44.45 180)
+		(fields_autoplaced yes)
+		(effects
+			(font
+				(size 1.524 1.524)
+			)
+			(justify right bottom)
+		)
+		(uuid "42a68be4-c28d-44c1-9b3c-503a4d872aa5")
+	)
 	(global_label "LoadOff"
 		(shape input)
 		(at 243.84 162.56 0)
@@ -26488,7 +26411,7 @@
 				)
 			)
 		)
-		(property "Value" "Arduino_Nano"
+		(property "Value" "Arduino_Nano_Every"
 			(at 88.9 118.11 0)
 			(effects
 				(font
@@ -26825,71 +26748,6 @@
 			)
 		)
 	)
-	(symbol
-		(lib_id "Electronic_DC_Load-rescue:TEST_1P")
-		(at 95.25 68.58 0)
-		(unit 1)
-		(exclude_from_sim no)
-		(in_bom yes)
-		(on_board yes)
-		(dnp no)
-		(uuid "00000000-0000-0000-0000-0000595a7b04")
-		(property "Reference" "J14"
-			(at 92.71 66.04 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-			)
-		)
-		(property "Value" "A0"
-			(at 97.79 64.77 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-					(bold yes)
-				)
-			)
-		)
-		(property "Footprint" "Connectors:PINTST"
-			(at 100.33 68.58 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-				(hide yes)
-			)
-		)
-		(property "Datasheet" ""
-			(at 100.33 68.58 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-				(hide yes)
-			)
-		)
-		(property "Description" ""
-			(at 95.25 68.58 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-				(hide yes)
-			)
-		)
-		(pin "1"
-			(uuid "b96432ed-77cb-482c-b32f-66070d8a9108")
-		)
-		(instances
-			(project "Electronic_DC_Load"
-				(path "/c0dab339-7200-490f-9e31-c88351ec25c5"
-					(reference "J14")
-					(unit 1)
-				)
-			)
-		)
-	)
 	(symbol
 		(lib_id "Electronic_DC_Load-rescue:C")
 		(at 176.53 99.06 0)
@@ -29404,71 +29262,6 @@
 			)
 		)
 	)
-	(symbol
-		(lib_id "Electronic_DC_Load-rescue:TEST_1P")
-		(at 21.59 43.18 0)
-		(unit 1)
-		(exclude_from_sim no)
-		(in_bom yes)
-		(on_board yes)
-		(dnp no)
-		(uuid "00000000-0000-0000-0000-00005ae215a2")
-		(property "Reference" "J16"
-			(at 21.59 36.322 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-			)
-		)
-		(property "Value" "to A0"
-			(at 21.59 38.1 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-					(bold yes)
-				)
-			)
-		)
-		(property "Footprint" "Connectors:PINTST"
-			(at 26.67 43.18 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-				(hide yes)
-			)
-		)
-		(property "Datasheet" ""
-			(at 26.67 43.18 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-				(hide yes)
-			)
-		)
-		(property "Description" ""
-			(at 21.59 43.18 0)
-			(effects
-				(font
-					(size 1.27 1.27)
-				)
-				(hide yes)
-			)
-		)
-		(pin "1"
-			(uuid "d3cd5586-9bf2-4aa1-a3a6-76b652160650")
-		)
-		(instances
-			(project "Electronic_DC_Load"
-				(path "/c0dab339-7200-490f-9e31-c88351ec25c5"
-					(reference "J16")
-					(unit 1)
-				)
-			)
-		)
-	)
 	(symbol
 		(lib_id "Mechanical:MountingHole")
 		(at 324.739 36.83 0)

+ 1 - 0
sw/DC_LOAD/include/screen.h

@@ -8,5 +8,6 @@ void print_chars2(int x1,int len);
 void screen_clear(char empty);
 void writeStr(char *  command, char * txt);
 void writeNum2(char * command, uint16_t value);
+void print_temp(void);
 void color_load (bool load);
 #endif //DCLOAD_SCREEN_H

+ 121 - 156
sw/DC_LOAD/src/main.cpp

@@ -155,15 +155,16 @@ float transientList [10][2];        //array to store Transient List data
 int total_instructions;             //used in Transient List Mode
 int current_instruction;            //used in Transient List Mode
 
+char line0[line_len]= {0};
 char line1[line_len]= {0};
 char line2[line_len]= {0};
 char line3[line_len]= {0};
-char line4[line_len]= {0};
-char line1_buf[line_len]= {0};
-char line2_buf[line_len]= {0};
-char line3_buf[line_len]= {0};
-char line4_buf[line_len]= {0};
-
+char line0_old[line_len]= {0};
+char line1_old[line_len]= {0};
+char line2_old[line_len]= {0};
+char line3_old[line_len]= {0};
+char temperature_val[5]={0x00};
+char temperature_buf[5]={0x00};
 bool old_load=true;
 void setmode(void);
 void color_load (bool load);
@@ -372,16 +373,16 @@ nDevices = 0;
  
   screen_clear('\0');
   writeNum2("t0.xcen", 1);                                 //print SCULLCOM to display with 5 leading spaces (you can change to your own)
-  memcpy(line1,(char*)"SCULLCOM",9);
+  memcpy(line0,(char*)"SCULLCOM",9);
   print_chars2(0,9);
   
-  memcpy(line2,(char*)"Hobby Electronics",18); 
+  memcpy(line1,(char*)"Hobby Electronics",18); 
   print_chars2(1,18);
 
-  memcpy(line3,(char*)"DC Electronic Load",19);
+  memcpy(line2,(char*)"DC Electronic Load",19);
   print_chars2(2,19);
 
-  memcpy(line4,(char*)"Ver. 35 (5x4 Keypad)",21);
+  memcpy(line3,(char*)"Ver. 35 (5x4 Keypad)",21);
   print_chars2(3,21);
 
   delay(2000);                                             //3000 mSec delay for intro display
@@ -393,10 +394,7 @@ nDevices = 0;
   last_time = 0;                                           //set the last_time to 0 at the start (Transicent Mode)
   transient_mode_status = false;                           //set the initial transient mode status (false = low, true = high);
   setCurrent = LowCurrent;                                 //first set the current to the low current value (Transicent Mode)
- 
 
-  line1[18]=0xB0;
-  line1[19]='C';
   color_load(0); 
   Current();                                               //sets initial mode to be CC (Constant Current) at Power Up
   //EEPROM.write(0x00, 0xff);
@@ -435,6 +433,10 @@ void loop() {
       lastCount = encoderPosition;                           //store rotary encoder current position
       CursorPosition();                                      //check and change the cursor position if cursor button pressed
     }else{
+      maxConstantCurrentSetting();                           //set maxiumum Current allowed in Constant Current Mode (CC)
+      powerLevelCutOff();                                    //Check if Power Limit has been exceeded
+    
+      temperatureCutOff();                                   //check if Maximum Temperature is exceeded
       transientLoadToggle();                                  //Start Transient Mode
     }
       
@@ -488,8 +490,6 @@ void readKeypadInput (void) {
                
   if(customKey == 'A'){                                   //check if Constant Current button pressed
     toggle = false;                                         //switch Load OFF
-    line1[18]=0xB0;
-    line1[19]='C';
     color_load(0);
     print_chars2(0,20);
     Current();                                              //if selected go to Constant Current Selected routine
@@ -502,8 +502,6 @@ void readKeypadInput (void) {
          
   if(customKey == 'B'){                                   //check if Constant Power button pressed
     toggle = false;                                         //switch Load OFF
-    line1[18]=0xB0;
-    line1[19]='C';
     color_load(0);
     print_chars2(0,20);
     Power();                                                //if selected go to Constant Power Selected routine
@@ -516,8 +514,6 @@ void readKeypadInput (void) {
           
   if(customKey == '#'){                                   //check if Constant Resistance button pressed  
     toggle = false;                                         //switch Load OFF
-    line1[18]=0xB0;
-    line1[19]='C';
     color_load(0);
     print_chars2(0,20);
     Resistance();                                           //if selected go to Constant Resistance Selected routine
@@ -536,8 +532,6 @@ void readKeypadInput (void) {
     z = 1;                                                  //sets column position for LCD displayed character
     decimalPoint = (' ');                                   //clear decimal point test character reset
     if (exitMode == 1){                                   //if NO battery type selected revert to CC Mode
-      line1[18]=0xB0;
-      line1[19]='C';
       color_load(0);
       print_chars2(0,20);
       Current();                                            //if selected go to Constant Current Selected routine
@@ -546,10 +540,8 @@ void readKeypadInput (void) {
     }
     else
     {
-      memcpy(line3+16,(char*)BatteryType.c_str(),4);
+      memcpy(line2+16,(char*)BatteryType.c_str(),4);
       print_chars2(2,20);
-      line1[18]=0xB0;
-      line1[19]='C';
       color_load(0);
       print_chars2(0,20);
       timer.reset();                                        //reset timer
@@ -559,12 +551,12 @@ void readKeypadInput (void) {
     }
   }
 
-  if (Mode != MODE_BC){
+  if (Mode != MODE_TC && Mode != MODE_TL && Mode != MODE_TP && Mode != MODE_TT){
 
     if(customKey >= '0' && customKey <= '9'){               //check for keypad number input
         numbers[index++] = customKey;
         numbers[index] = '\0';
-        line4[z]=customKey;
+        line3[z]=customKey;
         print_chars2(3,20);
         z = z+1;
         customKey ='\0';
@@ -574,7 +566,7 @@ void readKeypadInput (void) {
         if (decimalPoint != ('>')){                         //test if decimal point entered twice - if so skip 
           numbers[index++] = '.';
           numbers[index] = '\0';
-          line4[z]='.';
+          line3[z]='.';
           print_chars2(3,20);
           z = z+1;
           decimalPoint = ('>');                             //used to indicate decimal point has been input
@@ -638,8 +630,6 @@ void powerLevelCutOff (void) {
     encoderPosition = 0; 
 
     print_chars(3,0,(char*)"Exceeded Power      ",20);
-    line1[18]=0xB0;
-    line1[19]='C';
     color_load(0);
     print_chars2(0,20);
     toggle = false;                                         //switch Load Off
@@ -751,8 +741,8 @@ void ActualReading(void) {
     } else {
         dtostrf(ActualCurrent, 4, 2, buff);
     }
-    memcpy(line2,buff ,5);
-    memcpy(line2+5,(char *)"A " ,2);
+    memcpy(line1,buff ,5);
+    memcpy(line1+5,(char *)"A " ,2);
     
     if (ActualVoltage < 10.0) {
         //lcd.print(ActualVoltage, 3);
@@ -760,15 +750,15 @@ void ActualReading(void) {
     } else {
         dtostrf(ActualVoltage, 4, 2, buff);
     }    
-    memcpy(line2+7,buff ,6);
-    memcpy(line2+12,(char *)"V " ,2);
+    memcpy(line1+7,buff ,6);
+    memcpy(line1+12,(char *)"V " ,2);
      
     if (ActualPower < 100 ) {
          dtostrf(ActualPower, 4, 2, buff);
     } else {
          dtostrf(ActualPower, 4, 1, buff);
     }
-    memcpy(line2+14,buff ,6);
+    memcpy(line1+14,buff ,6);
     print_chars(1,18,(char *)"W " ,2);
 }
 
@@ -807,16 +797,11 @@ if (Mode == MODE_TC || Mode == MODE_TP || Mode == MODE_TT || Mode == MODE_TL){
 //-------------------------------------Battery Capacity Discharge Routine----------------------------------------------------
 void batteryCapacityloop (void) {
   if (Mode == MODE_BC){
-        Serial.println("TEST");  
     setCurrent = reading*1000;                             //set current is equal to input value in Amps
     setReading = setCurrent;                               //show the set current reading being used
     setControlCurrent = setCurrent * setCurrentCalibrationFactor;
     controlVoltage = setControlCurrent;
-
-    //lcd.setCursor(0,3);
-    //lcd.print (timer.getTime()); 
-  
-    print_chars(3,0,(char*)timer.getTime().c_str(),8);
+    memcpy(line3,(char*)timer.getTime().c_str(),8);
     Seconds = timer.getTotalSeconds();                     //get totals seconds
   
     LoadCurrent = ActualCurrent;                           //if timer still running use present Actual Current reading
@@ -825,51 +810,50 @@ void batteryCapacityloop (void) {
       }
  
     BatteryLife = (LoadCurrent*1000)*(Seconds/3600);       //calculate battery capacity in mAh
-    //lcd.setCursor(9,3);
     BatteryLife = round(BatteryLife);
 
     if(BatteryLife >= BatteryLifePrevious){                //only update LCD (mAh) if BatteryLife has increased
   
       if (BatteryLife < 10) {                              //add a 3 leading zero to display if reading less than 10
-      //lcd.print("000");
-       print_chars(3,9,(char*)String(BatteryLife).c_str(),3);
-      }
 
-      if (BatteryLife >= 10 && BatteryLife <100){          //add a 2 leading zero to display
-       print_chars(3,9,(char*)String(BatteryLife).c_str(),2); 
+        memcpy(line3+9,"000",3);
+        memcpy(line3+12,(char*)String(BatteryLife).c_str(),1);
       }
-
-      if (BatteryLife >= 100 && BatteryLife <1000){        //add a 1 leading zero to display
-      print_chars(3,9,(char*)"0",1); 
+      else if (BatteryLife >= 10 && BatteryLife <100){          //add a 2 leading zero to display
+        memcpy(line3+9,"00",2);
+        memcpy(line3+11,(char*)String(BatteryLife).c_str(),2);
       }
-  
-    //lcd.print(BatteryLife,0);
-    print_chars(3,13,"mAh",3);
+      else if (BatteryLife >= 100 && BatteryLife <1000){        //add a 1 leading zero to display
+        memcpy(line3+9,"0",1);
+        memcpy(line3+10,(char*)String(BatteryLife).c_str(),3);      
+      }
+      else {
+        memcpy(line3+9,(char*)String(BatteryLife).c_str(),4);   
+      }
+
+    memcpy(line3+13,"mAh",3);
+    print_chars2(3,20);
     BatteryLifePrevious = BatteryLife;                      //update displayed battery capacity on LCD
     } 
   }
 
 
   if (Mode == MODE_BC && ActualVoltage <= BatteryCutoffVolts){ //stops clock if battery reached cutoff level and switch load off
-
-  BatteryCurrent = ActualCurrent;
-  setVoltage(0,false);                                  //reset DAC to zero for no output current set at switch on                                             
-  toggle = false;                                           //Load is toggled OFF
-  line1[18]=0xB0;
-  line1[19]='C';
-  color_load(0);
-  print_chars2(0,20);
-  timer.stop();
+    BatteryCurrent = ActualCurrent;
+    setVoltage(0,false);                                  //reset DAC to zero for no output current set at switch on                                             
+    toggle = false;                                           //Load is toggled OFF
+    color_load(0);
+    timer.stop();
   }
 
-      if (Mode == MODE_BC && Load == 1){                       //Routine used for data logging in Battery Capacity Mode
-          if (Seconds != SecondsLog){                       //only send serial data if time has changed
-            SecondsLog = Seconds;
-            Serial.print (SecondsLog);                    //sends serial data of time in seconds
-            Serial.print (",");                             //sends a comma as delimiter for logged data
-            Serial.println (ActualVoltage);                   //sends serial data of Voltage reading         
-              }
-          }
+  if (Mode == MODE_BC && Load == 1){                       //Routine used for data logging in Battery Capacity Mode
+    if (Seconds != SecondsLog){                       //only send serial data if time has changed
+      SecondsLog = Seconds;
+      Serial.print (SecondsLog);                    //sends serial data of time in seconds
+      Serial.print (",");                             //sends a comma as delimiter for logged data
+      Serial.println (ActualVoltage);                   //sends serial data of Voltage reading         
+    }
+  }
 
 }
 
@@ -884,10 +868,11 @@ void fanControl (void) {
     digitalWrite(fan, LOW);                               //otherwise turn fan turned off
   }
   
-  memcpy(line1+16,(char*)String(temp).c_str(),2);
-  line1[18]=0xB0;
-  line1[19]='C';
-  print_chars2(0,21);
+  memcpy(temperature_val,(char*)String(temp).c_str(),2);
+  temperature_val[2]=0xB0;
+  temperature_val[3]='C';
+  temperature_val[4]=0x00;
+  print_temp();
 
 }
 
@@ -899,10 +884,7 @@ void LoadSwitch(void) {
  
     if(toggle)
     {
-      line1[18]=0xB0;
-      line1[19]='C';
       color_load(0);
-      print_chars2(0,20);
 
       color_load(0);
       current_instruction = 0;                            //reset current instruction for Transient List Mode to zero
@@ -914,9 +896,6 @@ void LoadSwitch(void) {
     }
     else
     {
-      line1[18]=0xB0;
-      line1[19]='C';
-      print_chars2(0,20);
       print_chars(3,0,(char*)"                    ",20);
       color_load(1);
       toggle = !toggle;
@@ -927,11 +906,11 @@ void LoadSwitch(void) {
 //-----------------------Select Constant Current LCD set up--------------------------------
 void Current(void) {
   Mode = MODE_CC;
-  memcpy(line1,(char*)"DC LOAD ",8);
+  memcpy(line0,(char*)"DC LOAD ",8);
   print_chars2(0,20);
   writeNum2("t0.xcen",(uint16_t) 0);
   print_chars(2,0,(char*)"Set I =            A",20);
-  memset(line4,' ',20);
+  memset(line3,' ',20);
   print_chars2(3,20);
   CP = 9;                                            //sets cursor starting position to units.
   setmode() ; 
@@ -941,10 +920,10 @@ void Current(void) {
 void Power(void) {
   Mode = MODE_CP;
   writeNum2("t0.xcen",(int) 0);
-  memcpy(line1,(char*)"DC LOAD ",7);
+  memcpy(line0,(char*)"DC LOAD ",7);
   print_chars2(0,20);
   print_chars(2,0,(char*)"Set W =            W",22);
-  memset(line4,' ',20);
+  memset(line3,' ',20);
   print_chars2(3,20);
   CP = 10;                                             //sets cursor starting position to units.
   setmode() ;    
@@ -954,10 +933,10 @@ void Power(void) {
 void Resistance(void) {
   Mode = MODE_CR;
   writeNum2("t0.xcen",(int) 0);
-  memcpy(line1,(char*)"DC LOAD ",8);
+  memcpy(line0,(char*)"DC LOAD ",8);
   print_chars2(0,20);
   print_chars(2,0,(char*)"Set R =            R",20);
-  memset(line4,' ',20);
+  memset(line3,' ',20);
   print_chars2(3,20);
   CP = 10;                                             //sets cursor starting position to units.
   setmode() ;
@@ -971,7 +950,7 @@ void BatteryCapacity(void) {
   writeNum2("t0.xcen",0);
   print_chars(0,0,(char*)"BATTERY             ",20);
   print_chars(2,0,(char*)"Set I =            A",20);
-  memset(line4,' ',20);
+  memset(line3,' ',20);
   print_chars2(3,20);
   CP = 9;                                             //sets cursor starting position to units.
   setmode() ;  
@@ -1054,17 +1033,17 @@ void batteryTypeSelected (void) {
   char buff[6];
   if (exitMode != 1){                                      //if battery selection was EXIT then skip this routine
     screen_clear(' ');
-    memcpy(line1+2,"Battery Selected",16);
-    memcpy(line2+8,(char *)BatteryType.c_str(),4);
-    memcpy(line3+2,"Discharge Cutoff",16);
+    memcpy(line0+2,"Battery Selected",16);
+    memcpy(line1+8,(char *)BatteryType.c_str(),4);
+    memcpy(line2+2,"Discharge Cutoff",16);
     dtostrf(BatteryCutoffVolts, 4, 2, buff);
-    memcpy(line4+6,buff,4);
-    memcpy(line4+11," volts",6);
+    memcpy(line3+6,buff,4);
+    memcpy(line3+11," volts",6);
     print_chars2(0,21);
     print_chars2(1,21);
     print_chars2(2,21);
     print_chars2(3,21);                                
-    delay(3000);
+    delay(2000);
   }
 }
 
@@ -1146,8 +1125,8 @@ void transientMode (void) {
     z = 11;
     screen_clear(' ');
     print_chars(0,4,(char*)"Transient Mode",15); 
-    memcpy(line2,(char *)"Set Low  I=",11);
-    memcpy(line2+19,(char *)"A " ,2);
+    memcpy(line1,(char *)"Set Low  I=",11);
+    memcpy(line1+19,(char *)"A " ,2);
     print_chars2(1,0); 
     inputValue(1);
     
@@ -1164,8 +1143,8 @@ void transientMode (void) {
     customKey = 0x00;
 
     z = 11;
-    memcpy(line3,(char *)"Set High I=",11);
-    memcpy(line3+19,(char *)"A " ,2);
+    memcpy(line2,(char *)"Set High I=",11);
+    memcpy(line2+19,(char *)"A " ,2);
     print_chars2(2,0); 
     inputValue(2);
     if(x >= CurrentCutOff){
@@ -1181,8 +1160,8 @@ void transientMode (void) {
 
     if(Mode == MODE_TC || Mode == MODE_TP){
       z = 11;
-      memcpy(line4,(char *)"Set Time  =",11);
-      memcpy(line4+16,(char *)"mSec " ,5);
+      memcpy(line3,(char *)"Set Time  =",11);
+      memcpy(line3+16,(char *)"mSec " ,5);
       print_chars2(3,0); 
       inputValue(3);
       transientPeriod = x;
@@ -1192,27 +1171,20 @@ void transientMode (void) {
 
     }else{
 
-      memset(line4,' ',20);
+      memset(line3,' ',20);
       print_chars2(3,0);
     }
 
     screen_clear(' ');
 
     toggle = false;                                           //switch Load OFF
-    memset(line1,' ',18);
-    line1[18]=0xB0;
-    line1[19]='C';
+    memset(line0,' ',18);
     color_load(0);
-    print_chars2(0,20);
   }else{  
     transientListSetup();
     screen_clear(' ');
     toggle = false;                                           //switch Load OFF
-
-    line1[18]=0xB0;
-    line1[19]='C';
     color_load(0);
-    print_chars2(0,20);
   }
 }
 
@@ -1222,15 +1194,15 @@ void transientType (void) {
   exitMode = 0;                                           //reset EXIT mode
   screen_clear(' ');
   writeNum2("t0.xcen",(int) 0);                                 //print SCULLCOM to display with 5 leading spaces (you can change to your own)
-  memcpy(line1,(char*)"Transient Mode",15);
+  memcpy(line0,(char*)"Transient Mode",15);
   print_chars2(0,0);
-  memcpy(line2,(char*)"1 = Continuous",15);
+  memcpy(line1,(char*)"1 = Continuous",15);
   print_chars2(1,0);
-  memcpy(line3,(char*)"2 = Toggle",10);
-  memcpy(line3+11,(char*)"3 = Pulse",9);
+  memcpy(line2,(char*)"2 = Toggle",10);
+  memcpy(line2+11,(char*)"3 = Pulse",9);
   print_chars2(2,0);
-  memcpy(line4,(char*)"4 = List",8);
-  memcpy(line4+11,(char*)"5 = Exit",9);
+  memcpy(line3,(char*)"4 = List",8);
+  memcpy(line3+11,(char*)"5 = Exit",9);
   print_chars2(3,0);
 
   wait_for_key(1);                 //stop everything till the user press a key.
@@ -1261,11 +1233,7 @@ void transientType (void) {
 screen_clear(' ');
 customKey=0x00;
 if (exitMode == 1){                                       //if NO Transient Mode type selected revert to CC Mode
-    line1[18]=0xB0;
-    line1[19]='C';
-
     color_load(0);
-    print_chars2(0,20);
     Current();                                            //if selected go to Constant Current Selected routine
     encoderPosition = 0;                                  //reset encoder reading to zero
     customKey = 'A';
@@ -1278,28 +1246,31 @@ if (exitMode == 1){                                       //if NO Transient Mode
 void transient (void) {
   char buff[6]={0x00};
   if(Mode ==  MODE_TC || Mode ==  MODE_TP || Mode ==  MODE_TT || Mode ==  MODE_TL){
-    memcpy(line1,(char*)"DC LOAD ",8);
+    memcpy(line0,(char*)"DC LOAD ",8);
     print_chars2(0,20);
     if(Mode != MODE_TL){
-      memcpy(line3,"Lo=     A  Hi=     A",20);
+      memcpy(line2,"Lo=     A  Hi=     A",20);
       dtostrf(LowCurrent, 4, 3, buff);
-      memcpy(line3+3,buff ,5);
+      memcpy(line2+3,buff ,5);
       dtostrf(HighCurrent, 4, 3, buff);
-      memcpy(line3+14,buff ,5);
-      print_chars2(2,20);
+      memcpy(line2+14,buff ,5);
+      
     }else{
-      delay(1);
+      memcpy(line2,"Set I =            A",20);
+      dtostrf(transientList[current_instruction][0], 4, 3, buff);
+      memcpy(line2+8,buff ,5);
     }
 
 
     if(Mode == MODE_TC || Mode == MODE_TP || Mode == MODE_TL){
-      memcpy(line4,"Time =       mSecs   ",20);
+      memcpy(line3,"Time =       mSecs   ",20);
       dtostrf(transientPeriod, 5, 0, buff);
-      memcpy(line4+7,buff,5);
+      memcpy(line3+7,buff,5);
     }else{
-      memcpy(line4,"  ",2);
+      memcpy(line3,"  ",2);
      
     }
+    print_chars2(2,20);
     print_chars2(3,20);
   }
 delay(1);
@@ -1310,11 +1281,11 @@ void transientListSetup(){
 
   screen_clear(' ');
   writeNum2("t0.xcen",(int) 0);                                 //print SCULLCOM to display with 5 leading spaces (you can change to your own)
-  memcpy(line1,(char*)"Setup Transient List",21);
+  memcpy(line0,(char*)"Setup Transient List",21);
   print_chars2(0,0);
-  memcpy(line2,(char*)"Enter Number in List",21);
+  memcpy(line1,(char*)"Enter Number in List",21);
   print_chars2(1,0);
-  memcpy(line3,(char*)"(between 2 to 10 max",21);
+  memcpy(line2,(char*)"(between 2 to 10 max",21);
   print_chars2(2,0);
   y = 0;
   z = 0;
@@ -1325,11 +1296,11 @@ void transientListSetup(){
   char buff[5] = {0x00};
     for(int i=0; i<=(total_instructions); i++){
       screen_clear(' ');
-      memcpy(line1,"Set Current     ",16);
+      memcpy(line0,"Set Current     ",16);
       int length = snprintf( NULL, 0, "%d", i+1 );
       itoa(i+1 ,buff,10);
-      memcpy(line1+12,buff,length);
-      memcpy(line2,"               A",16);
+      memcpy(line0+12,buff,length);
+      memcpy(line1,"               A",16);
       print_chars2(0,0);
       print_chars2(1,0);
 
@@ -1338,12 +1309,12 @@ void transientListSetup(){
       inputValue(1);            //get the users input value
       transientList[i][0] = x; //store the users entered value in the transient list 
       customKey = 0x00;
-      memcpy(line3,"Set Time        ",16);
+      memcpy(line2,"Set Time        ",16);
       length = snprintf( NULL, 0, "%d", i+1 );
       itoa(i+1 ,buff,10);
       
-      memcpy(line3+12,buff,length);
-      memcpy(line4,"               mSec",19);
+      memcpy(line2+12,buff,length);
+      memcpy(line3,"               mSec",19);
       print_chars2(2,0);
       print_chars2(3,0);
       y = 0;
@@ -1458,13 +1429,13 @@ void userSetUp (void) {
   writeNum2("t2.xcen",(int) 0);   
   writeNum2("t3.xcen",(int) 0);   
 
-  memcpy(line1,"User Set-Up         ",21);
+  memcpy(line0,"User Set-Up         ",21);
   print_chars2(0,20);
-  memset(line3,' ',20);
+  memset(line2,' ',20);
   print_chars2(2,20);
-  memset(line4,' ',20);
+  memset(line3,' ',20);
   print_chars2(3,20);
-  memcpy(line2,"Current Limit=     A",21);
+  memcpy(line1,"Current Limit=     A",21);
   print_chars2(1,20);
 
   inputValue(1);
@@ -1473,7 +1444,7 @@ void userSetUp (void) {
   
   customKey = 0x00;
   z = 15;
-  memcpy(line3,"Power Limit =      W",21);
+  memcpy(line2,"Power Limit =      W",21);
   print_chars2(2,20);
   inputValue(2);
   PowerCutOff = x;
@@ -1481,8 +1452,8 @@ void userSetUp (void) {
 
   customKey = 0x00;
   z = 15;
-  line4[18]=0xB0;
-  memcpy(line4,"Temp. Limit =      C",21);
+  line3[18]=0xB0;
+  memcpy(line3,"Temp. Limit =      C",21);
   print_chars2(3,20);
   inputValue(3);
   z = 1;
@@ -1492,10 +1463,7 @@ void userSetUp (void) {
 
     writeNum2("t0.xcen",(int) 0);   
     screen_clear(' ');
-    line1[18]=0xB0;
-    line1[19]='C';
     color_load(0);
-    print_chars2(0,20);
     Current();                                            //if selected go to Constant Current Selected routine
     encoderPosition = 0;                                  //reset encoder reading to zero
     customKey = 'A';
@@ -1506,11 +1474,8 @@ void temperatureCutOff (void){
   if (temp >= tempCutOff){                                 //if Maximum temperature is exceeded
   reading = 0;
   encoderPosition = 0; 
-  memcpy(line4,"Over Temperature    ",20);
+  memcpy(line3,"Over Temperature    ",20);
   print_chars2(3,20);
-  line1[18]=0xB0;
-  line1[19]='C';
-  print_chars2(0,20);
   color_load(0);
   toggle = false;                                         //switch Load Off
   }
@@ -1553,29 +1518,29 @@ void setupLimits (void){
   writeNum2("t1.xcen",(int) 0); 
   writeNum2("t2.xcen",(int) 0); 
   writeNum2("t3.xcen",(int) 0); 
-  memcpy(line1," Maximum Limits Set ",20);
+  memcpy(line0," Maximum Limits Set ",20);
   print_chars2(0,20);
   char snum[5];
-  memcpy(line2,"Current Limit=    A ",20);
+  memcpy(line1,"Current Limit=    A ",20);
   CurrentCutOff = EEPROM.read(0x00);
   int length = snprintf( NULL, 0, "%d", CurrentCutOff  );
 
   itoa(CurrentCutOff, snum, 10);
-  memcpy(line2+15,snum,length);
+  memcpy(line1+15,snum,length);
   print_chars2(1,20);
 
-  memcpy(line3,"Power Limit  =    W ",20);
+  memcpy(line2,"Power Limit  =    W ",20);
   PowerCutOff = EEPROM.read(0x20);
   length = snprintf( NULL, 0, "%d", PowerCutOff );
   itoa(PowerCutOff, snum, 10);
-  memcpy(line3+15,snum,length);
+  memcpy(line2+15,snum,length);
   print_chars2(2,20);
 
-  memcpy(line4,"Temp. Limit  =    C ",20);
+  memcpy(line3,"Temp. Limit  =    C ",20);
   tempCutOff = EEPROM.read(0x40);
   length = snprintf( NULL, 0, "%d", tempCutOff );
   itoa(tempCutOff, snum, 10);
-  memcpy(line4+15,snum,length);
+  memcpy(line3+15,snum,length);
   print_chars2(3,20);
 
 

+ 50 - 41
sw/DC_LOAD/src/screen.cpp

@@ -4,16 +4,17 @@
 extern SoftwareSerial nexSerial;
 extern uint8_t Mode; 
 extern uint8_t old_Mode;
+extern char line0[line_len];
 extern char line1[line_len];
 extern char line2[line_len];
 extern char line3[line_len];
-extern char line4[line_len];
-extern char line1_buf[line_len];
-extern char line2_buf[line_len];
-extern char line3_buf[line_len];
-extern char line4_buf[line_len];
+extern char line0_old[line_len];
+extern char line1_old[line_len];
+extern char line2_old[line_len];
+extern char line3_old[line_len];
 extern bool old_load;
-
+extern char temperature_val[5];
+extern char temperature_buf[5];
 void writeNum2(char * command, uint16_t value){ 
   nexSerial.print(command);  
   if(command !="cmd"){
@@ -35,53 +36,61 @@ void writeStr(char *  command, char * txt){
 }
 
 void screen_clear(char empty){
+  memset(line0, empty, 20);
   memset(line1, empty, 20);
   memset(line2, empty, 20);
   memset(line3, empty, 20);
-  memset(line4, empty, 20);
-  writeStr("t0",(char *)line1);
-  writeStr("t1",(char *)line2);
-  writeStr("t2",(char *)line3);
-  writeStr("t3",(char *)line4);
+  writeStr("t0",(char *)line0);
+  writeStr("t1",(char *)line1);
+  writeStr("t2",(char *)line2);
+  writeStr("t3",(char *)line3);
 }
 
-
+void print_temp(void){
+    uint8_t compare=0;
+    compare=memcmp(temperature_val,temperature_buf,5);
+    if (compare!=0){
+        writeStr("ttemp",temperature_val);
+         memcpy(temperature_buf,temperature_val,5);
+    }
+    
+}
 void print_chars2(int x1,int len){
       uint8_t compare=0;
       switch(x1){
         case 0: 
-          line1[21]=0x00;        
-          compare=memcmp(line1_buf,line1,20);
+          line0[21]=0x00;        
+          compare=memcmp(line0_old,line0,20);
           if (compare!=0){
-            writeStr("t0",line1);
+            writeStr("t0",line0);
           }
-          line1[21]=0x00;
-          memcpy(line1_buf,line1,21);
+          line0[21]=0x00;
+          memcpy(line0_old,line0,21);
           break;
         case 1:
-          line2[21]=0x00;
-          compare=memcmp(line2_buf,line2,20);
+          line1[21]=0x00;
+          compare=memcmp(line1_old,line1,20);
           if (compare!=0){
-            writeStr("t1",line2);
+            writeStr("t1",line1);
           }
-          line2[21]=0x00;
-          memcpy(line2_buf,line2,21);    
+          line1[21]=0x00;
+          memcpy(line1_old,line1,21);    
           break;
         case 2:
-          line3[21]=0x00;
-          compare=memcmp(line3_buf,line3,20);
+          line2[21]=0x00;
+          compare=memcmp(line2_old,line2,20);
           if (compare!=0)
-            writeStr("t2",line3);
-          line3[21]=0x00;
-          memcpy(line3_buf,line3,21);
+            writeStr("t2",line2);
+          line2[21]=0x00;
+          memcpy(line2_old,line2,21);
           break;
         case 3:
-          line4[21]=0x00;
-          compare=memcmp(line4_buf,line4,20);
+          line3[21]=0x00;
+          compare=memcmp(line3_old,line3,20);
           if (compare!=0)
-            writeStr("t3",line4);
-          line4[21]=0x00;
-          memcpy(line4_buf,line4,21); 
+            writeStr("t3",line3);
+          line3[21]=0x00;
+          memcpy(line3_old,line3,21); 
           break;         
       }
       delay(1);
@@ -89,16 +98,16 @@ void print_chars2(int x1,int len){
 void print_chars(int x1,int z, char * text,int len){
       switch(x1){
         case 0:
-          memcpy(line1+z,text,len);         
+          memcpy(line0+z,text,len);         
           break;
         case 1:
-          memcpy(line2+z,text,len);
+          memcpy(line1+z,text,len);
           break;
         case 2:
-          memcpy(line3+z,text,len);
+          memcpy(line2+z,text,len);
           break;
         case 3:         
-          memcpy(line4+z,text,len);
+          memcpy(line3+z,text,len);
           break;          
 
       }
@@ -107,16 +116,16 @@ void print_chars(int x1,int z, char * text,int len){
 void print_char(int x1,int z, char text){
       switch(x1){
         case 0:  
-          line1[z]=text;
+          line0[z]=text;
           break;
         case 1:
-          line2[z]=text;
+          line1[z]=text;
           break;
         case 2:
-          line3[z]=text;
+          line2[z]=text;
           break;
         case 3:
-          line4[z]=text;
+          line3[z]=text;
           break;          
 
       }
@@ -159,7 +168,7 @@ void setmode(){
           writeNum2("bbat.bco",(int) col_blue); 
           writeNum2("btrans.bco",(int) col_gray);
     }
-    Mode=old_Mode;
+    old_Mode=Mode;
   }
 }
 void color_load (bool load){

Some files were not shown because too many files changed in this diff