summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SPI.c18
-rw-r--r--SPI.h4
-rw-r--r--build/default/production/SPI.obin15592 -> 15592 bytes
-rw-r--r--build/default/production/main.obin8560 -> 8896 bytes
-rw-r--r--build/default/production/mcc_generated_files/mssp2_i2c.obin19196 -> 19500 bytes
-rw-r--r--dist/default/production/memoryfile.xml8
-rw-r--r--main.c48
-rw-r--r--mcc_generated_files/mssp2_i2c.c15
-rw-r--r--mcc_generated_files/mssp2_i2c.h3
-rw-r--r--nbproject/Makefile-genesis.properties8
-rw-r--r--nbproject/configurations.xml93
-rw-r--r--nbproject/private/configurations.xml2
12 files changed, 148 insertions, 51 deletions
diff --git a/SPI.c b/SPI.c
index a6590b4..96a18a8 100644
--- a/SPI.c
+++ b/SPI.c
@@ -35,17 +35,19 @@
//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);
+
+ if(Ohm_150>7)WriteBuffer[3] = 0x7f;
+ else WriteBuffer[3] = (0x7f >> (7-Ohm_150));// + ((Ohm_68 - 4)<<7);
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;
//if (Ohm_68 == 5) WriteBuffer[3]|= 0b10000000;
SPI_slaveSelect();
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
SPI_slaveDeselect();
}
- void active(uint8_t *ohm150, uint8_t *ohm68)
+ void active(uint8_t *activeResistors)
{
WriteBuffer[0] = WriteBuffer[2] = WriteBuffer[4] = 0x40;
WriteBuffer[1] = WriteBuffer[3] = WriteBuffer[5] = 0x02;
@@ -57,9 +59,11 @@
SPI_slaveSelect();
readData = MSSP1_SPI_Exchange8bitBuffer(WriteBuffer, 6, ReadBuffer);
SPI_slaveDeselect();
- ohm150 = bitcount(ReadBuffer[3]&0x7F) + bitcount(ReadBuffer[5]); //+ bitcount(ReadBuffer[3] << 1));
+ activeResistors[0] = bitcount(ReadBuffer[3]&0x7F) + bitcount(ReadBuffer[5]); //+ bitcount(ReadBuffer[3] << 1));
//ohm150 = bitcount(ReadBuffer[3]);// + ReadBuffer[5] + ReadBuffer[3] + ReadBuffer[1];
- ohm68 = ((ReadBuffer[3] & 0x80)>>7) + bitcount(ReadBuffer[0] & 0x0f);
+ activeResistors[1] = /*((ReadBuffer[3] & 0x80)>>7) +*/ bitcount(ReadBuffer[1] & 0x0f);
+ //activeResistors[0] = 0;
+ //activeResistors[0] = 3;
}
@@ -182,7 +186,7 @@
WriteBuffer[5] = outputs[2];
}
-int bitcount(uint8_t n)
+uint8_t bitcount(uint8_t n)
{
uint8_t count = 0;
while (n > 0)
diff --git a/SPI.h b/SPI.h
index 4181835..6cdeeea 100644
--- a/SPI.h
+++ b/SPI.h
@@ -57,8 +57,8 @@
Message_OUT(15, 5, false); //Max Load with testLED turned off.
*/
- void active(uint8_t *ohm150, uint8_t *ohm68);
- int bitcount(uint8_t);
+ void active(uint8_t *activeResistors);
+ uint8_t bitcount(uint8_t);
void Message_BIM(uint8_t outputs[3]);
/**
@Summary
diff --git a/build/default/production/SPI.o b/build/default/production/SPI.o
index a1791f2..4a81a77 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 189c9dc..20c5e38 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 4a618a4..1a72c9e 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/dist/default/production/memoryfile.xml b/dist/default/production/memoryfile.xml
index d64cd8d..48256ad 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>100</used>
- <free>1948</free>
+ <used>98</used>
+ <free>1950</free>
</memory>
<memory name="program">
<units>bytes</units>
<length>16128</length>
- <used>4188</used>
- <free>11940</free>
+ <used>4359</used>
+ <free>11769</free>
</memory>
</executable>
</project>
diff --git a/main.c b/main.c
index 77d9b11..04c1754 100644
--- a/main.c
+++ b/main.c
@@ -53,8 +53,10 @@
/*
Main application
*/
-uint8_t desired150, desired68, current150, current68 = 0;
+uint8_t activeResistors[2] = {0x00,0x00};
+uint8_t desired150, desired68 = 0;
bool relay_delay = false;
+static uint8_t* timeoutcounter;
void TMR1_Process(void);
@@ -77,41 +79,43 @@ int main(void)
while (1)
{
+ timeoutcounter = getTimeoutCounter();
desired150 = getI2CArray(1) & 0x0F;
- desired68 = (getI2CArray(1) & 0x70) >> 4;
+ desired68 = (getI2CArray(1) >> 4) & 0x07;
- //if((relay_delay)&&(getTimeoutCounter() < 2))
- //{
- //relay_delay = false;
- active(&current150,&current68);
- /*
- if(desired150 < current150)
+ if((relay_delay)&&(*timeoutcounter < 2))
+ {
+ _LATB8 = 1;
+ relay_delay = false;
+ active(activeResistors);
+
+ if(desired150 < activeResistors[0])
{
- Message_OUT(current150-1, current68, 1);
+ Message_OUT(activeResistors[0]-1, activeResistors[1], 1);
}
- else if(desired150 > current150)
+ else if(desired150 > activeResistors[0])
{
- Message_OUT(current150+1, current68, 1);
+ Message_OUT(activeResistors[0]+1, activeResistors[1], 1);
}
- else if(desired68 < current68)
+ else if(desired68 < activeResistors[1])
{
- Message_OUT(current150, current68-1, 1);
+ Message_OUT(activeResistors[0], activeResistors[1]-1, 0);
}
- else if(desired68 > current68)
+ else if(desired68 > activeResistors[1])
{
- Message_OUT(current150, current68+1, 1);
+ Message_OUT(activeResistors[0], activeResistors[1]+1, 0);
}
}
-
- if(getTimeoutCounter() > 2){ //Open contactors if I2C communication is broken.
+
+ if(*timeoutcounter > 0x02) //Open contactors if I2C communication is broken.
+ {
Message_OUT(0, 0, 0);
-
_LATB8 = 0;
- _LATB7 = 1;
- }*/
- Message_OUT(2, 0, relay_delay);
+ }
+ //(desired150, desired68, relay_delay);
- if(current150>0){_LATB8=0; _LATB7=0;}
+ //if(activeResistors[1]==3){_LATB8=0;}
+ //else{_LATB8=1;}
}
return 1;
diff --git a/mcc_generated_files/mssp2_i2c.c b/mcc_generated_files/mssp2_i2c.c
index dabd9a9..580366b 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 = 10; //Number of timer iterations since clear
+static uint8_t I2C_timeout = 0; //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,10 +188,10 @@ void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) {
}
if (SSP2STATbits.R_NOT_W == 0) // Master write (slave receive)
{
-
+ resetTimeoutCounter(); //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.
+ //resetTimeoutCounter(); //Reset our counter when a message is received.
_LATB7 = !_LATB7;
regAdd = 1; // Next byte register address
temp = SSP2BUF; // Clear BF
@@ -199,6 +199,7 @@ void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) {
}
if (SSP2STATbits.D_NOT_A == 1) // Last byte was data
{
+ //resetTimeoutCounter(); //Reset our counter when a message is received.
if (regAdd == 1) // Last byte was register add
{
index = SSP2BUF; // Load register address
@@ -225,15 +226,19 @@ void __attribute__((interrupt, no_auto_psv)) _MSSP2Interrupt(void) {
_LATB8 = !SSP2CON1bits.SSPOV;
}
-uint8_t getTimeoutCounter()
+uint8_t* getTimeoutCounter()
{
- return I2C_timeout;
+ return &I2C_timeout;
}
void incrementTimeoutCounter()
{
I2C_timeout++;
}
+void resetTimeoutCounter()
+{
+ I2C_timeout = 0x00;
+}
uint8_t getI2CArray(int index)
{
if(index < 5)return i2cArray[index];
diff --git a/mcc_generated_files/mssp2_i2c.h b/mcc_generated_files/mssp2_i2c.h
index f76d48c..329983a 100644
--- a/mcc_generated_files/mssp2_i2c.h
+++ b/mcc_generated_files/mssp2_i2c.h
@@ -149,7 +149,8 @@ typedef enum
</code>
*/
-uint8_t getTimeoutCounter(void);
+uint8_t* getTimeoutCounter(void);
+void resetTimeoutCounter(void);
void incrementTimeoutCounter(void);
void MSSP2_I2C_Initialize(void);
diff --git a/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties
index 58a5b7d..e8ecf1c 100644
--- a/nbproject/Makefile-genesis.properties
+++ b/nbproject/Makefile-genesis.properties
@@ -1,13 +1,13 @@
#
-#Thu May 02 18:31:10 CDT 2024
+#Fri May 03 20:19:47 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=17y8-g9hi-6g
-configurations-xml=548bce5bcce17c7b8a52ea2b767e1662
+host.id=0
+configurations-xml=297850d1f3e30335411a86c54d420620
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=e62346c0c0ecee2637e613b49cb7b7fa
proj.dir=/home/josh/MPLABXProjects/resbox
-default.com-microchip-mplab-mdbcore-pk4hybrid-Pk4HybridTooImpl.md5=38058ec39ea8224adcc766836376f0d6
host.platform=linux
default.com-microchip-mplab-nbide-toolchain-xc16-XC16LanguageToolchain.md5=07f7da95e66d00aa4668de5175f752c5
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 8b11231..b91c632 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -57,7 +57,7 @@
<targetDevice>PIC24FV16KM202</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
- <platformTool>pk4hybrid</platformTool>
+ <platformTool>PK5Tool</platformTool>
<languageToolchain>XC16</languageToolchain>
<languageToolchainVersion>2.10</languageToolchainVersion>
<platform>2</platform>
@@ -222,6 +222,89 @@
<property key="relaxed-math" value="false"/>
<property key="save-temps" value="false"/>
</C30Global>
+ <PK5Tool>
+ <property key="ADC 1" value="true"/>
+ <property key="AutoSelectMemRanges" value="auto"/>
+ <property key="CLC 1" value="true"/>
+ <property key="CLC 2" value="true"/>
+ <property key="CTMU" value="true"/>
+ <property key="Comparators" value="true"/>
+ <property key="DAC 1" value="true"/>
+ <property key="DAC 2" value="true"/>
+ <property key="Freeze All Other Peripherals" value="true"/>
+ <property key="HLVD" value="true"/>
+ <property key="MCCP/SCCP 1" value="true"/>
+ <property key="MCCP/SCCP 2" value="true"/>
+ <property key="MCCP/SCCP 3" value="true"/>
+ <property key="MCCP/SCCP 4" value="true"/>
+ <property key="MCCP/SCCP 5" value="true"/>
+ <property key="OPAMP 1" value="true"/>
+ <property key="OPAMP 2" value="true"/>
+ <property key="REFO Clock" value="true"/>
+ <property key="RTCC" value="true"/>
+ <property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
+ <property key="TIMER 1" value="true"/>
+ <property key="ToolFirmwareFilePath"
+ value="Press to browse for a specific firmware version"/>
+ <property key="ToolFirmwareOption.UpdateOptions"
+ value="ToolFirmwareOption.UseLatest"/>
+ <property key="ToolFirmwareToolPack"
+ value="Press to select which tool pack to use"/>
+ <property key="UART 1" value="true"/>
+ <property key="UART 2" value="true"/>
+ <property key="ULPWU" value="true"/>
+ <property key="communication.activationmode" value="nohv"/>
+ <property key="communication.interface" value=""/>
+ <property key="communication.interface.jtag" value="2wire"/>
+ <property key="communication.speed" value="${communication.speed.default}"/>
+ <property key="debugoptions.debug-startup" value="Use system settings"/>
+ <property key="debugoptions.reset-behaviour" value="Use system settings"/>
+ <property key="debugoptions.useswbreakpoints" value="false"/>
+ <property key="event.recorder.enabled" value="false"/>
+ <property key="event.recorder.scvd.files" value=""/>
+ <property key="hwtoolclock.frcindebug" value="false"/>
+ <property key="lastid" value=""/>
+ <property key="memories.aux" value="false"/>
+ <property key="memories.bootflash" value="true"/>
+ <property key="memories.configurationmemory" value="true"/>
+ <property key="memories.configurationmemory2" value="true"/>
+ <property key="memories.dataflash" value="true"/>
+ <property key="memories.eeprom" value="true"/>
+ <property key="memories.exclude.configurationmemory" value="true"/>
+ <property key="memories.flashdata" value="true"/>
+ <property key="memories.id" value="true"/>
+ <property key="memories.instruction.ram.ranges"
+ value="${memories.instruction.ram.ranges}"/>
+ <property key="memories.programmemory" value="true"/>
+ <property key="memories.programmemory.ranges" value="0-2bff"/>
+ <property key="poweroptions.powerenable" value="false"/>
+ <property key="programmerToGoImageName" value="default_ptg"/>
+ <property key="programoptions.donoteraseauxmem" value="false"/>
+ <property key="programoptions.eraseb4program" value="true"/>
+ <property key="programoptions.ledbrightness" value="5"/>
+ <property key="programoptions.pgcconfig" value="pull down"/>
+ <property key="programoptions.pgcresistor.value" value="4.7"/>
+ <property key="programoptions.pgdconfig" value="pull down"/>
+ <property key="programoptions.pgdresistor.value" value="4.7"/>
+ <property key="programoptions.pgmentry.voltage" value="high"/>
+ <property key="programoptions.pgmspeed" value="Med"/>
+ <property key="programoptions.preservedataflash" value="false"/>
+ <property key="programoptions.preserveeeprom" value="false"/>
+ <property key="programoptions.preserveeeprom.ranges" value="7ffe00-7fffff"/>
+ <property key="programoptions.preserveprogram.ranges" value=""/>
+ <property key="programoptions.preserveprogramrange" value="false"/>
+ <property key="programoptions.preserveuserid" value="false"/>
+ <property key="programoptions.programcalmem" value="false"/>
+ <property key="programoptions.programuserotp" value="false"/>
+ <property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
+ <property key="ptgProgramImage" value="true"/>
+ <property key="ptgSendImage" value="true"/>
+ <property key="toolpack.updateoptions"
+ value="toolpack.updateoptions.uselatestoolpack"/>
+ <property key="toolpack.updateoptions.packversion"
+ value="Press to select which tool pack to use"/>
+ <property key="voltagevalue" value="5.0"/>
+ </PK5Tool>
<Simulator>
<property key="codecoverage.enabled" value="Disable"/>
<property key="codecoverage.enableoutputtofile" value="false"/>
@@ -705,7 +788,7 @@
<property key="Comparators" value="true"/>
<property key="DAC 1" value="true"/>
<property key="DAC 2" value="true"/>
- <property key="Freeze All Other Peripherals" value="false"/>
+ <property key="Freeze All Other Peripherals" value="true"/>
<property key="HLVD" value="true"/>
<property key="MCCP/SCCP 1" value="true"/>
<property key="MCCP/SCCP 2" value="true"/>
@@ -731,8 +814,7 @@
<property key="codecoverage.enableoutputtofile" value="false"/>
<property key="codecoverage.outputfile" value=""/>
<property key="communication.activationmode" value="nohv"/>
- <property key="communication.interface"
- value="${communication.interface.default}"/>
+ <property key="communication.interface" value=""/>
<property key="communication.interface.jtag" value="2wire"/>
<property key="communication.speed" value="${communication.speed.default}"/>
<property key="debugoptions.debug-startup" value="Use system settings"/>
@@ -742,6 +824,7 @@
<property key="event.recorder.enabled" value="false"/>
<property key="event.recorder.scvd.files" value=""/>
<property key="freeze.timers" value="false"/>
+ <property key="hwtoolclock.frcindebug" value="false"/>
<property key="lastid" value=""/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
@@ -786,7 +869,7 @@
<property key="programoptions.pgdconfig" value="pull down"/>
<property key="programoptions.pgdresistor.value" value="4.7"/>
<property key="programoptions.pgmentry.voltage" value="high"/>
- <property key="programoptions.pgmspeed" value="Min"/>
+ <property key="programoptions.pgmspeed" value="Med"/>
<property key="programoptions.preservedataflash" value="false"/>
<property key="programoptions.preservedataflash.ranges"
value="${memories.dataflash.default}"/>
diff --git a/nbproject/private/configurations.xml b/nbproject/private/configurations.xml
index 512c97f..4cec2e3 100644
--- a/nbproject/private/configurations.xml
+++ b/nbproject/private/configurations.xml
@@ -4,7 +4,7 @@
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
- <platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>9012:=&lt;rev>0100:=&lt;man>Microchip Technology Incorporated:=&lt;prod>MPLAB PICkit 4:=&lt;sn>BUR222271433:=&lt;drv>x:=&lt;xpt>b:=end</platformToolSN>
+ <platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>9036:=&lt;rev>0100:=&lt;man>Microchip Technology Incorporated:=&lt;prod>MPLAB PICkit 5:=&lt;sn>020026702RYN018328:=&lt;drv>x:=&lt;xpt>b:=end</platformToolSN>
<languageToolchainDir>/opt/microchip/xc16/v2.10/bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>