From f8c0bc5de5211c44f8a9c97ef9dfbdf99644be5d Mon Sep 17 00:00:00 2001 From: Martin Prudek Date: Wed, 15 Apr 2015 21:04:19 +0200 Subject: [PATCH] Current measurment bits transferring via SPI from FPGA to RPi extended from 12 to 24 bits. This is preparation for transferring sum of currents. --- pmsm-control/rpi_pmsm_control.vhdl | 15 ++++++++----- pmsm-control/test_sw/rp_spi.c | 35 +++++++++++++++++++++++------- pmsm-control/test_sw/rp_spi.h | 2 +- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/pmsm-control/rpi_pmsm_control.vhdl b/pmsm-control/rpi_pmsm_control.vhdl index 9e60675..104d272 100644 --- a/pmsm-control/rpi_pmsm_control.vhdl +++ b/pmsm-control/rpi_pmsm_control.vhdl @@ -232,7 +232,7 @@ begin match => pwm_match(i), count => pwm_count, -- outputs - out_p => pwm(i), --positive signal + out_p => open,--pwm(i), --positive signal out_n => shdn(i) --reverse signal is in shutdown mode ); end generate; @@ -347,10 +347,15 @@ begin 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) <= pwm_match(1)(10 downto 5); --6 MSb of PWM1 - dat_reg(80 downto 74) <= pwm_match(2)(10 downto 4); --7 MSb of PWM2 - dat_reg(73 downto 68) <= pwm_match(3)(10 downto 5); --6 MSb of PWM3 - dat_reg(67 downto 32) <= adc_channels(35 downto 0); --current mesurments + dat_reg(86 downto 81) <= (others=>'0');--pwm_match(1)(10 downto 5); --6 MSb of PWM1 + dat_reg(80 downto 74) <= (others=>'0');--pwm_match(2)(10 downto 4); --7 MSb of PWM2 + dat_reg(73 downto 68) <= (others=>'0');--pwm_match(3)(10 downto 5); --6 MSb of PWM3 + dat_reg(71 downto 60)<=(others=>'0'); + dat_reg(59 downto 48) <= adc_channels(35 downto 24); --current mesurments + dat_reg(47 downto 36)<=(others=>'0'); + dat_reg(35 downto 24) <= adc_channels(23 downto 12); --current mesurments + dat_reg(23 downto 12)<=(others=>'0'); + dat_reg(11 downto 0) <= adc_channels(11 downto 0); --current mesurments adc_reset<='0'; --remove reset flag, and wait on its rising edge elsif (ce0_old = "01") then --rising edge of SS, we should read the data adc_reset<='1'; diff --git a/pmsm-control/test_sw/rp_spi.c b/pmsm-control/test_sw/rp_spi.c index 57a2122..98d4eca 100644 --- a/pmsm-control/test_sw/rp_spi.c +++ b/pmsm-control/test_sw/rp_spi.c @@ -97,7 +97,7 @@ struct rpi_in spi_read(uint8_t * tx) /*/ /*prichozi data: - * rx[0] - bity 127 downto 120 + * rx[0] - bity 127 downto 120 the first income bit..127 * rx[1] - bity 119 downto 112 * rx[2] - bity 111 downto 104 * rx[3] - bity 103 downto 96 @@ -112,7 +112,7 @@ struct rpi_in spi_read(uint8_t * tx) * rx[12] - bity 31 downto 24 * rx[13] - bity 23 downto 16 * rx[14] - bity 15 downto 8 - * rx[15] - bity 7 downto 0 + * rx[15] - bity 7 downto 0 the last income bit..0 */ /*uprava endianity pozice*/ @@ -174,19 +174,38 @@ struct rpi_in spi_read(uint8_t * tx) in.b37=!!(0x20 & rx[7]); in.b36=!!(0x10 & rx[7]); + /** currents + * ch0 - bits 71 downto 48 + * 71..64 in rx[7] - all byte + * 63..56 in rx[8] - all byte + * 55..48 in rx[9] - all byte + * ch1 - bits 47 downto 24 + * 47..40 in rx[10] - all byte + * 39..32 in rx[11] - all byte + * 31..24 in rx[12] - all byte + * ch2 - bits 23 downto 0 + * 23..16 in rx[13] - all byte + * 15..8 in rx[14] - all byte + * 7..0 in rx[15] - all byte + */ - in.ch0=0x0F & rx[7]; + in.ch0=rx[7]; in.ch0<<=8; in.ch0|=rx[8]; + in.ch0<<=8; + in.ch0|=rx[9]; - in.ch1= rx[9]; + in.ch1=rx[10]; in.ch1<<=8; - in.ch1|=(rx[10] & 0xF0); - in.ch1>>=4; + in.ch1|=rx[11]; + in.ch1<<=8; + in.ch1|=rx[12]; - in.ch2=(0xF & rx[10]); + in.ch2=rx[13]; + in.ch2<<=8; + in.ch2|=rx[14]; in.ch2<<=8; - in.ch2|=rx[11]; + in.ch2|=rx[15]; return in; diff --git a/pmsm-control/test_sw/rp_spi.h b/pmsm-control/test_sw/rp_spi.h index a5cc719..999d7b3 100644 --- a/pmsm-control/test_sw/rp_spi.h +++ b/pmsm-control/test_sw/rp_spi.h @@ -9,7 +9,7 @@ */ struct rpi_in{ uint64_t pozice; /*use twice the origin size to avoid underflow when sunstracting offset*/ - uint16_t ch0, ch1, ch2; + 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 ! */ int8_t shdn1,shdn2,shdn3; /*(bool)last read shutdown values - !they are changed after reading ! */ -- 2.39.2