]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/commitdiff
RoCoN: enhance stepper and BLDC motor support to allow build for calibration.
authorPavel Pisa <ppisa@pikron.com>
Sun, 1 Jun 2014 12:19:41 +0000 (14:19 +0200)
committerPavel Pisa <ppisa@pikron.com>
Sun, 1 Jun 2014 12:19:41 +0000 (14:19 +0200)
Signed-off-by: Pavel Pisa <ppisa@pikron.com>
sw/app/rocon/appl_pxmc.c

index d9a8408c4a8f01260ede0b842516eccc2d112bd8..31de21e60223df14915c9eaa355eaf796b54f41d 100644 (file)
@@ -305,6 +305,8 @@ pxmc_rocon_process_hal_error(struct pxmc_state *mcs)
 int
 pxmc_rocon_pwm3ph_out(pxmc_state_t *mcs)
 {
+  typeof(mcs->pxms_ptvang) ptvang;
+  int sync_mode = 0;
   unsigned char hal_pos;
   short pwm1;
   short pwm2;
@@ -322,6 +324,7 @@ pxmc_rocon_pwm3ph_out(pxmc_state_t *mcs)
 
    #if 0
     pxmc_irc_16bit_commindx(mcs, mcs->pxms_rp >> PXMC_SUBDIV(mcs));
+    sync_mode = 1;
    #elif 1
     {
       int res;
@@ -398,11 +401,13 @@ pxmc_rocon_pwm3ph_out(pxmc_state_t *mcs)
     /* pxmc_set_errno(mcs, PXMS_E_WINDCURRENT); */
   }
 
- #if 1
-  ene = mcs->pxms_ene;
- #else
-  ene = mcs->pxms_flg & PXMS_BSY_m? mcs->pxms_me: 0;
- #endif
+  if (!sync_mode) {
+    ptvang = mcs->pxms_ptvang;
+    ene = mcs->pxms_ene;
+  } else {
+    ptvang = 0;
+    ene = mcs->pxms_flg & PXMS_BSY_m? mcs->pxms_me: 0;
+  }
 
   if (ene) {
     indx = mcs->pxms_ptindx;
@@ -416,13 +421,13 @@ pxmc_rocon_pwm3ph_out(pxmc_state_t *mcs)
       /* Generating direction of stator mag. field for backward torque */
       ene = -ene;
 
-      if ((indx -= mcs->pxms_ptvang) < 0)
+      if ((indx -= ptvang) < 0)
         indx += mcs->pxms_ptirc;
     }
     else
     {
       /* Generating direction of stator mag. field for forward torque */
-      if ((indx += mcs->pxms_ptvang) >= mcs->pxms_ptirc)
+      if ((indx += ptvang) >= mcs->pxms_ptirc)
         indx -= mcs->pxms_ptirc;
     }
 
@@ -508,6 +513,8 @@ pxmc_rocon_pwm2ph_wr(pxmc_state_t *mcs, short pwm1, short pwm2)
 int
 pxmc_rocon_pwm2ph_out(pxmc_state_t *mcs)
 {
+  typeof(mcs->pxms_ptvang) ptvang;
+  int sync_mode = 0;
   short pwm1;
   short pwm2;
   int indx = 0;
@@ -519,7 +526,21 @@ pxmc_rocon_pwm2ph_out(pxmc_state_t *mcs)
     short ptindx;
     short ptirc=mcs->pxms_ptirc;
 
-    pxmc_irc_16bit_commindx(mcs,mcs->pxms_rp>>PXMC_SUBDIV(mcs));
+   #if 0
+    pxmc_irc_16bit_commindx(mcs, mcs->pxms_rp >> PXMC_SUBDIV(mcs));
+    sync_mode = 1;
+   #elif 1
+    {
+      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) {
+        pxmc_set_flag(mcs, PXMS_PTI_b);
+        pxmc_set_flag(mcs, PXMS_PHA_b);
+      }
+    }
+   #else
 
     ptindx = mcs->pxms_ptindx;
 
@@ -540,6 +561,7 @@ pxmc_rocon_pwm2ph_out(pxmc_state_t *mcs)
       if(!(mcs->pxms_flg&PXMS_PTI_m))
             mcs->pxms_ptindx = ptindx;
     }
+   #endif
   }
 
   {
@@ -548,26 +570,28 @@ pxmc_rocon_pwm2ph_out(pxmc_state_t *mcs)
     /* pxmc_set_errno(mcs, PXMS_E_WINDCURRENT); */
   }
 
- #if 1
-  ene = mcs->pxms_ene;
- #else
-  ene = mcs->pxms_flg & PXMS_BSY_m? mcs->pxms_me: 0;
- #endif
+  if (!sync_mode) {
+    ptvang = mcs->pxms_ptvang;
+    ene = mcs->pxms_ene;
+  } else {
+    ptvang = 0;
+    ene = mcs->pxms_flg & PXMS_BSY_m? mcs->pxms_me: 0;
+  }
 
   if (ene) {
     indx = mcs->pxms_ptindx;
-   #if 1
+   #if 0
     /* tuning of magnetic field/voltage advance angle */
     indx += (mcs->pxms_s1 * mcs->pxms_as) >> (PXMC_SUBDIV(mcs) + 8);
    #endif
     if (ene<0){
       /* Generating direction of stator mag. field for backward torque */
       ene = -ene;
-      if ((indx -= mcs->pxms_ptvang)<0)
+      if ((indx -= ptvang)<0)
         indx += mcs->pxms_ptirc;
     }else{
       /* Generating direction of stator mag. field for forward torque */
-      if ((indx += mcs->pxms_ptvang) >= mcs->pxms_ptirc)
+      if ((indx += ptvang) >= mcs->pxms_ptirc)
         indx -= mcs->pxms_ptirc;
     }