]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/commitdiff
TUMBL interface: Combine D and Q PWM components into single variable.
authorPavel Pisa <ppisa@pikron.com>
Sun, 14 Dec 2014 12:28:38 +0000 (13:28 +0100)
committerPavel Pisa <ppisa@pikron.com>
Sun, 14 Dec 2014 12:28:38 +0000 (13:28 +0100)
This ensures that both components are changed by single write
command. This ensures data consistency even when PWM is
written asynchronously by LPC.

Signed-off-by: Pavel Pisa <ppisa@pikron.com>
hw/lx-rocon_firmware/firmware.c
sw/app/rocon/appl_tests.c

index 22d4ca50181a645cd66d97c8419ac4994c14abd5..678c8e3ad46a707af391f238f96eab215cbcf238 100644 (file)
 
 typedef struct pxmcc_axis_data_t {
   uint32_t  ccflg;
-  int32_t   pwm_d;
-  int32_t   pwm_q;
-  int32_t   cur_d;
-  int32_t   cur_q;
+  uint32_t  pwm_dq;    /* D and Q components of PWM (pwm_d << 16) | (pwm_q) & 0xffff */
+  uint32_t  cur_dq;    /* D and Q components current (cur_d << 16) | (cur_q) & 0xffff */
   uint32_t  ptindx;    /* index into phase table / irc in the cycle */
   uint32_t  ptirc;     /* IRC count per phase table */
   uint32_t  ptreci;    /* Reciprocal value of ptirc * 63356  */
@@ -101,8 +99,7 @@ void main(void)
   pxmcc->ptirc = 1000;
   pxmcc->ptreci = 4294967; /* (1LL<<32)*ptper/ptirc */
   pxmcc->min_idle = 0;
-  pxmcc->pwm_d = 0;
-  pxmcc->pwm_q = 0;
+  pxmcc->pwm_dq = 0;
 
   asm volatile("": : : "memory");
 
@@ -148,12 +145,18 @@ void main(void)
       uint32_t pwm1;
       uint32_t pwm2;
       uint32_t pwm3;
-     #if defined(COMPUTE_PHASE_SECTOR) || !defined(SUPPRESS_CONDITIONALS)
+      int32_t pwm_d;
+      int32_t pwm_q;
+    #if defined(COMPUTE_PHASE_SECTOR) || !defined(SUPPRESS_CONDITIONALS)
       uint32_t phs;
      #endif /*COMPUTE_PHASE_SECTOR*/
 
-      pwm_alp = pxmcc->pwm_d * pxmcc->ptcos - pxmcc->pwm_q * pxmcc->ptsin;
-      pwm_bet = pxmcc->pwm_d * pxmcc->ptsin + pxmcc->pwm_q * pxmcc->ptcos;
+      pwm_d = (volatile uint32_t)pxmcc->pwm_dq;
+      pwm_q = (pwm_d << 16) >> 16;
+      pwm_d >>= 16;
+
+      pwm_alp = pwm_d * pxmcc->ptcos - pwm_q * pxmcc->ptsin;
+      pwm_bet = pwm_d * pxmcc->ptsin + pwm_q * pxmcc->ptcos;
 
       pwm_bet_div_2_k3 = RECI16_2_K3 * (pwm_bet >> 16);
 
index 0e932e362c525a1403773a915ca73a8b541a2db7..cf3a5f3582ab221dc4113025241491f3f7351114 100644 (file)
@@ -409,12 +409,11 @@ int cmd_do_testtumblefw(cmd_io_t *cmd_io, const struct cmd_des *des, char *param
   ptreci = (ull + ptirc / 2) / ptirc;
 
   fpga_tumbl_dmem[0] = 0;
-  fpga_tumbl_dmem[1] = pwm_d;
-  fpga_tumbl_dmem[2] = pwm_q;
+  fpga_tumbl_dmem[1] = (pwm_d << 16) | (pwm_q & 0xffff);
 
-  fpga_tumbl_dmem[6] = ptirc;
-  fpga_tumbl_dmem[7] = ptreci;
-  fpga_tumbl_dmem[8] = ptofs;
+  fpga_tumbl_dmem[4] = ptirc;
+  fpga_tumbl_dmem[5] = ptreci;
+  fpga_tumbl_dmem[6] = ptofs;
 
   fpga_tumbl_dmem[0] = 1;