]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/commitdiff
Extend PXMCC control and support routines to enable/disable ptofs automatic update.
authorPavel Pisa <ppisa@pikron.com>
Tue, 6 Jan 2015 11:13:21 +0000 (12:13 +0100)
committerPavel Pisa <ppisa@pikron.com>
Tue, 6 Jan 2015 11:13:21 +0000 (12:13 +0100)
Signed-off-by: Pavel Pisa <ppisa@pikron.com>
hw/lx-rocon_firmware/firmware.c
sw/app/rocon/appl_pxmc.c
sw/app/rocon/pxmcc_interface.h

index 0d8bfec9fa562d8e16609968bdebf4e30b70507b..8a21bbcb3a63b1b06a07189ab7a36d2f6cb216ce 100644 (file)
@@ -121,7 +121,13 @@ void main(void)
       irc = *(FPGA_IRC0 + (FPGA_IRC1 - FPGA_IRC0) * pxmcc->inp_info);
 
       pti = irc - ofs;
-      if ((uint32_t)pti >= per) {
+      /*
+       * the '>=' is appropriate to keep pti in <0;per-1> range,
+       * but sine and cosine computations can work over multiple
+       * periods and value of per=0xffffffff allows to control/stop
+       * updates if only '>' is used.
+       */
+      if ((uint32_t)pti > per) {
         if (pti < 0) {
           ofs -= per;
         } else {
index f49f5e1c4049449cc921074c9d4bac2bd699b06c..6954b0b39a1eaa7f9f300ee371061e249b79dd01 100644 (file)
@@ -716,7 +716,7 @@ pxmc_rocon_pwm_dc_out(pxmc_state_t *mcs)
 /*******************************************************************/
 /* PXMCC - PXMC coprocessor support and communication */
 
-void pxmcc_pxmc_ptofs2mcc(pxmc_state_t *mcs)
+void pxmcc_pxmc_ptofs2mcc(pxmc_state_t *mcs, int enable_update)
 {
   volatile pxmcc_axis_data_t *mcc_axis = pxmc_rocon_mcs2pxmcc(mcs);
   int inp_chan=mcs->pxms_inp_info;
@@ -724,10 +724,15 @@ void pxmcc_pxmc_ptofs2mcc(pxmc_state_t *mcs)
   uint32_t irc;
 
   if (mcc_axis != NULL) {
+    if (enable_update >= 0)
+      mcc_axis->ptirc = 0xffffffff;
     ptofs = mcs->pxms_ptofs - pxmc_rocon_irc_offset[inp_chan];
     irc = fpga_irc[inp_chan]->count;
     ptofs = (int16_t)(ptofs - irc) + irc;
     mcc_axis->ptofs = ptofs;
+    if (enable_update > 0) {
+      mcc_axis->ptirc = mcs->pxms_ptirc;
+    }
   }
 }
 
@@ -754,6 +759,7 @@ pxmc_pxmcc_pwm3ph_out(pxmc_state_t *mcs)
 
       if (!(mcs->pxms_flg & PXMS_PTI_m) || (mcs->pxms_flg & PXMS_PRA_m)) {
         int set_ptofs_fl = 0;
+        int ptofs_enable_update = 0;
 
         if (((hal_pos != mcs->pxms_hal) && (mcs->pxms_hal != 0x40)) && 1) {
           short ptindx_prev = (mcs->pxms_hal * ptirc + divisor / 2) / divisor;;
@@ -769,6 +775,7 @@ pxmc_pxmcc_pwm3ph_out(pxmc_state_t *mcs)
           }
 
           set_ptofs_fl = 1;
+          ptofs_enable_update = 1;
 
           pxmc_set_flag(mcs, PXMS_PTI_b);
           pxmc_clear_flag(mcs, PXMS_PRA_b);
@@ -780,7 +787,7 @@ pxmc_pxmcc_pwm3ph_out(pxmc_state_t *mcs)
           mcs->pxms_ptindx = ptindx;
           mcs->pxms_ptofs = (mcs->pxms_ap >> PXMC_SUBDIV(mcs)) + mcs->pxms_ptshift - ptindx;
 
-          pxmcc_pxmc_ptofs2mcc(mcs);
+          pxmcc_pxmc_ptofs2mcc(mcs, ptofs_enable_update);
         }
       } else {
         /* if phase table position to mask is know do fine phase table alignment */
@@ -791,7 +798,7 @@ pxmc_pxmcc_pwm3ph_out(pxmc_state_t *mcs)
           if (res < 0) {
             pxmc_set_errno(mcs, PXMS_E_I2PT_TOOBIG);
           } else if (res) {
-            pxmcc_pxmc_ptofs2mcc(mcs);
+            pxmcc_pxmc_ptofs2mcc(mcs, 1);
             pxmc_set_flag(mcs, PXMS_PTI_b);
             pxmc_set_flag(mcs, PXMS_PHA_b);
           }
@@ -826,6 +833,25 @@ pxmc_pxmcc_pwm3ph_out(pxmc_state_t *mcs)
 int
 pxmc_pxmcc_pwm2ph_out(pxmc_state_t *mcs)
 {
+  if(!(mcs->pxms_flg&PXMS_PTI_m) || !(mcs->pxms_flg&PXMS_PHA_m) ||
+     (mcs->pxms_flg&PXMS_PRA_m)) {
+
+    {
+      /* Wait for index mark to align phases */
+      int res;
+      res = pxmc_inp_rocon_ptofs_from_index_poll(mcs, 0);
+      if (res < 0) {
+        pxmc_set_errno(mcs, PXMS_E_I2PT_TOOBIG);
+      } else if (res) {
+        pxmcc_pxmc_ptofs2mcc(mcs, 1);
+        pxmc_set_flag(mcs, PXMS_PTI_b);
+        pxmc_set_flag(mcs, PXMS_PHA_b);
+      } else {
+        pxmcc_pxmc_ptofs2mcc(mcs, 0);
+      }
+    }
+  }
+
   {
     int ene, pwm_d, pwm_q;
 
@@ -858,6 +884,9 @@ int pxmcc_axis_setup(pxmc_state_t *mcs, int mode)
   if (mcc_axis == NULL)
     return -1;
 
+  if (mcc_data->common.fwversion != PXMCC_FWVERSION)
+    return -1;
+
   mcc_axis->ccflg = 0;
   mcc_axis->mode = PXMCC_MODE_IDLE;
 
@@ -867,10 +896,9 @@ int pxmcc_axis_setup(pxmc_state_t *mcs, int mode)
   ull = (1ULL << 32) * mcs->pxms_ptper;
   ptreci = (ull + ptirc / 2) / ptirc;
 
-  mcc_axis->ptirc = ptirc;
   mcc_axis->ptreci = ptreci;
 
-  pxmcc_pxmc_ptofs2mcc(mcs);
+  pxmcc_pxmc_ptofs2mcc(mcs, 0);
 
   switch (mode) {
     case PXMCC_MODE_IDLE:
@@ -913,6 +941,8 @@ int pxmcc_axis_setup(pxmc_state_t *mcs, int mode)
   mcc_axis->ccflg = 0;
   mcc_axis->pwm_dq = 0;
 
+  pxmcc_pxmc_ptofs2mcc(mcs, 1);
+
   return 0;
 }
 
@@ -1808,6 +1838,8 @@ int pxmc_axis_rdmode(pxmc_state_t *mcs)
     return PXMC_AXIS_MODE_BLDC;
   if (mcs->pxms_do_out == pxmc_pxmcc_pwm3ph_out)
     return PXMC_AXIS_MODE_BLDC_PXMCC;
+  if (mcs->pxms_do_out == pxmc_pxmcc_pwm2ph_out)
+    return PXMC_AXIS_MODE_STEPPER_WITH_IRC_PXMCC;
   return -1;
 }
 
index e55ade48e61d2eb556b4be966c30ee0f76d45a65..2ffeccf016d81125debd34bda6883ee89a6c6aa9 100644 (file)
@@ -52,7 +52,7 @@ void pxmcc_axis_enable(pxmc_state_t *mcs, int enable)
   mcc_axis->ccflg = enable? 1: 0;
 }
 
-void pxmcc_pxmc_ptofs2mcc(pxmc_state_t *mcs);
+void pxmcc_pxmc_ptofs2mcc(pxmc_state_t *mcs, int enable_update);
 
 int pxmcc_axis_setup(pxmc_state_t *mcs, int mode);