summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SPI.c28
-rw-r--r--SPI.h6
-rw-r--r--build/default/debug/mcc_generated_files/mssp2_i2c.obin19200 -> 19200 bytes
-rw-r--r--build/default/production/SPI.obin13888 -> 15596 bytes
-rw-r--r--build/default/production/main.obin6616 -> 8384 bytes
-rw-r--r--build/default/production/mcc_generated_files/mssp2_i2c.obin17856 -> 19196 bytes
-rw-r--r--build/default/production/mcc_generated_files/tmr1.obin14132 -> 13168 bytes
-rw-r--r--dist/default/production/memoryfile.xml8
-rw-r--r--main.c30
-rw-r--r--mcc_generated_files/mssp2_i2c.c9
-rw-r--r--mcc_generated_files/mssp2_i2c.h2
-rw-r--r--nbproject/Makefile-genesis.properties6
-rw-r--r--nbproject/configurations.xml4
-rw-r--r--nbproject/private/private.xml4
14 files changed, 54 insertions, 43 deletions
diff --git a/SPI.c b/SPI.c
index a526a42..1a1b8b6 100644
--- a/SPI.c
+++ b/SPI.c
@@ -32,26 +32,30 @@
if (Ohm_68 > 5) Ohm_68 = 5;
//WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = (write << 8) | (!write << 7) | 0b000000;
WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0b10000000;
- WriteBuffer[5] = !(0xFF << Ohm_150);
- WriteBuffer[3] = !(0xFF << (Ohm_150 - 8)) | ((Ohm_68 - 4) << 7);
- WriteBuffer[1] = !(0xFF << (Ohm_68 - 1)) | (testLED << 7);
+ //WriteBuffer[1] = 0xFF >> (15-Ohm_150);
+ //WriteBuffer[3] = 0xFE << (7-(Ohm_150-8)) | (Ohm_68 - 4);
+ //2WriteBuffer[1] = 0x0F << (4-(Ohm_68 - 1)) | (testLED << 7);
+ WriteBuffer[1] = (0xf0 >> (Ohm_68 - 1)) | (testLED << 7);
+ if(Ohm_150>7)WriteBuffer[3] = 0x7f | ((Ohm_68 - 4)<<7);
+ else WriteBuffer[3] = (0x7f >> (7-Ohm_150)) | ((Ohm_68 - 4)<<7);
+ WriteBuffer[5] = 0xff >> (15-Ohm_150);
//WriteBuffer[1] = 0xFF;
//if (Ohm_68 == 5) WriteBuffer[3]|= 0b10000000;
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
}
- uint8_t active150()
+ int active150()
{
- WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0b01000000;
- WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x00;
+ WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40;
+ WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02;
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
- return (bitcount(ReadBuffer[5]) + bitcount(ReadBuffer[3] << 1));
+ return bitcount(ReadBuffer[2]&0x7F) + (bitcount(ReadBuffer[4])); //+ bitcount(ReadBuffer[3] << 1));
}
- uint8_t active68()
+ int active68()
{
- WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0b01000000;
- WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x00;
+ WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40;
+ WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02;
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
- return ((ReadBuffer[3] >> 7) + bitcount(ReadBuffer[1] << 1));
+ return ((ReadBuffer[2] & 0x80) + bitcount(ReadBuffer[0] & 0x0f));
}
void Message_BIM(uint8_t outputs[3])
@@ -176,7 +180,7 @@
WriteBuffer[5] = outputs[2];
}
-uint8_t bitcount(uint8_t n)
+int bitcount(uint8_t n)
{
uint8_t count = 0;
while (n > 0)
diff --git a/SPI.h b/SPI.h
index c23fd9f..3988e80 100644
--- a/SPI.h
+++ b/SPI.h
@@ -57,9 +57,9 @@
Message_OUT(15, 5, false); //Max Load with testLED turned off.
*/
- uint8_t active150(void);
- uint8_t active68(void);
- uint8_t bitcount(uint8_t);
+ int active150(void);
+ int active68(void);
+ int bitcount(uint8_t);
void Message_BIM(uint8_t outputs[3]);
/**
@Summary
diff --git a/build/default/debug/mcc_generated_files/mssp2_i2c.o b/build/default/debug/mcc_generated_files/mssp2_i2c.o
index 9e8fbaa..3837607 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 a234b33..528ca5c 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 aec5a52..8414092 100644
--- a/build/default/production/main.o
+++ b/build/default/production/main.o
Binary files differ
diff --git a/build/default/production/mcc_generated_files/mssp2_i2c.o b/build/default/production/mcc_generated_files/mssp2_i2c.o
index 52e6ca2..4a618a4 100644
--- a/build/default/production/mcc_generated_files/mssp2_i2c.o
+++ b/build/default/production/mcc_generated_files/mssp2_i2c.o
Binary files differ
diff --git a/build/default/production/mcc_generated_files/tmr1.o b/build/default/production/mcc_generated_files/tmr1.o
index 540f482..c1fd9de 100644
--- a/build/default/production/mcc_generated_files/tmr1.o
+++ b/build/default/production/mcc_generated_files/tmr1.o
Binary files differ
diff --git a/dist/default/production/memoryfile.xml b/dist/default/production/memoryfile.xml
index 1f3140a..6dda4a3 100644
--- a/dist/default/production/memoryfile.xml
+++ b/dist/default/production/memoryfile.xml
@@ -5,14 +5,14 @@
<memory name="data">
<units>bytes</units>
<length>2048</length>
- <used>92</used>
- <free>1956</free>
+ <used>96</used>
+ <free>1952</free>
</memory>
<memory name="program">
<units>bytes</units>
<length>16128</length>
- <used>3801</used>
- <free>12327</free>
+ <used>4161</used>
+ <free>11967</free>
</memory>
</executable>
</project>
diff --git a/main.c b/main.c
index c4efe2a..e99c874 100644
--- a/main.c
+++ b/main.c
@@ -47,6 +47,7 @@
*/
#include "mcc_generated_files/system.h"
#include "SPI.h"
+#include <stdbool.h>
/*
@@ -54,7 +55,7 @@
*/
uint8_t nullarray = {0x00, 0x00, 0x00};
uint8_t desired150, desired68, current150, current68 = 0;
-uint8_t relay_delay_counter = 0;
+bool relay_delay = false;
void TMR1_Process(void);
@@ -64,7 +65,7 @@ int main(void)
SYSTEM_Initialize();
//OSCCONbits.SOSCEN = 0;
SPI_slaveDeselect();
- _LATA0 = _LATA1 = 1;//_LATA4 = 1; //Activate gate driver chips
+ _LATA0 = _LATA1 = 0;//_LATA4 = 1; //Activate gate driver chips
_LATA4 = 1;
SPI_slaveSelect();
@@ -82,15 +83,16 @@ int main(void)
while (1)
{
- desired150 = getI2CArray(0x01) & 0b00001111;
- desired68 = (getI2CArray(0x01) & 0b01110000) >> 4;
+ desired150 = getI2CArray(1) & 0x0F;
+ desired68 = (getI2CArray(1) & 0x70) >> 4;
- if((relay_delay_counter % 2 == 0)&&(getTimeoutCounter() < 2))
- {
+ //if((relay_delay)&&(getTimeoutCounter() < 2))
+ //{
+ //relay_delay = false;
SPI_slaveSelect();
- current150 = active150();
+ current150 = current150();
SPI_slaveDeselect();
-
+ /*
SPI_slaveSelect();
current68 = active68();
SPI_slaveDeselect();
@@ -121,19 +123,19 @@ int main(void)
}
}
- else { //Open contactors if I2C communication is broken.
+ if(getTimeoutCounter() > 2){ //Open contactors if I2C communication is broken.
SPI_slaveSelect();
Message_OUT(0, 0, 0);
SPI_slaveDeselect();
_LATB8 = 0;
_LATB7 = 1;
- }
- /*
+ }*/
+
SPI_slaveSelect();
- Message_OUT(15, 5, 0);
+ Message_OUT(desired150, 0, relay_delay);
SPI_slaveDeselect();
-
+ /*
SPI_slaveSelect();
Message_OUT(15, 5, 0);
SPI_slaveDeselect();
@@ -156,7 +158,7 @@ int main(void)
void __attribute__ ((weak)) TMR1_Process(void)
{
- relay_delay_counter++;
+ relay_delay = !relay_delay;
incrementTimeoutCounter();
}
/**
diff --git a/mcc_generated_files/mssp2_i2c.c b/mcc_generated_files/mssp2_i2c.c
index 2a07931..dabd9a9 100644
--- a/mcc_generated_files/mssp2_i2c.c
+++ b/mcc_generated_files/mssp2_i2c.c
@@ -128,7 +128,7 @@ uint8_t yeah;
#define ARRAY_CNT 6 // Number of bytes in array
uint8_t slaveAddress = 0x30; // 7-bit slave address
uint8_t index = 0; // Array pointer
-uint8_t I2C_timeout = 0; //Number of timer iterations since clear
+uint8_t I2C_timeout = 10; //Number of timer iterations since clear
uint8_t temp = 0; // Temp register
uint8_t regAdd = 1; // First data byte was reg add
uint8_t i2cArray[ARRAY_CNT] =
@@ -188,9 +188,10 @@ void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) {
}
if (SSP2STATbits.R_NOT_W == 0) // Master write (slave receive)
{
- I2C_timeout = 0x00; //Reset our counter when a message is received.
+
if (SSP2STATbits.D_NOT_A == 0) // Last byte was an address
- {
+ {
+ I2C_timeout = 0; //Reset our counter when a message is received.
_LATB7 = !_LATB7;
regAdd = 1; // Next byte register address
temp = SSP2BUF; // Clear BF
@@ -233,7 +234,7 @@ void incrementTimeoutCounter()
{
I2C_timeout++;
}
-uint8_t getI2CArray(uint8_t index)
+uint8_t getI2CArray(int index)
{
if(index < 5)return i2cArray[index];
else return 0;
diff --git a/mcc_generated_files/mssp2_i2c.h b/mcc_generated_files/mssp2_i2c.h
index 5937b45..f76d48c 100644
--- a/mcc_generated_files/mssp2_i2c.h
+++ b/mcc_generated_files/mssp2_i2c.h
@@ -345,7 +345,7 @@ uint8_t *MSSP2_I2C_ReadPointerGet(void);
</code>
*/
-uint8_t getI2CArray(uint8_t);
+uint8_t getI2CArray(int);
uint8_t *MSSP2_I2C_WritePointerGet(void);
diff --git a/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties
index 22f4b1a..e7e8590 100644
--- a/nbproject/Makefile-genesis.properties
+++ b/nbproject/Makefile-genesis.properties
@@ -1,11 +1,11 @@
#
-#Wed Apr 24 19:53:02 CDT 2024
+#Fri Apr 26 12:52:12 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
conf.ids=default
default.languagetoolchain.dir=/opt/microchip/xc16/v2.10/bin
-host.id=17y8-g9hi-6g
-configurations-xml=89ab504be582c356042d967bf1c98485
+host.id=0
+configurations-xml=67675cd84f9b3787f20789de6c2794fb
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=e62346c0c0ecee2637e613b49cb7b7fa
proj.dir=/home/josh/MPLABXProjects/resbox
default.com-microchip-mplab-mdbcore-pk4hybrid-Pk4HybridTooImpl.md5=38058ec39ea8224adcc766836376f0d6
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 99cc128..e4b4ca8 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -773,7 +773,7 @@
<property key="periphComp4.gte" value="gt"/>
<property key="periphComp5.gte" value="gt"/>
<property key="periphComp6.gte" value="gt"/>
- <property key="poweroptions.powerenable" value="true"/>
+ <property key="poweroptions.powerenable" value="false"/>
<property key="programmerToGoFilePath"
value="/home/josh/MPLABXProjects/resbox.X/debug/default/resbox_ptg"/>
<property key="programmerToGoImageName" value="resbox_ptg"/>
@@ -1304,7 +1304,7 @@
value="${memories.instruction.ram.ranges}"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.ranges" value="0-2bff"/>
- <property key="poweroptions.powerenable" value="true"/>
+ <property key="poweroptions.powerenable" value="false"/>
<property key="programmerToGoImageName" value="resbox_ptg"/>
<property key="programoptions.donoteraseauxmem" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
index d425bc8..95cc132 100644
--- a/nbproject/private/private.xml
+++ b/nbproject/private/private.xml
@@ -3,9 +3,13 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
+ <file>file:/home/josh/MPLABXProjects/resbox/SPI.h</file>
+ <file>file:/home/josh/MPLABXProjects/resbox/mcc_generated_files/mssp1_spi.h</file>
+ <file>file:/home/josh/MPLABXProjects/resbox/SPI.c</file>
<file>file:/home/josh/MPLABXProjects/resbox/main.c</file>
<file>file:/home/josh/MPLABXProjects/resbox/mcc_generated_files/mssp2_i2c.c</file>
<file>file:/home/josh/MPLABXProjects/resbox/mcc_generated_files/tmr1.c</file>
+ <file>file:/home/josh/MPLABXProjects/resbox/mcc_generated_files/mssp2_i2c.h</file>
<file>file:/home/josh/MPLABXProjects/resbox/mcc_generated_files/mssp1_spi.c</file>
</group>
</open-files>