power board firmware for dyno

Dependencies:   mbed

Revision:
1:6b03278584b2
Parent:
0:f4f2a7b3364c
--- a/main.cpp	Mon Jun 21 19:50:05 2021 +0000
+++ b/main.cpp	Mon Jun 21 19:56:09 2021 +0000
@@ -14,38 +14,30 @@
 Serial       pc(PA_2, PA_3);
 
 //setup scaling
-float HV_CURRENT_SCALING = 0.0400; //V/A
-float LV_CURRENT_SCALING = 0.0550; //V/A
-float VOL_SENSE_SCALING = (1000000.0+30000.0)/30000.0; //V per Volt
-float SYSTEM_VOLTAGE = 3.3; //volts
-float VCC = 5.0; //volts
-float EXT_CURRENT_SCALING = 0.008; //Sensitivity = 8mv/A external sensor
+float TORQUE_SCALING = 0.0550; //V/A
 
 //setup analog inputs
 AnalogIn hv_current(PC_0);
-AnalogIn lv_current(PC_1);
-AnalogIn voltage_sense(PC_2);
-AnalogIn ext_current_A(PC_3); //V_OUT (for now)
-AnalogIn ext_current_B(PC_4); //V_REF (for now)
+
 //setup CAN
 CAN          can(PA_11, PA_12, 1000000);  // CAN Rx pin name, CAN Tx pin name
-CANMessage   currMsg, statMsg;
+CANMessage   tauMsg;
 int                     ledState;
 Ticker                  sendCAN;
 int                     counter = 0;
 volatile bool           msgAvailable = false;
 Ticker loop;
 
-void pack_cmd(CANMessage * msg, float f1, float f2){
+void pack_cmd(CANMessage * msg, float f1){
      /// convert floats to unsigned ints ///
      uint16_t f1_int = float_to_uint(f1, MIN, MAX, 16);            
-     uint16_t f2_int = float_to_uint(f2, MIN, MAX, 16);
+     //uint16_t f2_int = float_to_uint(f2, MIN, MAX, 16);
      /// pack ints into the can buffer ///
      msg->data[0] = f1_int>>8;                                       
      msg->data[1] = f1_int&0xFF;
+     /*
      msg->data[2] = f2_int>>8;
      msg->data[3] = f2_int&0xFF;
-     /*
      msg->data[4] = 0x00;
      msg->data[5] = 0x00;
      msg->data[6] = 0x00;
@@ -58,14 +50,11 @@
     wait(1);
     pc.baud(115200);
     wait(.01);
-    pc.printf("\n\r\n\r Biomimetics Power Board\n\r\n\r");
+    pc.printf("\n\r\n\r Biomimetics Torque Sense Board\n\r\n\r");
     wait(.01);
     
-    currMsg.len = 4;                        //transmit 4 bytes
-    statMsg.len = 4;                        //transmit 4 bytes
-    
-    currMsg.id = 0x1;                       //higher priority                
-    statMsg.id = 0x2;                       //lower
+    tauMsg.len = 2;                        //transmit 4 bytes
+    tauMsg.id = 0x2;                       //higher priority                
     
     while(1){
         //wait(1); //GET RID OF THIS WAIT LATER
@@ -79,10 +68,8 @@
         float ext_cur = (V_OUT_EXT*SYSTEM_VOLTAGE-V_REF_EXT*SYSTEM_VOLTAGE) / EXT_CURRENT_SCALING;                            //PUBLISH
         
         //now we have to publish the four floats to the CAN BUS
-        pack_cmd(&currMsg, hv_cur, ext_cur);
-        pack_cmd(&statMsg, vol, lv_cur);
-        can.write(currMsg);
+        pack_cmd(&tauMsg, hv_cur);
+        can.write(tauMsg);
         wait(.00002);
-        can.write(statMsg); 
     }
 }