summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Drake <Joshua.Ellis.Drake@gmail.com>2024-06-06 16:23:43 -0500
committerJoshua Drake <Joshua.Ellis.Drake@gmail.com>2024-06-06 16:23:43 -0500
commited2644ef4e934f2f7cf93890760737790925a1c8 (patch)
tree9acece7182c9dde4d3bd665705a8f795e8b2fc8a
parentf54fe1d4bfdec539ec9143d1ec9040bb737e850a (diff)
Changed loss of connection behavior and cleaned up code.
-rw-r--r--Arduino/main.c/main.c.ino26
-rw-r--r--SPI.c13
-rw-r--r--SPI.h2
-rw-r--r--build/default/debug/SPI.obin15548 -> 15580 bytes
-rw-r--r--build/default/debug/main.obin8156 -> 9044 bytes
-rw-r--r--build/default/debug/mcc_generated_files/mssp2_i2c.obin19196 -> 19500 bytes
-rw-r--r--build/default/production/SPI.obin15592 -> 15580 bytes
-rw-r--r--build/default/production/main.obin8908 -> 8920 bytes
-rw-r--r--dist/default/production/memoryfile.xml4
-rw-r--r--main.c79
-rw-r--r--nbproject/Makefile-genesis.properties4
11 files changed, 50 insertions, 78 deletions
diff --git a/Arduino/main.c/main.c.ino b/Arduino/main.c/main.c.ino
index cf6ea90..c527c33 100644
--- a/Arduino/main.c/main.c.ino
+++ b/Arduino/main.c/main.c.ino
@@ -1,8 +1,8 @@
#include <Wire.h>
-double VOLTAGE, P100, P150;
+double VOLTAGE, P68, P150;
double temp, load = 0;
-uint8_t Q100, Q150;
+uint8_t Q68, Q150;
bool new_message = false;
void setup()
@@ -15,7 +15,7 @@ void setup()
Serial.print("System Voltage: ");
Serial.println(VOLTAGE, DEC);
P150 = (VOLTAGE * VOLTAGE) / 150;
- P100 = (VOLTAGE * VOLTAGE) / 100;
+ P68 = (VOLTAGE * VOLTAGE) / 68;
Serial.println("Enter Load in kW:");
}
@@ -28,32 +28,32 @@ void loop()
if ((temp != load) && (temp > 0))
{
load = temp;
- if (VOLTAGE <= 500) //We don't want to use the 100ohm resistors if the voltage is higher than 500 as they would draw excessive power.
+ if (VOLTAGE <= 420) //We don't want to use the 68ohm resistors if the voltage is higher than 420 as they would draw excessive power.
{
- Q100 = load / P100;
- if (Q100 > 5) Q100 = 5;
- Q150 = (load - (Q100 * P100)) / P150;
+ Q68 = load / P68;
+ if (Q68 > 5) Q68 = 5;
+ Q150 = (load - (Q68 * P68)) / P150;
}
else
{
Q150 = load / P150;
- Q100 = 0;
+ Q68 = 0;
}
if (Q150 > 15) Q150 = 15;
Serial.print("A combination of ");
Serial.print(Q150, DEC);
Serial.print(" 150ohm and ");
- Serial.print(Q100, DEC);
- Serial.print(" 100ohm resistors will be requested. ");
+ Serial.print(Q68, DEC);
+ Serial.print(" 68ohm resistors will be requested. ");
//Serial.print(load - ((P150*Q150)+(P100*Q100)),DEC);
- Serial.print(((P150 * Q150) + (P100 * Q100)), DEC);
+ Serial.print(((P150 * Q150) + (P68 * Q68)), DEC);
Serial.println("W Accounted for.");
new_message = true;
}
delay(50);
Wire.beginTransmission(0x30); //Controller Board Has Address 0x07
Wire.write(0x01); //First "EEPROM Address" stores resistor data.
- Wire.write((Q100 << 4) | Q150);
+ Wire.write((Q68 << 4) | Q150);
Wire.endTransmission();
@@ -64,7 +64,7 @@ void loop()
int c = Wire.read();
Serial.print("Quantity of 150Ohm: ");
Serial.print(c & 0b00001111); //Print Q150
- Serial.print(" Quantity of 100Ohm: ");
+ Serial.print(" Quantity of 68Ohm: ");
Serial.print((c & 0b01110000)>>4);
Serial.println(" was recieved.");
}
diff --git a/SPI.c b/SPI.c
index 96a18a8..1fff384 100644
--- a/SPI.c
+++ b/SPI.c
@@ -38,7 +38,7 @@
if(Ohm_150>7)WriteBuffer[3] = 0x7f;
else WriteBuffer[3] = (0x7f >> (7-Ohm_150));// + ((Ohm_68 - 4)<<7);
- WriteBuffer[5] = 0xff >> (15-Ohm_150);
+ WriteBuffer[5] = 0xff << (15-Ohm_150);
if(Ohm_68<5)WriteBuffer[1] = ((0xf0 >> (Ohm_68))&0x0f)| (testLED << 7);
else {WriteBuffer[1] = 0x0f | (testLED << 7); WriteBuffer[3] |= 0x80;}
//WriteBuffer[1] = 0xFF;
@@ -46,15 +46,16 @@
SPI_slaveSelect();
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
SPI_slaveDeselect();
+ //if(ReadBuffer[5]>0)_LATB8 = 0;
}
void active(uint8_t *activeResistors)
{
- WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40;
+ WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40; //Output driver data will be received by host controller after next message is sent.
WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02;
SPI_slaveSelect();
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
SPI_slaveDeselect();
- WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x00;
+ WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x00; //Output diagnostic data on next frame
WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x00;
SPI_slaveSelect();
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
@@ -132,12 +133,10 @@
SPI_slaveDeselect();
}
- void Message_HWCROCL(uint8_t outputs[3])
+ void Message_HWCROCL()
{
WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x8D;
- WriteBuffer[1] = outputs[0];
- WriteBuffer[3] = outputs[1];
- WriteBuffer[5] = outputs[2];
+ WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0xff;
}
void Message_HWCRPWM(uint8_t outputs[3])
diff --git a/SPI.h b/SPI.h
index 6cdeeea..2fcc0d4 100644
--- a/SPI.h
+++ b/SPI.h
@@ -309,7 +309,7 @@ synchronized. See section ?Outputs in Parallel? for output combinations
Message_DAGOLONEN({0b11xx0000, 0b00xx0000, 0b00xx0000}); //Device 1 enters active mode, resets SPI operation, and maintains normal latch operation.
*/
- void Message_HWCROCL(uint8_t outputs[3]);
+ void Message_HWCROCL(voids);
/**
@Summary
Output Latch (ERRn) Clear bits (HWCR_OCL.OUTn)
diff --git a/build/default/debug/SPI.o b/build/default/debug/SPI.o
index aad8f34..3f25dd1 100644
--- a/build/default/debug/SPI.o
+++ b/build/default/debug/SPI.o
Binary files differ
diff --git a/build/default/debug/main.o b/build/default/debug/main.o
index 2e756c0..9d9cf16 100644
--- a/build/default/debug/main.o
+++ b/build/default/debug/main.o
Binary files differ
diff --git a/build/default/debug/mcc_generated_files/mssp2_i2c.o b/build/default/debug/mcc_generated_files/mssp2_i2c.o
index 4a618a4..ffcfcef 100644
--- a/build/default/debug/mcc_generated_files/mssp2_i2c.o
+++ b/build/default/debug/mcc_generated_files/mssp2_i2c.o
Binary files differ
diff --git a/build/default/production/SPI.o b/build/default/production/SPI.o
index 4a81a77..3f25dd1 100644
--- a/build/default/production/SPI.o
+++ b/build/default/production/SPI.o
Binary files differ
diff --git a/build/default/production/main.o b/build/default/production/main.o
index 2ffe358..2ab8071 100644
--- a/build/default/production/main.o
+++ b/build/default/production/main.o
Binary files differ
diff --git a/dist/default/production/memoryfile.xml b/dist/default/production/memoryfile.xml
index 9180b88..ad07adc 100644
--- a/dist/default/production/memoryfile.xml
+++ b/dist/default/production/memoryfile.xml
@@ -11,8 +11,8 @@
<memory name="program">
<units>bytes</units>
<length>16128</length>
- <used>4362</used>
- <free>11766</free>
+ <used>4353</used>
+ <free>11775</free>
</memory>
</executable>
</project>
diff --git a/main.c b/main.c
index 11787fd..ca5aa4b 100644
--- a/main.c
+++ b/main.c
@@ -1,9 +1,4 @@
/**
- Generated main.c file from MPLAB Code Configurator
-
- @Company
- Microchip Technology Inc.
-
@File Name
main.c
@@ -19,29 +14,6 @@
Compiler : XC16 v2.10
MPLAB : MPLAB X v6.05
*/
-
-/*
- (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this
- software and any derivatives exclusively with Microchip products.
-
- THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
- EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
- WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
- PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
- WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
-
- IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
- INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
- WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
- BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
- FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
- ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
- THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
-
- MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
- TERMS.
-*/
-
/**
Section: Included Files
*/
@@ -83,36 +55,37 @@ int main(void)
desired150 = getI2CArray(1) & 0x0F;
desired68 = (getI2CArray(1) >> 4) & 0x07;
- if((relay_delay)&&(*timeoutcounter < 2))
+ if (relay_delay)
{
- _LATB8 = 1;
- relay_delay = false;
- active(activeResistors);
-
- if(desired150 < activeResistors[0])
- {
- Message_OUT(activeResistors[0]-1, activeResistors[1], 1);
- }
- else if(desired150 > activeResistors[0])
- {
- Message_OUT(activeResistors[0]+1, activeResistors[1], 1);
- }
- else if(desired68 < activeResistors[1])
+ active(activeResistors);
+ if (*timeoutcounter < 2)
{
- Message_OUT(activeResistors[0], activeResistors[1]-1, 0);
- }
- else if(desired68 > activeResistors[1])
+ _LATB8 = 1;
+ relay_delay = false;
+
+ if (desired150 < activeResistors[0])
+ {
+ Message_OUT(activeResistors[0] - 1, activeResistors[1], 1);
+ } else if (desired150 > activeResistors[0])
+ {
+ Message_OUT(activeResistors[0] + 1, activeResistors[1], 1);
+ } else if (desired68 < activeResistors[1])
+ {
+ Message_OUT(activeResistors[0], activeResistors[1] - 1, 0);
+ } else if (desired68 > activeResistors[1])
+ {
+ Message_OUT(activeResistors[0], activeResistors[1] + 1, 0);
+ }
+ }
+ else //Open contactors if I2C communication is broken.
{
- Message_OUT(activeResistors[0], activeResistors[1]+1, 0);
+ if (relay_delay) Message_OUT(activeResistors[0] - 1, activeResistors[1] - 1, 0);
+ _LATB7 = 1; //Make sure activity light is off
+ _LATB8 = 0;
+ //Message_HWCROCL();
}
}
-
- if(*timeoutcounter > 0x02) //Open contactors if I2C communication is broken.
- {
- Message_OUT(0, 0, 0);
- _LATB7 = 1; //Make sure activity light is off
- _LATB8 = 0;
- }
+ //Message_OUT(15, 0, 1);
//(desired150, desired68, relay_delay);
//if(activeResistors[1]==3){_LATB8=0;}
diff --git a/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties
index e8ecf1c..23d9a04 100644
--- a/nbproject/Makefile-genesis.properties
+++ b/nbproject/Makefile-genesis.properties
@@ -1,11 +1,11 @@
#
-#Fri May 03 20:19:47 CDT 2024
+#Thu Jun 06 16:11:03 CDT 2024
default.languagetoolchain.version=2.10
default.Pack.dfplocation=/opt/microchip/mplabx/v6.15/packs/Microchip/PIC24F-KA-KL-KM_DFP/1.4.83
default.com-microchip-mplab-mdbcore-PK5Tool-PK5ToolImpl.md5=723771b957e0f1e0ec1761a42d8bb5e8
conf.ids=default
default.languagetoolchain.dir=/opt/microchip/xc16/v2.10/bin
-host.id=0
+host.id=17y8-g9hi-6g
configurations-xml=297850d1f3e30335411a86c54d420620
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=e62346c0c0ecee2637e613b49cb7b7fa
proj.dir=/home/josh/MPLABXProjects/resbox