From: Martin Prudek Date: Thu, 16 Apr 2015 17:25:43 +0000 (+0200) Subject: Added reading of irc_index position. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/fpga/rpi-motor-control.git/commitdiff_plain/c4cdcbe5bfaecb9024e4fe41be29a4541653b8ef Added reading of irc_index position. --- diff --git a/pmsm-control/rpi_pmsm_control.vhdl b/pmsm-control/rpi_pmsm_control.vhdl index 52e362f..45ea914 100644 --- a/pmsm-control/rpi_pmsm_control.vhdl +++ b/pmsm-control/rpi_pmsm_control.vhdl @@ -165,6 +165,7 @@ architecture behavioral of rpi_mc_simple_dc is signal gpio_clk: std_logic; signal dat_reg : STD_LOGIC_VECTOR (127 downto 0); --shift register for spi signal position: std_logic_vector(31 downto 0); --pozice z qcounteru + signal index_position: std_logic_vector(11 downto 0); --pozice irc_i signal ce0_old: std_logic_vector(1 downto 0); --pwm signals @@ -300,6 +301,11 @@ begin pwm(3) <= pwm_sig(3) and dip_sw(3); + process + begin + wait until (irc_i'event and irc_i='1'); + index_position(11 downto 0)<=position(11 downto 0); + end process; process begin @@ -345,9 +351,7 @@ begin income_data_valid<='0'; dat_reg(127 downto 96) <= position(31 downto 0); --pozice dat_reg(95 downto 93) <= hal_in(1 to 3); --halovy sondy - dat_reg(92 downto 90) <= pwm_en_p(1 to 3); --enable positive - dat_reg(89 downto 87) <= pwm_en_n(1 to 3); --shutdown - dat_reg(86 downto 81) <= (others=>'0');--pwm_match(1)(10 downto 5); --6 MSb of PWM1 + dat_reg(92 downto 81) <= index_position(11 downto 0); --position of irc_i dat_reg(80 downto 72) <=adc_m_count(8 downto 0); --count of measurments --data order schould be: ch2 downto ch0 downto ch1 dat_reg(71 downto 0) <= adc_channels(71 downto 0); --current mesurments diff --git a/pmsm-control/test_sw/main_pmsm.c b/pmsm-control/test_sw/main_pmsm.c index 6219d69..7d707da 100644 --- a/pmsm-control/test_sw/main_pmsm.c +++ b/pmsm-control/test_sw/main_pmsm.c @@ -67,6 +67,7 @@ void sighnd_fnc(){ } void substractOffset(struct rpi_in* data, struct rpi_in* offset){ + data->pozice_raw=data->pozice; data->pozice-=offset->pozice; return; } @@ -100,6 +101,9 @@ void printData(struct rpi_in data){ } puts(""); printf("\npozice=%d\n",(int32_t)data.pozice); + printf("raw_pozice=%d\n",(int32_t)data.pozice_raw); + printf("raw_pozice last11=%u\n",(data.pozice_raw&0x7FF)); + printf("index position=%d\n",(int16_t)data.index_position); printf("hal1=%d, hal2=%d, hal3=%d\n",data.hal1,data.hal2,data.hal3); printf("en1=%d, en2=%d, en3=%d (Last sent)\n",!!(0x40&test),!!(0x20&test),!!(0x10&test)); printf("shdn1=%d, shdn2=%d, shdn3=%d (L.s.)\n",!!(0x08&test),!!(0x04&test),!!(0x02&test)); diff --git a/pmsm-control/test_sw/rp_spi.c b/pmsm-control/test_sw/rp_spi.c index 056cb5d..bbe8225 100644 --- a/pmsm-control/test_sw/rp_spi.c +++ b/pmsm-control/test_sw/rp_spi.c @@ -120,7 +120,6 @@ struct rpi_in spi_read(uint8_t * tx) uint8_p[1]=rx[2]; uint8_p[2]=rx[1]; uint8_p[3]=rx[0]; /*MSB*/ /*with sign bit*/ - uint8_p[4]=uint8_p[5]=uint8_p[6]=uint8_p[7]=0; /*halove sondy * hal1 - bit95 @@ -131,23 +130,15 @@ struct rpi_in spi_read(uint8_t * tx) in.hal2=!!(0x40 & rx[4]); in.hal3=!!(0x20 & rx[4]); - /*pwm enable - * en1 - bit92 - * en2 - bit91 - * en2 - bit90 + /* index position + * bits 92 downto 81 + * 92..88 in rx[4] last 5 bits (from left) + * 87..81 in rx[5] first 7 bits (from left) */ - in.en1=!!(0x10 & rx[4]); - in.en2=!!(0x08 & rx[4]); - in.en3=!!(0x04 & rx[4]); - - /*shutdown - * shdn1 - bit89 - * shdn2 - bit88 - * shdn3 - bit87 - */ - in.shdn1=!!(0x02 & rx[4]); - in.shdn2=!!(0x01 & rx[4]); - in.shdn3=!!(0x80 & rx[5]); + in.index_position=0x1F & rx[4]; + in.index_position<<=8; + in.index_position|=0xFE & rx[5]; + in.index_position>>=1; /* current measurments count * bits 80 downto 72 diff --git a/pmsm-control/test_sw/rp_spi.h b/pmsm-control/test_sw/rp_spi.h index 7d2dd7f..d286fa2 100644 --- a/pmsm-control/test_sw/rp_spi.h +++ b/pmsm-control/test_sw/rp_spi.h @@ -8,7 +8,8 @@ * \brief Struktura pro prichozi data z fpga. */ struct rpi_in{ - uint64_t pozice; /*use twice the origin size to avoid underflow when sunstracting offset*/ + uint32_t pozice; /*continue with normal size and test it..*/ + uint32_t pozice_raw; /*with offset*/ uint32_t ch0, ch1, ch2; int8_t hal1,hal2,hal3; /* bool values */ int8_t en1, en2, en3; /*(bool)last read pwm-enable values - !they are changed after reading ! */ @@ -16,6 +17,7 @@ struct rpi_in{ int8_t b54, b53, b52, b51, b50, b49, b48, b47, b46, b45, b44, b43, b42, b41, b40, b39, b38, b37, b36; /*bits for debug*/ uint16_t adc_m_count; /*current measurments count*/ uint8_t debug_rx[16]; + uint16_t index_position; /* raw position of irc_i */ }; /**