rainbow

Dependencies:   mbed FastPWM

Files at this revision

API Documentation at this revision

Comitter:
Lightvalve
Date:
Tue Apr 05 09:07:14 2022 +0000
Parent:
240:fb5b57e3f157
Child:
242:b235d67d25ba
Commit message:
220405

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
setting.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Apr 05 05:12:12 2022 +0000
+++ b/main.cpp	Tue Apr 05 09:07:14 2022 +0000
@@ -322,10 +322,10 @@
 //        timer_while ++;
 
         //i2c for SW valve
-        if(OPERATING_MODE == 5) {
-            read_field(i2c_slave_addr1);
-            if(DIR_VALVE_ENC < 0) value = 1023 - value;
-        }
+//        if(OPERATING_MODE == 5) {
+//            read_field(i2c_slave_addr1);
+//            if(DIR_VALVE_ENC < 0) value = 1023 - value;
+//        }
     }
 }
 
@@ -498,7 +498,7 @@
         LVDT_H = 1;
         LVDT_L = 0;
 
-        for (int ij = 0; ij<400; ij++) {
+        for (int ij = 0; ij<200; ij++) {
 //            LED = 1;
             ADC1->CR2  |= 0x40000000;
             LVDT_new = ((float)ADC1->DR) - 2047.5f;
@@ -510,11 +510,11 @@
         LVDT_L = 0;
 
 //        LED = 0;
-        LVDT_new = LVDT_sum * 0.0025f;
+        LVDT_new = LVDT_sum * 0.005f;
 
-        float alpha_LVDT = 1.0f;//1.0f/(1.0f+TMR_FREQ_1k/(2.0f*PI*300.0f));
+        float alpha_LVDT = 1.0f/(1.0f+TMR_FREQ_1k/(2.0f*PI*300.0f));
         LVDT_LPF = (1.0f-alpha_LVDT) * LVDT_LPF + alpha_LVDT * LVDT_new;
-        force.sen = LVDT_LPF;
+        valve_pos.sen = LVDT_LPF;
 
     }
     TIM3->SR = 0x0;  // reset the status register
@@ -591,8 +591,8 @@
 {
     if (TIM2->SR & TIM_SR_UIF ) {
 
-        if (LED > 0) LED = 0;
-        else LED = 1;
+//        if (LED > 0) LED = 0;
+//        else LED = 1;
 
         if(MODE_POS_FT_TRANS == 1) {
             if (alpha_trans == 1.0f) MODE_POS_FT_TRANS = 2;
@@ -1529,20 +1529,21 @@
         //////////////////////  Data transmission through CAN //////////////////////
         ////////////////////////////////////////////////////////////////////////////
 
-        if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) {
+        if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) {  
+        
 
             // Position, Velocity, and Torque (ID:1200)
-            if (flag_data_request[0] == HIGH) {
+//            if (flag_data_request[0] == LOW) {
 
-                if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator
-                    CAN_TX_POSITION_FT((int16_t) (pos.sen*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (torq.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f));
+//                if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator
+//                    CAN_TX_POSITION_FT((int16_t) (pos.sen*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (torq.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f));
 //                    CAN_TX_POSITION_FT((int16_t) (PRES_B_VREF*10.0f*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (pres_B.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f));
 
-                } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator
-                    CAN_TX_POSITION_FT((int16_t) (pos.sen*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (force.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f));
-//                    CAN_TX_POSITION_FT((int16_t) (force.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f), (int16_t) (vel.sen*20.0f), (int16_t) (((float)ADC1->DR)));
-                }
-            }
+//                } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator
+//                    CAN_TX_POSITION_FT((int16_t) (pos.sen*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (force.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f));
+                    CAN_TX_POSITION_FT((int16_t) (7.0f*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (valve_pos.sen));
+//                }
+//            }
 
             // Valve Position (ID:1300)
             if (flag_data_request[1] == HIGH) {
--- a/setting.h	Tue Apr 05 05:12:12 2022 +0000
+++ b/setting.h	Tue Apr 05 09:07:14 2022 +0000
@@ -29,6 +29,7 @@
 
 //#define             TMR_FREQ_10k       10000
 #define             TMR_FREQ_5k         5000
+#define             TMR_FREQ_1k         1000
 
 extern DigitalOut check;
 extern DigitalOut check_2;