From 3ee1a69c65589a744b67f770001022a884fe32ba Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Sat, 4 May 2024 11:11:46 -0500 Subject: Code is fully functional with delay timer at uC level. --- main.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'main.c') 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(¤t150,¤t68); - /* - 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; -- cgit v1.2.3