From: Pavel Pisa Date: Sun, 14 Dec 2014 12:28:38 +0000 (+0100) Subject: TUMBL interface: Combine D and Q PWM components into single variable. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/fpga/lx-cpu1/lx-rocon.git/commitdiff_plain/545733c11c1ed8a55b9521b74e63aec784b49eca TUMBL interface: Combine D and Q PWM components into single variable. 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 --- diff --git a/hw/lx-rocon_firmware/firmware.c b/hw/lx-rocon_firmware/firmware.c index 22d4ca5..678c8e3 100644 --- a/hw/lx-rocon_firmware/firmware.c +++ b/hw/lx-rocon_firmware/firmware.c @@ -32,10 +32,8 @@ 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); diff --git a/sw/app/rocon/appl_tests.c b/sw/app/rocon/appl_tests.c index 0e932e3..cf3a5f3 100644 --- a/sw/app/rocon/appl_tests.c +++ b/sw/app/rocon/appl_tests.c @@ -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;