Components and supplies
ATtiny 1614 Processor
Arduino Nano R3
Project description
Code
LogicProbe code
arduino
1/* 2 This sketch acts as a logic level tester, by Marco Zonca, 10/2020 3 ATTINY 1614 as MPU, a button to switch TTL/CMOS (max 10v), 3 x LEDs and a few resistors, etc.; 4 5 // ---------------------------------------------------------------------------------------------- 6 // TTL levels : undefined=yellow >0.8v <= 2.0v low=blue <= 0.8v high=red > 2.0v 7 // CMOS levels: undefined=yellow >1.5v <= 3.5v low=blue <= 1.5v high=red > 3.5v 8 // ---------------------------------------------------------------------------------------------- 9 10 As a further step I added a small 300mA/h LiPo battery, code and circuitry to provide charging 11 functionality: SMD micro relay, NPN BC337, 1N4148 diod and a few more resistors; for 12 the two couples of 10k resistors as voltage dividers try to select them with similar values as possibile 13 or you have to apply some +- % of arbitrary correction to the voltage calculation (i.e. VProbe=(n1...)) 14 for every one of them; it is another voltage divider, on probe input, 10k and 5k ohm values. 15 16 Charging values: 17 -----------------s 18 CBatt = 0.3 (battery power in A/h) 19 VResis = 15.5 (resistor value in series between PowerSource and Battery, in ohm 20 please measure the exact resistor value and put it here and below there) 21 ICirc = 0.05 (estimated maximum current consumption of the circuit without battery charging) 22 23 VPower = 5.0 (charging PowerSource voltage from USB) not a constant, it will change in reading 24 VMinPower = 4.6 (minimum voltage from USB to charge battery) 25 VBmin = 3.2 (absolute minimum voltage) 26 VBWmin = 3.4 (working minimum voltage) 27 VMax = 4.2 (absolute maximum voltage) 28 VBchgd = 4.0 (battery voltage, or more, to consider it already charged at power-on) 29 ETFact = 1.5 (estimated time of charging factor) 30 OvTiFact = 1.2 (overtime of charging factor, in addition to ETFact) 31 VInitBatt = initial battery voltage, after power-on of just after charged or at start of charging 32 VBatt = actual battery voltage 33 IBatt = (( VPower - VBatt ) / VResis) - ICirc (charging current; 0.066A at 0%, 0.034A at 50%, 0.002A at 100%) 34 IBattAvg = (( VPower - ((VMax+VBmin)/2) ) / VResis) - ICirc = 0.034A (average charging current) 35 SoC = 100 - (( VMax - VBatt ) * 100) (state of charge in %) 36 TFull = ( CBatt / IBattAvg ) * 60 = 529 minutes (time of charging at average current and battery at VBmin) 37 TMaxChg = TFull * ( VMax - VInitBatt ) * ETFact (estimated maximum time of charging considering initial voltage state, in minutes) 38 TChg = ( TFull * (VMax - VBatt)) * ETFact (restimated remaining time of charging in minutes) 39 ChTimeStart = time elapsed as minutes from power-up 40 ChTimeEnd = time end of charging as minute from power-up 41 ChTimeNow = time as minutes from power-up 42*/ 43 44// #include <SoftwareSerial.h> // can be uncommented for isDEBUG=true and Serial Monitor 45 46// ports in/out 47const int ledBluePin = 0; // pa4, on=LOW lovel (logic 0) 48const int ledYellowPin = 6; // pb1, on=UNDEFINED level in between 0 and 1 49const int ledRedPin = 8; // pa1, on=HIGH level (logic 1) 50const int RelayPin = 2; // pa6, set on (close) or off (open) the relay, due the contact is normally open 51const int ProbePin = 10; // pa3, analog input, logic level will be tested here 52const int ButtonPin = 9; // pa2, open/released=TTL closed/pressed=CMOS 53const int VBattPin = 7; // pb0, analog input, battery voltage is tested here 54const int VRawPin = 1; // pa5, analog input, USB power source voltage is tested here 55 56// Charging constant Values, see notes above 57const float CBatt = 0.300; // put the battery power A/h 58const float VResis = 15.5; // put the exact resistor value 59const float ICirc = 0.05; // put the maximum circuit consumption 60const float VMinPower = 4.6; 61const float VBmin = 3.2; 62const float VBWmin = 3.4; 63const float VMax = 4.2; 64const float VBchgd = 4.0; 65const float ETFact = 1.5; 66const float OvTiFact = 1.2; 67float VPower = 5.0; // it will change with read value 68float IBattAvg = ((VPower - ((VMax+VBmin)/2) ) / VResis) - ICirc; 69float TFull = ( CBatt / IBattAvg ) * 60; 70 71const boolean IsDEBUG = false; // set this to 'true' for Serial Monitor 72 73const int CLOSE = HIGH; 74const int OPEN = LOW; 75const float MillisReadVoltages = 2000; 76const float MillisCheckCharge = 4000; 77const float MillisDebug = 10000; 78 79// Charging variable Values, see notes above 80float VInitBatt = 0; 81float VBatt = 0; 82float IBatt = 0; 83float SoC = 0; 84float TMaxChg = 0; 85float TChg = 0; 86float VRaw = 0; 87double ChTimeStart = 0; 88double ChTimeEnd = 0; 89double ChTimeNow = 0; 90bool IsOverTime = false; 91bool IsCharging = false; 92 93float prevMillisReadVoltages = 0; 94float prevMillisCheckCharge = 0; 95float prevMillisDebug = 0; 96bool isCMOS=false; 97float n=0; 98float n1=0; 99float VProbe=0; 100byte Status=0; // 0=0 1=1 2=undefined 101byte prevStatus=9; // 0=0 1=1 2=undefined (previous) [value=9 is just for first loop run] 102 103void setup() { 104 if (IsDEBUG) Serial.begin(9600); 105 pinMode(ledBluePin, OUTPUT); 106 pinMode(ledYellowPin, OUTPUT); 107 pinMode(ledRedPin, OUTPUT); 108 pinMode(RelayPin, OUTPUT); 109 pinMode(ButtonPin, INPUT); 110 pinMode(ProbePin, INPUT); 111 pinMode(VBattPin, INPUT); 112 pinMode(VRawPin, INPUT); 113 digitalWrite(RelayPin,OPEN); // disconnects power from battery 114 digitalWrite(ledBluePin,HIGH); // LEDs test show 115 delay(150); 116 digitalWrite(ledBluePin,LOW); 117 digitalWrite(ledYellowPin,HIGH); 118 delay(150); 119 digitalWrite(ledYellowPin,LOW); 120 digitalWrite(ledRedPin,HIGH); 121 delay(150); 122 digitalWrite(ledRedPin,LOW); 123} // setup() 124 125void loop() { 126 readProbe(); 127 display(); 128 if ((prevMillisReadVoltages+MillisReadVoltages) < millis()) readVoltages(); 129 if ((prevMillisCheckCharge+MillisCheckCharge) < millis()) checkCharge(); 130 if (((prevMillisDebug+MillisDebug) < millis()) && (IsDEBUG)) printDebugging(); 131} // loop() 132 133void display() { 134 digitalWrite(ledBluePin,LOW); 135 digitalWrite(ledYellowPin,LOW); 136 digitalWrite(ledRedPin,LOW); 137 if (VPower > 0) { // ------------------------- with USB power 138 if (IsCharging==true) { 139 if (IsOverTime==false) { 140 if (SoC <= 20) blink_red(); 141 if (SoC > 20 && SoC <=40) blink_red_yellow(); 142 if (SoC > 40 && SoC <=60) blink_yellow(); 143 if (SoC > 60 && SoC <=80) blink_yellow_blue(); 144 if (SoC > 80 && SoC <=90) blink_blue(); 145 if (SoC > 90) blink_slowblue(); 146 } else { 147 blink_quickyellow(); //overtime warning 148 } 149 } else { 150 blink_quickblue(); //battery already charged 151 } 152 } else { 153 switch (Status) { // ----------------------- with battery, normal probing operation 154 case 0: 155 digitalWrite(ledBluePin, HIGH); 156 break; 157 case 1: 158 digitalWrite(ledRedPin, HIGH); 159 break; 160 case 2: 161 digitalWrite(ledYellowPin, HIGH); 162 break; 163 } 164 prevStatus=Status; 165 } 166} // display() 167 168 169void readVoltages() { 170 n=analogRead(VRawPin); 171 if (n > 0) { 172 n1=(((6.60 * n) / 1023.00)); // 6.60 = 3.30 x 2 (voltage divider /2 in input) 173 VRaw=(n1 + ((n1 * 0.0) /100)); // arbitrary correction (not active, +-0.0%) 174 } else { 175 VRaw=0; 176 } 177 VPower=VRaw; 178 n=analogRead(VBattPin); 179 if (n > 0) { 180 n1=(((6.60 * n) / 1023.00)); // 6.60 = 3.30 x 2 (voltage divider /2 in input) 181 VBatt=(n1 + ((n1 * 0.0) /100)); // arbitrary correction (not active, +-0.0%) 182 } else { 183 VBatt=0; 184 } 185 if (VInitBatt==0) VInitBatt=VBatt; // initial battery voltage, at power-on 186 prevMillisReadVoltages=millis(); 187} // readVoltages() 188 189 190void checkCharge() { 191 if ((IsCharging == false) && (VPower >= VMinPower) && (VBatt < VBchgd)) { 192 ChTimeStart=int((millis()/1000)/60); // start charging, elapsed time as minutes from power-up 193 digitalWrite(RelayPin,CLOSE); // connets power to battery 194 VInitBatt=VBatt; // initial charging battery voltage 195 IsOverTime=false; 196 IsCharging=true; 197 } 198 if ((IsCharging == true) && ((VPower < VMinPower) || (VBatt >= VMax))) { 199 ChTimeEnd=int((millis()/1000)/60); // end charging, elapsed time as minutes from power-up 200 digitalWrite(RelayPin,OPEN); // disconnects power from battery 201 VInitBatt=VBatt; // battery voltage, just after charging is finished 202 IsCharging=false; 203 } 204 IBatt = ((VPower - VBatt) / VResis) - ICirc; // charging current; 0.066A at 0%, 0.034A at 50%, 0.002A at 100% 205 IBattAvg = ((VPower - ((VMax+VBmin)/2) ) / VResis) - ICirc; // 0.034A average charging current 206 SoC = 100 - ((VMax - VBatt) * 100); // state of charge in % 207 TFull = (CBatt / IBattAvg) * 60; // 529 minutes, time of charging at average current and battery at VBmin 208 TMaxChg = TFull * (VMax - VInitBatt) * ETFact * OvTiFact; // estimated maximum time of charging considering initial voltage state, in minutes 209 TChg = (TFull * (VMax - VBatt)) * ETFact; // estimated remaining time of charging in minutes 210 ChTimeNow=int((millis()/1000)/60); // now time as minutes from power-up 211 if ((ChTimeNow-ChTimeStart) > TMaxChg) IsOverTime=true; 212 prevMillisCheckCharge=millis(); 213} // checkCharge() 214 215 216void readProbe() { 217 if (digitalRead(ButtonPin) == LOW) { 218 isCMOS=true; 219 } else { 220 isCMOS=false; 221 } 222 n = analogRead(ProbePin); 223 if (n > 0) { 224 n1=(((9.90 * n) / 1023.00)); // 9.90 = 3.30 x 3 (voltage divider /3 in input) 225 VProbe=(n1 + ((n1 * 0.0) /100)); // arbitrary correction (not active, +-0.0%) 226 } else { 227 VProbe=0; 228 } 229 if (isCMOS==false) { // TTL case 230 if (VProbe <= 0.8) { 231 Status=0; 232 } 233 if (VProbe > 0.8 && VProbe <= 2.0) { 234 Status=2; 235 } 236 if (VProbe > 2.0) { 237 Status=1; 238 } 239 } 240 if (isCMOS==true) { // CMOS case 241 if (VProbe <= 1.5) { 242 Status=0; 243 } 244 if (VProbe > 1.5 && VProbe <= 3.5) { 245 Status=2; 246 } 247 if (VProbe > 3.5) { 248 Status=1; 249 } 250 } 251} // readProbe() 252 253void blink_red() { 254 delay(500); 255 digitalWrite(ledRedPin, HIGH); 256} 257void blink_blue() { 258 delay(500); 259 digitalWrite(ledBluePin, HIGH); 260 delay(500); 261} 262void blink_yellow() { 263 delay(500); 264 digitalWrite(ledYellowPin, HIGH); 265 delay(500); 266} 267void blink_red_yellow() { 268 delay(500); 269 digitalWrite(ledRedPin, HIGH); 270 delay(500); 271 digitalWrite(ledRedPin, LOW); 272 digitalWrite(ledYellowPin, HIGH); 273 delay(500); 274} 275void blink_yellow_blue() { 276 delay(500); 277 digitalWrite(ledYellowPin, HIGH); 278 delay(500); 279 digitalWrite(ledYellowPin, LOW); 280 digitalWrite(ledBluePin, HIGH); 281 delay(500); 282} 283void blink_slowblue() { 284 delay(1000); 285 digitalWrite(ledBluePin, HIGH); 286 delay(2000); 287} 288void blink_quickyellow() { 289 delay(100); 290 digitalWrite(ledYellowPin, HIGH); 291 delay(100); 292} 293void blink_quickblue() { 294 delay(100); 295 digitalWrite(ledBluePin, HIGH); 296 delay(100); 297} 298void printDebugging() { 299 Serial.println("----------------------------------------------"); 300 if (IsCharging) { 301 Serial.print("IsCharging="); 302 Serial.println(IsCharging); 303 Serial.print("VRaw (VPower)="); 304 Serial.println(VRaw); 305 Serial.print("VInitBatt="); 306 Serial.println(VInitBatt); 307 Serial.print("VBatt="); 308 Serial.println(VBatt); 309 Serial.print("IBatt="); 310 Serial.println(IBatt); 311 Serial.print("IBattAvg="); 312 Serial.println(IBattAvg); 313 Serial.print("SoC%="); 314 Serial.println(SoC); 315 Serial.print("TFull="); 316 Serial.println(TFull); 317 Serial.print("TMaxChg max minutes, more is OverTime="); 318 Serial.println(TMaxChg); 319 Serial.print("TChg remaining minutes="); 320 Serial.println(TChg); 321 Serial.print("ChTimeStart="); 322 Serial.println(ChTimeStart); 323 Serial.print("TimeNow="); 324 Serial.println(ChTimeNow); 325 Serial.print("IsOverTime="); 326 Serial.println(IsOverTime); 327 Serial.print("VProbe="); 328 Serial.println(VProbe); 329 } else { 330 Serial.print("IsCharging="); 331 Serial.println(IsCharging); 332 Serial.print("VRaw (VPower)="); 333 Serial.println(VRaw); 334 Serial.print("VInitBatt="); 335 Serial.println(VInitBatt); 336 Serial.print("VBatt="); 337 Serial.println(VBatt); 338 Serial.print("SoC%="); 339 Serial.println(SoC); 340 Serial.print("ChTimeStart="); 341 Serial.println(ChTimeStart); 342 Serial.print("ChTimeEnd="); 343 Serial.println(ChTimeEnd); 344 Serial.print("TimeNow="); 345 Serial.println(ChTimeNow); 346 Serial.print("Millis()= "); 347 Serial.println(millis()); 348 Serial.print("VProbe="); 349 Serial.println(VProbe); 350 } 351 prevMillisDebug=millis(); 352} // printDebugging() 353
LogicProbe code
arduino
1/* 2 This sketch acts as a logic level tester, by Marco Zonca, 10/2020 3 4 ATTINY 1614 as MPU, a button to switch TTL/CMOS (max 10v), 3 x LEDs and a few 5 resistors, etc.; 6 7 // ---------------------------------------------------------------------------------------------- 8 9 // TTL levels : undefined=yellow >0.8v <= 2.0v low=blue <= 0.8v high=red > 10 2.0v 11 // CMOS levels: undefined=yellow 12 >1.5v <= 3.5v low=blue <= 1.5v high=red > 3.5v 13 // ---------------------------------------------------------------------------------------------- 14 15 16 As a further step I added a small 300mA/h LiPo battery, code and circuitry 17 to provide charging 18 functionality: SMD micro relay, NPN BC337, 1N4148 diod 19 and a few more resistors; for 20 the two couples of 10k resistors as voltage dividers 21 try to select them with similar values as possibile 22 or you have to apply some 23 +- % of arbitrary correction to the voltage calculation (i.e. VProbe=(n1...)) 24 25 for every one of them; it is another voltage divider, on probe input, 10k and 26 5k ohm values. 27 28 Charging values: 29 -----------------s 30 CBatt = 0.3 31 (battery power in A/h) 32 VResis = 15.5 (resistor value in series between PowerSource 33 and Battery, in ohm 34 please measure the exact resistor value and 35 put it here and below there) 36 ICirc = 0.05 (estimated maximum current consumption 37 of the circuit without battery charging) 38 39 VPower = 5.0 (charging PowerSource 40 voltage from USB) not a constant, it will change in reading 41 VMinPower = 4.6 42 (minimum voltage from USB to charge battery) 43 VBmin = 3.2 (absolute minimum 44 voltage) 45 VBWmin = 3.4 (working minimum voltage) 46 VMax = 4.2 (absolute maximum 47 voltage) 48 VBchgd = 4.0 (battery voltage, or more, to consider it already charged 49 at power-on) 50 ETFact = 1.5 (estimated time of charging factor) 51 OvTiFact 52 = 1.2 (overtime of charging factor, in addition to ETFact) 53 VInitBatt = initial 54 battery voltage, after power-on of just after charged or at start of charging 55 56 VBatt = actual battery voltage 57 IBatt = (( VPower - VBatt ) / VResis) - ICirc 58 (charging current; 0.066A at 0%, 0.034A at 50%, 0.002A at 100%) 59 IBattAvg = 60 (( VPower - ((VMax+VBmin)/2) ) / VResis) - ICirc = 0.034A (average charging current) 61 62 SoC = 100 - (( VMax - VBatt ) * 100) (state of charge in %) 63 TFull = ( CBatt 64 / IBattAvg ) * 60 = 529 minutes (time of charging at average current and battery 65 at VBmin) 66 TMaxChg = TFull * ( VMax - VInitBatt ) * ETFact (estimated maximum 67 time of charging considering initial voltage state, in minutes) 68 TChg = ( TFull 69 * (VMax - VBatt)) * ETFact (restimated remaining time of charging in minutes) 70 71 ChTimeStart = time elapsed as minutes from power-up 72 ChTimeEnd = time end 73 of charging as minute from power-up 74 ChTimeNow = time as minutes from power-up 75*/ 76 77// 78 #include <SoftwareSerial.h> // can be uncommented for isDEBUG=true and Serial Monitor 79 80// 81 ports in/out 82const int ledBluePin = 0; // pa4, on=LOW lovel (logic 0) 83const 84 int ledYellowPin = 6; // pb1, on=UNDEFINED level in between 0 and 1 85const int 86 ledRedPin = 8; // pa1, on=HIGH level (logic 1) 87const int RelayPin = 2; // pa6, 88 set on (close) or off (open) the relay, due the contact is normally open 89const 90 int ProbePin = 10; // pa3, analog input, logic level will be tested here 91const 92 int ButtonPin = 9; // pa2, open/released=TTL closed/pressed=CMOS 93const int 94 VBattPin = 7; // pb0, analog input, battery voltage is tested here 95const int 96 VRawPin = 1; // pa5, analog input, USB power source voltage is tested here 97 98// 99 Charging constant Values, see notes above 100const float CBatt = 0.300; // put 101 the battery power A/h 102const float VResis = 15.5; // put the exact resistor value 103const 104 float ICirc = 0.05; // put the maximum circuit consumption 105const float VMinPower 106 = 4.6; 107const float VBmin = 3.2; 108const float VBWmin = 3.4; 109const float VMax 110 = 4.2; 111const float VBchgd = 4.0; 112const float ETFact = 1.5; 113const float 114 OvTiFact = 1.2; 115float VPower = 5.0; // it will change with read value 116float 117 IBattAvg = ((VPower - ((VMax+VBmin)/2) ) / VResis) - ICirc; 118float TFull = ( CBatt 119 / IBattAvg ) * 60; 120 121const boolean IsDEBUG = false; // set this to 'true' 122 for Serial Monitor 123 124const int CLOSE = HIGH; 125const int OPEN = LOW; 126const 127 float MillisReadVoltages = 2000; 128const float MillisCheckCharge = 4000; 129const 130 float MillisDebug = 10000; 131 132// Charging variable Values, see notes above 133float 134 VInitBatt = 0; 135float VBatt = 0; 136float IBatt = 0; 137float SoC = 0; 138float 139 TMaxChg = 0; 140float TChg = 0; 141float VRaw = 0; 142double ChTimeStart = 0; 143double 144 ChTimeEnd = 0; 145double ChTimeNow = 0; 146bool IsOverTime = false; 147bool IsCharging 148 = false; 149 150float prevMillisReadVoltages = 0; 151float prevMillisCheckCharge 152 = 0; 153float prevMillisDebug = 0; 154bool isCMOS=false; 155float n=0; 156float 157 n1=0; 158float VProbe=0; 159byte Status=0; // 0=0 1=1 2=undefined 160byte prevStatus=9; 161 // 0=0 1=1 2=undefined (previous) [value=9 is just for first loop run] 162 163void 164 setup() { 165 if (IsDEBUG) Serial.begin(9600); 166 pinMode(ledBluePin, OUTPUT); 167 168 pinMode(ledYellowPin, OUTPUT); 169 pinMode(ledRedPin, OUTPUT); 170 pinMode(RelayPin, 171 OUTPUT); 172 pinMode(ButtonPin, INPUT); 173 pinMode(ProbePin, INPUT); 174 pinMode(VBattPin, 175 INPUT); 176 pinMode(VRawPin, INPUT); 177 digitalWrite(RelayPin,OPEN); // disconnects 178 power from battery 179 digitalWrite(ledBluePin,HIGH); // LEDs test show 180 delay(150); 181 182 digitalWrite(ledBluePin,LOW); 183 digitalWrite(ledYellowPin,HIGH); 184 delay(150); 185 186 digitalWrite(ledYellowPin,LOW); 187 digitalWrite(ledRedPin,HIGH); 188 delay(150); 189 190 digitalWrite(ledRedPin,LOW); 191} // setup() 192 193void loop() { 194 readProbe(); 195 196 display(); 197 if ((prevMillisReadVoltages+MillisReadVoltages) < millis()) readVoltages(); 198 199 if ((prevMillisCheckCharge+MillisCheckCharge) < millis()) checkCharge(); 200 if 201 (((prevMillisDebug+MillisDebug) < millis()) && (IsDEBUG)) printDebugging(); 202} 203 // loop() 204 205void display() { 206 digitalWrite(ledBluePin,LOW); 207 digitalWrite(ledYellowPin,LOW); 208 209 digitalWrite(ledRedPin,LOW); 210 if (VPower > 0) { // ------------------------- 211 with USB power 212 if (IsCharging==true) { 213 if (IsOverTime==false) { 214 215 if (SoC <= 20) blink_red(); 216 if (SoC > 20 && SoC <=40) blink_red_yellow(); 217 218 if (SoC > 40 && SoC <=60) blink_yellow(); 219 if (SoC > 60 && SoC 220 <=80) blink_yellow_blue(); 221 if (SoC > 80 && SoC <=90) blink_blue(); 222 223 if (SoC > 90) blink_slowblue(); 224 } else { 225 blink_quickyellow(); 226 //overtime warning 227 } 228 } else { 229 blink_quickblue(); //battery 230 already charged 231 } 232 } else { 233 switch (Status) { // ----------------------- 234 with battery, normal probing operation 235 case 0: 236 digitalWrite(ledBluePin, 237 HIGH); 238 break; 239 case 1: 240 digitalWrite(ledRedPin, HIGH); 241 242 break; 243 case 2: 244 digitalWrite(ledYellowPin, HIGH); 245 break; 246 247 } 248 prevStatus=Status; 249 } 250} // display() 251 252 253void readVoltages() 254 { 255 n=analogRead(VRawPin); 256 if (n > 0) { 257 n1=(((6.60 * n) / 1023.00)); 258 // 6.60 = 3.30 x 2 (voltage divider /2 in input) 259 VRaw=(n1 + ((n1 * 0.0) 260 /100)); // arbitrary correction (not active, +-0.0%) 261 } else { 262 VRaw=0; 263 264 } 265 VPower=VRaw; 266 n=analogRead(VBattPin); 267 if (n > 0) { 268 n1=(((6.60 269 * n) / 1023.00)); // 6.60 = 3.30 x 2 (voltage divider /2 in input) 270 VBatt=(n1 271 + ((n1 * 0.0) /100)); // arbitrary correction (not active, +-0.0%) 272 } else 273 { 274 VBatt=0; 275 } 276 if (VInitBatt==0) VInitBatt=VBatt; // initial battery 277 voltage, at power-on 278 prevMillisReadVoltages=millis(); 279} // readVoltages() 280 281 282void 283 checkCharge() { 284 if ((IsCharging == false) && (VPower >= VMinPower) && (VBatt 285 < VBchgd)) { 286 ChTimeStart=int((millis()/1000)/60); // start charging, elapsed 287 time as minutes from power-up 288 digitalWrite(RelayPin,CLOSE); // connets power 289 to battery 290 VInitBatt=VBatt; // initial charging battery voltage 291 IsOverTime=false; 292 293 IsCharging=true; 294 } 295 if ((IsCharging == true) && ((VPower < VMinPower) 296 || (VBatt >= VMax))) { 297 ChTimeEnd=int((millis()/1000)/60); // end charging, 298 elapsed time as minutes from power-up 299 digitalWrite(RelayPin,OPEN); // disconnects 300 power from battery 301 VInitBatt=VBatt; // battery voltage, just after charging 302 is finished 303 IsCharging=false; 304 } 305 IBatt = ((VPower - VBatt) / VResis) 306 - ICirc; // charging current; 0.066A at 0%, 0.034A at 50%, 0.002A at 100% 307 IBattAvg 308 = ((VPower - ((VMax+VBmin)/2) ) / VResis) - ICirc; // 0.034A average charging current 309 310 SoC = 100 - ((VMax - VBatt) * 100); // state of charge in % 311 TFull = (CBatt 312 / IBattAvg) * 60; // 529 minutes, time of charging at average current and battery 313 at VBmin 314 TMaxChg = TFull * (VMax - VInitBatt) * ETFact * OvTiFact; // estimated 315 maximum time of charging considering initial voltage state, in minutes 316 TChg 317 = (TFull * (VMax - VBatt)) * ETFact; // estimated remaining time of charging in 318 minutes 319 ChTimeNow=int((millis()/1000)/60); // now time as minutes from power-up 320 321 if ((ChTimeNow-ChTimeStart) > TMaxChg) IsOverTime=true; 322 prevMillisCheckCharge=millis(); 323} 324 // checkCharge() 325 326 327void readProbe() { 328 if (digitalRead(ButtonPin) 329 == LOW) { 330 isCMOS=true; 331 } else { 332 isCMOS=false; 333 } 334 n = 335 analogRead(ProbePin); 336 if (n > 0) { 337 n1=(((9.90 * n) / 1023.00)); // 338 9.90 = 3.30 x 3 (voltage divider /3 in input) 339 VProbe=(n1 + ((n1 * 0.0) /100)); 340 // arbitrary correction (not active, +-0.0%) 341 } else { 342 VProbe=0; 343 344 } 345 if (isCMOS==false) { // TTL case 346 if (VProbe <= 0.8) { 347 Status=0; 348 349 } 350 if (VProbe > 0.8 && VProbe <= 2.0) { 351 Status=2; 352 } 353 354 if (VProbe > 2.0) { 355 Status=1; 356 } 357 } 358 if (isCMOS==true) 359 { // CMOS case 360 if (VProbe <= 1.5) { 361 Status=0; 362 } 363 if 364 (VProbe > 1.5 && VProbe <= 3.5) { 365 Status=2; 366 } 367 if (VProbe 368 > 3.5) { 369 Status=1; 370 } 371 } 372} // readProbe() 373 374void blink_red() 375 { 376 delay(500); 377 digitalWrite(ledRedPin, HIGH); 378} 379void blink_blue() 380 { 381 delay(500); 382 digitalWrite(ledBluePin, HIGH); 383 delay(500); 384} 385void 386 blink_yellow() { 387 delay(500); 388 digitalWrite(ledYellowPin, HIGH); 389 delay(500); 390} 391void 392 blink_red_yellow() { 393 delay(500); 394 digitalWrite(ledRedPin, HIGH); 395 delay(500); 396 397 digitalWrite(ledRedPin, LOW); 398 digitalWrite(ledYellowPin, HIGH); 399 delay(500); 400} 401void 402 blink_yellow_blue() { 403 delay(500); 404 digitalWrite(ledYellowPin, HIGH); 405 406 delay(500); 407 digitalWrite(ledYellowPin, LOW); 408 digitalWrite(ledBluePin, 409 HIGH); 410 delay(500); 411} 412void blink_slowblue() { 413 delay(1000); 414 digitalWrite(ledBluePin, 415 HIGH); 416 delay(2000); 417} 418void blink_quickyellow() { 419 delay(100); 420 421 digitalWrite(ledYellowPin, HIGH); 422 delay(100); 423} 424void blink_quickblue() 425 { 426 delay(100); 427 digitalWrite(ledBluePin, HIGH); 428 delay(100); 429} 430void 431 printDebugging() { 432 Serial.println("----------------------------------------------"); 433 434 if (IsCharging) { 435 Serial.print("IsCharging="); 436 Serial.println(IsCharging); 437 438 Serial.print("VRaw (VPower)="); 439 Serial.println(VRaw); 440 Serial.print("VInitBatt="); 441 442 Serial.println(VInitBatt); 443 Serial.print("VBatt="); 444 Serial.println(VBatt); 445 446 Serial.print("IBatt="); 447 Serial.println(IBatt); 448 Serial.print("IBattAvg="); 449 450 Serial.println(IBattAvg); 451 Serial.print("SoC%="); 452 Serial.println(SoC); 453 454 Serial.print("TFull="); 455 Serial.println(TFull); 456 Serial.print("TMaxChg 457 max minutes, more is OverTime="); 458 Serial.println(TMaxChg); 459 Serial.print("TChg 460 remaining minutes="); 461 Serial.println(TChg); 462 Serial.print("ChTimeStart="); 463 464 Serial.println(ChTimeStart); 465 Serial.print("TimeNow="); 466 Serial.println(ChTimeNow); 467 468 Serial.print("IsOverTime="); 469 Serial.println(IsOverTime); 470 471 Serial.print("VProbe="); 472 Serial.println(VProbe); 473 } else { 474 475 Serial.print("IsCharging="); 476 Serial.println(IsCharging); 477 Serial.print("VRaw 478 (VPower)="); 479 Serial.println(VRaw); 480 Serial.print("VInitBatt="); 481 482 Serial.println(VInitBatt); 483 Serial.print("VBatt="); 484 Serial.println(VBatt); 485 486 Serial.print("SoC%="); 487 Serial.println(SoC); 488 Serial.print("ChTimeStart="); 489 490 Serial.println(ChTimeStart); 491 Serial.print("ChTimeEnd="); 492 Serial.println(ChTimeEnd); 493 494 Serial.print("TimeNow="); 495 Serial.println(ChTimeNow); 496 Serial.print("Millis()= 497 "); 498 Serial.println(millis()); 499 Serial.print("VProbe="); 500 Serial.println(VProbe); 501 502 } 503 prevMillisDebug=millis(); 504} // printDebugging() 505
Downloadable files
Main PCB top face
Main PCB top face
Main PCB components face
Main PCB components face
Main PCB bottom face
Main PCB bottom face
Microcontroller PCB top face
Microcontroller PCB top face
Microcontroller PCB components face
Microcontroller PCB components face
Main PCB overview
Main PCB overview
Main Fritzing schematic diagram
Main Fritzing schematic diagram
Microcontroller PCB overview
Microcontroller PCB overview
Microcontroller PCB bottom face
Microcontroller PCB bottom face
Main PCB components face
Main PCB components face
Microcontroller PCB components face
Microcontroller PCB components face
Main PCB overview
Main PCB overview
Main Fritzing schematic diagram
Main Fritzing schematic diagram
Microcontroller PCB overview
Microcontroller PCB overview
Microcontroller PCB bottom face
Microcontroller PCB bottom face
Main PCB bottom face
Main PCB bottom face
Main PCB top face
Main PCB top face
Microcontroller PCB top face
Microcontroller PCB top face
Microcontroller Fritzing schematic diagram
Microcontroller Fritzing schematic diagram
Comments
Only logged in users can leave comments
marcozonca
11 Followers
•11 Projects
2
1
A Tiny Logic Probe TTL / CMOS with Battery Charger | Arduino Project Hub
marcozonca
a year ago
Please check updates of this and other my projects on https://www.hackster.io/marcozonca and keep in contact with me too with your comments and questions there. Thank you.