Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Revision:
6:39442d493098
Parent:
5:09be5bbb5020
Child:
8:d3d7dca419b3
--- a/src/boards.cpp	Sat Dec 01 00:08:53 2018 +0000
+++ b/src/boards.cpp	Mon Dec 03 01:03:14 2018 +0000
@@ -37,53 +37,73 @@
 
 unsigned int boardEnableBits;
 
-
+/*******************************************************************************
+delay
+*******************************************************************************/
 void delay(long ticks)
 {
    long i;
    for(i=0;i<ticks;i++);    
 }  
 
-void setBoardEnables(unsigned int enableBits[])
+/*******************************************************************************
+setBoardEnables
+*******************************************************************************/
+//void setBoardEnables(unsigned int enableBits[])
+unsigned int setBoardEnables(unsigned int tCode)
 {
-   unsigned int i, boardEnable;
-
+   unsigned int i = 0;
+   unsigned int boardTcode = 0;
    // Default is all boards OFF
-   unsigned int boardsEnabled = ALLOFF;
-
-   for (i = 0; i < MAX_BOARDS; i++)
-   {
+   //unsigned int boardTcode = ALLOFF;
+   
+   dec2therm_fix(tCode, (unsigned int)BOARDS_THERMCODE_WIDTH);
+   
+   for (i = 0; i < MAX_BOARDS; i++){
       // 0 == enabled
-      boardEnable = (enableBits[i] & (1 << i));
-      
+      boardTcode = (thermCode[i] & (1 << i));
    }
-      
-   wr_out = boardEnable;
-   
+    
+   //wr_out = boardTcode;
+   wr_out = tCode;
+   //return boardTcode;
+   return tCode;
 }
 
-void setBoardWeights(unsigned int enableWeights[])
+/*******************************************************************************
+setBoardWeights
+*******************************************************************************/
+//void setBoardWeights(unsigned int enableWeights[])
+unsigned int setBoardWeights(unsigned int bCode)
 {
-   unsigned int i, boardWeight;
+   unsigned int i = 0;
+   unsigned int boardBcode = 0;
+   
+   dec2bin_fix(bCode, WEIGHT_BIN_WIDTH);
 
-   for (i = 0; i < MAX_BOARDS; i++)
-   {
+   for (i = 0; i <= WEIGHT_BIN_WIDTH; i++){
       // 0 == enabled
-      boardWeight = (enableWeights[i] & (1 << i));
-      
+      boardBcode = (binCode[i] & (1 << i));
    }
-      
-   en_out = boardWeight;
+   //en_out = boardBcode;
+   en_out = bCode;
    toggleLatchSignal();
-   
+   //return boardBcode;
+   return bCode;
 }
 
+/*******************************************************************************
+toggleLatchSignal
+*******************************************************************************/
 void toggleLatchSignal(void){
     extchlat = OFF;
     extchlat = ON;
     extchlat = OFF;
 }
- 
+
+/*******************************************************************************
+initDACs
+*******************************************************************************/
 void initDACs(void)
 {
    //setupDacInit();
@@ -104,70 +124,73 @@
 **************************************************************/
 int checkRange(int setvalue, int limlo, int limhi)
 {
-
-   if ((setvalue >= limlo) && (setvalue <= limhi))
-   {
+   if ((setvalue >= limlo) && (setvalue <= limhi)){
       return 1;
-   }
-   else
-   {
+   }else{
       showRangeError(0, 0, setvalue);
       return 0;
    }
-
 }
 
-// start the converter
+/*******************************************************************************
+startConverter
+*******************************************************************************/
 // RK: ch[i][reg].enabled has not been used correctly yet. Need to modify that code.
 void startConverter(unsigned int reg)
 {
-   
-   int i;
+   //unsigned int i;
    //float period;
-
    running = TRUE;
 
-   unsigned int boardsEnabled = 0;
-   
-   char stemp[50];
+   //unsigned int boardsEnabled = 0;
+   //char stemp[50];
    
-   for (i = 0; i < MAX_BOARDS; i++)
-   {
-      //if (ch[i][reg].enabled == 1)
-      //{
-          // Set the corresponding bit
-          boardsEnabled |= (1 << i);
-
-          sprintf(stemp, "\n\rBoard %d RUNNING", i + 1);
-          sendSerial(stemp);
-      //}
-   }
-   
+   //for (i = 0; i < MAX_BOARDS; i++){
+   //   //if (ch[i][reg].enabled == 1)
+   //   //{
+   //       // Set the corresponding bit
+   //       boardsEnabled |= (1 << i);
+   //
+   //       sprintf(stemp, "\n\rBoard %d RUNNING", i + 1);
+   //       sendSerial(stemp);
+   //   //}
+   //}
    // Invert the bits because 0 == enabled on the SPI write
    //boardsEnabled = ~boardsEnabled;
    
    // Fire in the hole!
-   setBoardEnables(thermCode);
+   wr_out_code = setBoardEnables(reg);
+   
+   sprintf(strbuf, "\r\nConverter started");
+   sendSerial(strbuf);
 
    //setupRunVoltages();
-      
    //currentRegister = reg;
-
    //pulser.attach_us(&pulserInt, period);    
 }   
 
-// stop the converter and set outputs to 0
+/*******************************************************************************
+stopConverter - stop the converter and set outputs to 0
+*******************************************************************************/
 void stopConverter(void)
 {
    //pulser.detach();
-   setBoardEnables(ALLOFF);
+   wr_out_code = setBoardEnables(ALLOFF);
+   //setBoardEnables((unsigned int *)alloff);
    running = FALSE;
-
+   sprintf(strbuf, "\r\nConverter stopped");
+   sendSerial(strbuf);
 }
 
-void updateControls(int my12){
+/*******************************************************************************
+updateControls
+*******************************************************************************/
+void updateControls(unsigned short ref){
     //getLUTcode(i12);
-    getLUTcode(my12);
-    setBoardEnables(thermCode);
-    setBoardWeights(binCode);
+    //getLUTcode(my12);
+    unsigned int cBuf = getLUT_thermCode(ref);
+    wr_out_code = setBoardEnables(cBuf);
+    
+    cBuf = getLUT_binCode(ref);
+    en_out_code = setBoardWeights(cBuf);
 }
\ No newline at end of file