diff --git a/Firmware/Variable_Load/Backup/Variable_Load.4.2.zip b/Firmware/Variable_Load/Backup/Variable_Load.4.2.zip new file mode 100644 index 0000000..210e388 Binary files /dev/null and b/Firmware/Variable_Load/Backup/Variable_Load.4.2.zip differ diff --git a/Firmware/Variable_Load/Bootloader.cydsn/Bootloader.cyprj b/Firmware/Variable_Load/Bootloader.cydsn/Bootloader.cyprj index af61bfd..9804fa0 100755 --- a/Firmware/Variable_Load/Bootloader.cydsn/Bootloader.cyprj +++ b/Firmware/Variable_Load/Bootloader.cydsn/Bootloader.cyprj @@ -426,6 +426,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -745,39 +778,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1075,13 +1075,21 @@ + + + + + + + + - - + + diff --git a/Firmware/Variable_Load/Variable_Load.cydsn/TopDesign/TopDesign.cysch b/Firmware/Variable_Load/Variable_Load.cydsn/TopDesign/TopDesign.cysch index 79f30aa..70aa1fd 100755 Binary files a/Firmware/Variable_Load/Variable_Load.cydsn/TopDesign/TopDesign.cysch and b/Firmware/Variable_Load/Variable_Load.cydsn/TopDesign/TopDesign.cysch differ diff --git a/Firmware/Variable_Load/Variable_Load.cydsn/Variable_Load.cyprj b/Firmware/Variable_Load/Variable_Load.cydsn/Variable_Load.cyprj index 6168db0..b471a35 100755 --- a/Firmware/Variable_Load/Variable_Load.cydsn/Variable_Load.cyprj +++ b/Firmware/Variable_Load/Variable_Load.cydsn/Variable_Load.cyprj @@ -142,6 +142,20 @@ + + + + + + + + + + + + + + @@ -773,53 +787,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1092,32 +1059,51 @@ - + - + - + + + + + + + + + + + + + - + + + + + + + + @@ -1125,32 +1111,51 @@ - + - + - + + + + + + + + + + + + + - + + + + + + + + @@ -1158,20 +1163,20 @@ - + - + - + @@ -1184,20 +1189,20 @@ - + - + - + @@ -1210,25 +1215,46 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + @@ -1236,25 +1262,32 @@ - - + + - - + + - - + + + + + + + + + @@ -1262,25 +1295,32 @@ - + - + - + + + + + + + + @@ -1288,21 +1328,21 @@ - - + + - - + + - - + + @@ -1314,20 +1354,20 @@ - + - + - + @@ -1340,20 +1380,20 @@ - + - + - + @@ -1366,27 +1406,46 @@ - + - + + + + + + + + + + + + + + + + + + + + - + - + @@ -1399,27 +1458,27 @@ - + - + - + - + @@ -1432,27 +1491,27 @@ - + - + - + - + @@ -1465,23 +1524,82 @@ - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1718,301 +1836,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3475,8 +3298,8 @@ - - + + diff --git a/Firmware/Variable_Load/Variable_Load.cydsn/main.c b/Firmware/Variable_Load/Variable_Load.cydsn/main.c index 55dd3c8..849161d 100755 --- a/Firmware/Variable_Load/Variable_Load.cydsn/main.c +++ b/Firmware/Variable_Load/Variable_Load.cydsn/main.c @@ -4,10 +4,15 @@ #include #include "terminal.h" -#define KPN 19 +#define KPN 20 #define KPD 100 -#define KIN 1 -#define KID 10 +#define KIN 5 +#define KID 100 + +#define KPN_P 20 +#define KPD_P 1000 +#define KIN_P 5 +#define KID_P 1000 #define DEFAULT_I_LIM 0 #define DEFAULT_V_MIN 2000 @@ -58,8 +63,10 @@ volatile static int32 systemTimer = 0; static float fiLimit; volatile static uint32 iLimit = DEFAULT_I_LIM; +volatile static uint32 pLimit = 50000; volatile static uint16 vSource = 0; volatile static int iSource = 0; +volatile static int pSource = 0; volatile static uint32 dt = 0; volatile static int vMin = DEFAULT_V_MIN; volatile static uint32 maHours; @@ -104,7 +111,11 @@ int main(void) ConversionClock_Start(); LCD_Start(); LCD_DisplayOn(); - LCD_PrintString("Hello, world"); + + LCD_Position(0, 0); + LCD_PrintString(" "); + LCD_Position(1, 0); + LCD_PrintString(" "); /* DMA Configuration for SourceDMA */ SourceDMA_Chan = SourceDMA_DmaInitialize(SourceDMA_BYTES_PER_BURST, SourceDMA_REQUEST_PER_BURST, @@ -265,7 +276,7 @@ int main(void) vAve = vAve/40; vSource = 10*Source_ADC_CountsTo_mVolts((uint16)(vAve)); // 10*vAve/40 - if (systemTimer - 20 > SlowTick) + if (systemTimer - 200 > SlowTick) { SlowTick = systemTimer; cls(); @@ -278,23 +289,44 @@ int main(void) goToPos(1, 4); putString("V Min:"); goToPos(1, 5); + putString("P Source (W):"); + goToPos(1, 6); + putString("P Limit (W):"); + goToPos(1,7); putString("mA Hours:"); - goToPos(12, 1); + goToPos(15, 1); if (iSource < 0) iSource *= -1; sprintf(buff, "%6.3f", iSource / 1000.0f); putString(buff); - goToPos(12, 2); + goToPos(15, 2); sprintf(buff, "%6.3f", iLimit / 1000.0f); putString(buff); - goToPos(12, 3); + goToPos(15, 3); sprintf(buff, "%6.3f", (float)vSource / 1000.0f); putString(buff); - goToPos(12, 4); + goToPos(15, 4); sprintf(buff, "%6.3f", vMin / 1000.0f); putString(buff); - goToPos(12, 5); + goToPos(15, 5); + sprintf(buff, "%6.2f", (float)pSource / 1000.0f); + putString(buff); + goToPos(15, 6); + sprintf(buff, "%6.2f", (float)pLimit / 1000.0f); + putString(buff); + goToPos(15, 7); sprintf(buff, "%6.2f", maHours / 3600.0f); putString(buff); + + goToPos(1,9); + putString("I - Set Current Limit"); + goToPos(1,10); + putString("V - Set Minimum Voltage Limit"); + goToPos(1,11); + putString("E(1/0) - Enable/Disable Load"); + goToPos(1,12); + putString("R - Reset mA Hours Counter"); + goToPos(1,13); + putString("P - Set Power Limit"); sprintf(buff, "I: %.2f V: %.2f", iLimit / 1000.0f, vSource / 1000.0f); LCD_Position(0, 0); @@ -322,6 +354,11 @@ int main(void) case 'R': maHours = 0; break; + case 'P': + if (fiLimit > 50.00 || + fiLimit < 0.0) fiLimit = 0.0; + pLimit = 1000.0*fiLimit; + break; case 'B': Bootloadable_Load(); CySoftwareReset(); @@ -362,11 +399,29 @@ void DoPid() iSource = I_Source_ADC_CountsTo_mVolts(iSourceRaw); - error = iLimit - iSource; - integral = integral + error; - setPoint = (KPN * iLimit) / KPD + (KIN * integral) / KID + 2000; // Use feed forward plus integral - if (setPoint < 0) - setPoint = 0; + //calculate the drawn power + pSource = ((int64)iSource * (int64)vSource) / 1000; + + //if pLimit is reduced from maximum, calculate error based on this number + + if(pLimit < 50000) + { + error = pLimit - pSource; + integral = integral + error; + setPoint = (KPN_P * error) / KPD_P + (KIN_P * integral) / KID_P; + setPoint+=2000; + if (setPoint < 0) + setPoint = 0; + } + else + { + error = iLimit - iSource; + integral = integral + error; + setPoint = (KPN * error) / KPD + (KIN * integral) / KID; + setPoint+=2000; + if (setPoint < 0) + setPoint = 0; + } // setPoint is a voltage. We need to convert that // into an integer that can be fed into our DACs. @@ -384,11 +439,12 @@ void DoPid() fineSetPoint = 255; // Finally, one last check: if the source voltage is below vMin, - // or the total power is greater than 15W, + // or the total power is greater than 50W, // disable. + //DISABLED over-power limit! if ((vSource < vMin) || - (vSource * iLimit > 15000000)) - OutputEnable(false); + (pSource > 50000)) + OutputEnable(false); if (enableOutput == false) { @@ -399,7 +455,7 @@ void DoPid() } else { - if (loopCount++ == 100) + if (loopCount++ == 1000) { maHours += iSource; loopCount = 0;