FPGARelated.com
Forums

problem while receiving negative integer in microblaze

Started by GrIsH October 11, 2009
I got the problem while receiving the value of "count" (i.e. of
integer type with value positive as well as negative) in MICROBLAZE
that was send from custom IP  named as encoder module using "User
Logic Software Register"  IPIF. Encoder module counts the value of
encoder pulses ranges from -5000 to +5000.

I assigned value of   "count"  to  IP2Bus_Data by converting it to
std_logic_vector type and receive this value in microblaze software
application using variable "Data_receive" of int type. and
"Data_received" was displayed into Hyper Terminal But data received
was not as expecting mainly the negative numbers.....so how this
problem is resolved to get exact data, positive as well as negative.

Can i receive the data in Microblaze application in std_logic_vector
form?? i mean std_logic_vector equivalent form....

OR is there any easier method of transferring negative data ...??

Another problem is...... i found SIGNED(N downto 0) is same as
std_logic_vector except it represents +ve as well as -ve
numbers....But it didn't work in my program...why??

my code written in "user_logic".vhd template is given below.....
------------------------------------------------------------------------------------------------------------------------------
signal cnt:					integer range -5000 to 5000:=0;

 my_uut1:process(channel_A) is
    begin
        if(channel_A 'event and channel_A='1') then
            direction<= '1' and channel_B;
        end if;
    end process;

    my_uut2:process(channel_A) is
    begin
        if(channel_A 'event and channel_A='1') then
            if(direction='0') then
                cnt<=cnt+1;
            else
                cnt<=cnt-1;
            end if;
        end if;
    end process;

IP2Bus_Data(0 to 15)  <= (others=>'0');
IP2Bus_Data(16 to 31) <= conv_std_logic_vector(cnt,16);
-----------------------------------------------------------------------------------------------------------------------------
SOFTWARE APPLICATION IN MICROBLAZE

Xint DataRead;

encoder_module_p = (Xuint32 *)XPAR_ENCODER_MODULE_0_BASEADDR;
XASSERT_NONVOID(encoder_module_p != XNULL);
encoder_module = (Xuint32 *)encoder_module_p;



	while(1){

		DataRead = ENCODER_MODULE_mReadSlaveReg0(encoder_module, 0);
		xil_printf("Received data: %d\r\n", DataRead);

	}
----------------------------------------------------------------------------------------------------------------------------------------

any suggestion is greatly appreciated!!
On Oct 11, 9:05=A0am, GrIsH <grishkun...@gmail.com> wrote:
> I got the problem while receiving the value of "count" (i.e. of > integer type with value positive as well as negative) in MICROBLAZE > that was send from custom IP =A0named as encoder module using "User > Logic Software Register" =A0IPIF. Encoder module counts the value of > encoder pulses ranges from -5000 to +5000. > > I assigned value of =A0 "count" =A0to =A0IP2Bus_Data by converting it to > std_logic_vector type and receive this value in microblaze software > application using variable "Data_receive" of int type. and > "Data_received" was displayed into Hyper Terminal But data received > was not as expecting mainly the negative numbers.....so how this > problem is resolved to get exact data, positive as well as negative. > > Can i receive the data in Microblaze application in std_logic_vector > form?? i mean std_logic_vector equivalent form.... > > OR is there any easier method of transferring negative data ...?? > > Another problem is...... i found SIGNED(N downto 0) is same as > std_logic_vector except it represents +ve as well as -ve > numbers....But it didn't work in my program...why?? > > my code written in "user_logic".vhd template is given below..... > -------------------------------------------------------------------------=
-----------------------------------------------------
> signal cnt: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 integer range -5000 to 5000:=3D0;
> > =A0my_uut1:process(channel_A) is > =A0 =A0 begin > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > =A0 =A0 =A0 =A0 =A0 =A0 direction<=3D '1' and channel_B; > =A0 =A0 =A0 =A0 end if; > =A0 =A0 end process; > > =A0 =A0 my_uut2:process(channel_A) is > =A0 =A0 begin > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > =A0 =A0 =A0 =A0 =A0 =A0 if(direction=3D'0') then > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt+1; > =A0 =A0 =A0 =A0 =A0 =A0 else > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt-1; > =A0 =A0 =A0 =A0 =A0 =A0 end if; > =A0 =A0 =A0 =A0 end if; > =A0 =A0 end process; > > IP2Bus_Data(0 to 15) =A0<=3D (others=3D>'0'); > IP2Bus_Data(16 to 31) <=3D conv_std_logic_vector(cnt,16); > -------------------------------------------------------------------------=
----------------------------------------------------
> SOFTWARE APPLICATION IN MICROBLAZE > > Xint DataRead; > > encoder_module_p =3D (Xuint32 *)XPAR_ENCODER_MODULE_0_BASEADDR; > XASSERT_NONVOID(encoder_module_p !=3D XNULL); > encoder_module =3D (Xuint32 *)encoder_module_p; > > =A0 =A0 =A0 =A0 while(1){ > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DataRead =3D ENCODER_MODULE_mReadSlaveReg=
0(encoder_module, 0);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 xil_printf("Received data: %d\r\n", DataR=
ead);
> > =A0 =A0 =A0 =A0 }
You only included part of your code, I don't see your library declarations and the other signal declarations. I guess IP2Bus_Data is an output maybe? Your problem likely is in the numbering of your bus. How was it declared, 31 downto 0 (the most common convention) or 0 to 31 (not so common)? You are assigning the msb of the integer to bit 16 of your SLV which is in the middle of the vector. I can see why uBlaze is confused. I also recommend that you not use std_logic_arith. This has been covered many, many times here and elsewhere. There are some sticky issues with using this package. It is highly recommended to use ieee.std_logic_1164 and ieee.numeric_std. I won't go into the details of why this is better, but if you continue to use std_logic_arith don't say you weren't warned. Rick
On Oct 12, 9:02=A0am, rickman <gnu...@gmail.com> wrote:
> On Oct 11, 9:05=A0am, GrIsH <grishkun...@gmail.com> wrote: > > > > > I got the problem while receiving the value of "count" (i.e. of > > integer type with value positive as well as negative) in MICROBLAZE > > that was send from custom IP =A0named as encoder module using "User > > Logic Software Register" =A0IPIF. Encoder module counts the value of > > encoder pulses ranges from -5000 to +5000. > > > I assigned value of =A0 "count" =A0to =A0IP2Bus_Data by converting it t=
o
> > std_logic_vector type and receive this value in microblaze software > > application using variable "Data_receive" of int type. and > > "Data_received" was displayed into Hyper Terminal But data received > > was not as expecting mainly the negative numbers.....so how this > > problem is resolved to get exact data, positive as well as negative. > > > Can i receive the data in Microblaze application in std_logic_vector > > form?? i mean std_logic_vector equivalent form.... > > > OR is there any easier method of transferring negative data ...?? > > > Another problem is...... i found SIGNED(N downto 0) is same as > > std_logic_vector except it represents +ve as well as -ve > > numbers....But it didn't work in my program...why?? > > > my code written in "user_logic".vhd template is given below..... > > -----------------------------------------------------------------------=
-------------------------------------------------------
> > signal cnt: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 integer range -5000 to 5000:=3D0;
> > > =A0my_uut1:process(channel_A) is > > =A0 =A0 begin > > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > > =A0 =A0 =A0 =A0 =A0 =A0 direction<=3D '1' and channel_B; > > =A0 =A0 =A0 =A0 end if; > > =A0 =A0 end process; > > > =A0 =A0 my_uut2:process(channel_A) is > > =A0 =A0 begin > > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > > =A0 =A0 =A0 =A0 =A0 =A0 if(direction=3D'0') then > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt+1; > > =A0 =A0 =A0 =A0 =A0 =A0 else > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt-1; > > =A0 =A0 =A0 =A0 =A0 =A0 end if; > > =A0 =A0 =A0 =A0 end if; > > =A0 =A0 end process; > > > IP2Bus_Data(0 to 15) =A0<=3D (others=3D>'0'); > > IP2Bus_Data(16 to 31) <=3D conv_std_logic_vector(cnt,16); > > -----------------------------------------------------------------------=
------------------------------------------------------
> > SOFTWARE APPLICATION IN MICROBLAZE > > > Xint DataRead; > > > encoder_module_p =3D (Xuint32 *)XPAR_ENCODER_MODULE_0_BASEADDR; > > XASSERT_NONVOID(encoder_module_p !=3D XNULL); > > encoder_module =3D (Xuint32 *)encoder_module_p; > > > =A0 =A0 =A0 =A0 while(1){ > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DataRead =3D ENCODER_MODULE_mReadSlaveR=
eg0(encoder_module, 0);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 xil_printf("Received data: %d\r\n", Dat=
aRead);
> > > =A0 =A0 =A0 =A0 } > > You only included part of your code, I don't see your library > declarations and the other signal declarations. =A0I guess IP2Bus_Data > is an output maybe? > > Your problem likely is in the numbering of your bus. =A0How was it > declared, 31 downto 0 (the most common convention) or 0 to 31 (not so > common)? =A0You are assigning the msb of the integer to bit 16 of your > SLV which is in the middle of the vector. =A0I can see why uBlaze is > confused. > > I also recommend that you not use std_logic_arith. =A0This has been > covered many, many times here and elsewhere. =A0There are some sticky > issues with using this package. =A0It is highly recommended to use > ieee.std_logic_1164 and ieee.numeric_std. =A0I won't go into the details > of why this is better, but if you continue to use std_logic_arith > don't say you weren't warned. > > Rick
Here is my complete code: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library proc_common_v2_00_a; use proc_common_v2_00_a.proc_common_pkg.all; -- DO NOT EDIT ABOVE THIS LINE -------------------- --USER libraries added here ---------------------------------------------------------------------------= --- -- Entity section ---------------------------------------------------------------------------= --- -- Definition of Generics: -- C_SLV_DWIDTH -- Slave interface data bus width -- C_NUM_REG -- Number of software accessible registers -- -- Definition of Ports: -- Bus2IP_Clk -- Bus to IP clock -- Bus2IP_Reset -- Bus to IP reset -- Bus2IP_Data -- Bus to IP data bus -- Bus2IP_BE -- Bus to IP byte enables -- Bus2IP_RdCE -- Bus to IP read chip enable -- Bus2IP_WrCE -- Bus to IP write chip enable -- IP2Bus_Data -- IP to Bus data bus -- IP2Bus_RdAck -- IP to Bus read transfer acknowledgement -- IP2Bus_WrAck -- IP to Bus write transfer acknowledgement -- IP2Bus_Error -- IP to Bus error response ---------------------------------------------------------------------------= --- entity user_logic is generic ( -- ADD USER GENERICS BELOW THIS LINE --------------- --USER generics added here -- ADD USER GENERICS ABOVE THIS LINE --------------- -- DO NOT EDIT BELOW THIS LINE --------------------- -- Bus protocol parameters, do not add to or delete C_SLV_DWIDTH : integer :=3D 32; C_NUM_REG : integer :=3D 1 -- DO NOT EDIT ABOVE THIS LINE --------------------- ); port ( -- ADD USER PORTS BELOW THIS LINE ------------------ channel_A: in std_logic; channel_B: in std_logic; -- ADD USER PORTS ABOVE THIS LINE ------------------ -- DO NOT EDIT BELOW THIS LINE --------------------- -- Bus protocol ports, do not add to or delete Bus2IP_Clk : in std_logic; Bus2IP_Reset : in std_logic; Bus2IP_Data : in std_logic_vector(0 to C_SLV_DWIDTH-1); Bus2IP_BE : in std_logic_vector(0 to C_SLV_DWIDTH/8-1); Bus2IP_RdCE : in std_logic_vector(0 to C_NUM_REG-1); Bus2IP_WrCE : in std_logic_vector(0 to C_NUM_REG-1); IP2Bus_Data : out std_logic_vector(0 to C_SLV_DWIDTH-1); IP2Bus_RdAck : out std_logic; IP2Bus_WrAck : out std_logic; IP2Bus_Error : out std_logic -- DO NOT EDIT ABOVE THIS LINE --------------------- ); attribute SIGIS : string; attribute SIGIS of Bus2IP_Clk : signal is "CLK"; attribute SIGIS of Bus2IP_Reset : signal is "RST"; end entity user_logic; ---------------------------------------------------------------------------= --- -- Architecture section ---------------------------------------------------------------------------= --- architecture IMP of user_logic is --USER signal declarations added here, as needed for user logic ------------------------------------------ -- Signals for user logic slave model s/w accessible register example ------------------------------------------ signal slv_reg0 : std_logic_vector(0 to C_SLV_DWIDTH-1); signal slv_reg_write_sel : std_logic_vector(0 to 0); signal slv_reg_read_sel : std_logic_vector(0 to 0); signal slv_ip2bus_data : std_logic_vector(0 to C_SLV_DWIDTH-1); signal slv_read_ack : std_logic; signal slv_write_ack : std_logic; signal cnt: integer range -1000 to 1000:=3D0; signal direction: std_logic; begin --USER logic implementation added here ------------------------------------------ -- Example code to read/write user logic slave model s/w accessible registers -- -- Note: -- The example code presented here is to show you one way of reading/ writing -- software accessible registers implemented in the user logic slave model. -- Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond -- to one software accessible register by the top level template. For example, -- if you have four 32 bit software accessible registers in the user logic, -- you are basically operating on the following memory mapped registers: -- -- Bus2IP_WrCE/Bus2IP_RdCE Memory Mapped Register -- "1000" C_BASEADDR + 0x0 -- "0100" C_BASEADDR + 0x4 -- "0010" C_BASEADDR + 0x8 -- "0001" C_BASEADDR + 0xC -- ------------------------------------------ slv_reg_write_sel <=3D Bus2IP_WrCE(0 to 0); slv_reg_read_sel <=3D Bus2IP_RdCE(0 to 0); slv_write_ack <=3D Bus2IP_WrCE(0); slv_read_ack <=3D Bus2IP_RdCE(0); -- Encoder Module Code ----------------------------------------------- =20 ---------------------------------------------------------------------- my_uut1:process(channel_A) is begin if(channel_A 'event and channel_A=3D'1') then direction<=3D '1' and channel_B; end if; end process; my_uut2:process(channel_A) is begin if(channel_A 'event and channel_A=3D'1') then if(direction=3D'0') then cnt<=3Dcnt+1; else cnt<=3Dcnt-1; end if; end if; end process; =20 ---------------------------------------------------------------------- =20 ---------------------------------------------------------------------- -- implement slave model software accessible register(s) SLAVE_REG_WRITE_PROC : process( Bus2IP_Clk ) is begin if Bus2IP_Clk'event and Bus2IP_Clk =3D '1' then if Bus2IP_Reset =3D '1' then slv_reg0 <=3D (others =3D> '0'); else case slv_reg_write_sel is when "1" =3D> for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop if ( Bus2IP_BE(byte_index) =3D '1' ) then slv_reg0(byte_index*8 to byte_index*8+7) <=3D Bus2IP_Data (byte_index*8 to byte_index*8+7); end if; end loop; when others =3D> null; end case; end if; end if; end process SLAVE_REG_WRITE_PROC; -- implement slave model software accessible register(s) read mux SLAVE_REG_READ_PROC : process( slv_reg_read_sel, slv_reg0 ) is begin case slv_reg_read_sel is when "1" =3D> slv_ip2bus_data <=3D slv_reg0; when others =3D> slv_ip2bus_data <=3D (others =3D> '0'); end case; end process SLAVE_REG_READ_PROC; ------------------------------------------ -- Example code to drive IP to Bus signals ------------------------------------------ --IP2Bus_Data <=3D slv_ip2bus_data when slv_read_ack =3D '1' else --(others =3D> '0'); -- my logic-------------------------------------------------------- =20 ------------------------------------------------------------------- IP2Bus_Data(0 to 15) <=3D (others=3D>'0'); IP2Bus_Data(16 to 31) <=3D conv_std_logic_vector(cnt,16); ------------------------------------------------------------------- ------------------------------------------------------------------- IP2Bus_WrAck <=3D slv_write_ack; IP2Bus_RdAck <=3D slv_read_ack; IP2Bus_Error <=3D '0'; end IMP;
On Oct 12, 1:08 pm, GrIsH <grishkun...@gmail.com> wrote:
> On Oct 12, 9:02 am, rickman <gnu...@gmail.com> wrote: > > > On Oct 11, 9:05 am, GrIsH <grishkun...@gmail.com> wrote: > > > > I got the problem while receiving the value of "count" (i.e. of > > > integer type with value positive as well as negative) in MICROBLAZE > > > that was send from custom IP named as encoder module using "User > > > Logic Software Register" IPIF. Encoder module counts the value of > > > encoder pulses ranges from -5000 to +5000. > > > > I assigned value of "count" to IP2Bus_Data by converting it to > > > std_logic_vector type and receive this value in microblaze software > > > application using variable "Data_receive" of int type. and > > > "Data_received" was displayed into Hyper Terminal But data received > > > was not as expecting mainly the negative numbers.....so how this > > > problem is resolved to get exact data, positive as well as negative. > > > > Can i receive the data in Microblaze application in std_logic_vector > > > form?? i mean std_logic_vector equivalent form.... > > > > OR is there any easier method of transferring negative data ...?? > > > > Another problem is...... i found SIGNED(N downto 0) is same as > > > std_logic_vector except it represents +ve as well as -ve > > > numbers....But it didn't work in my program...why?? > > > > my code written in "user_logic".vhd template is given below..... > > > ------------------------------------------------------------------------------------------------------------------------------ > > > signal cnt: integer range -5000 to 5000:=0; > > > > my_uut1:process(channel_A) is > > > begin > > > if(channel_A 'event and channel_A='1') then > > > direction<= '1' and channel_B; > > > end if; > > > end process; > > > > my_uut2:process(channel_A) is > > > begin > > > if(channel_A 'event and channel_A='1') then > > > if(direction='0') then > > > cnt<=cnt+1; > > > else > > > cnt<=cnt-1; > > > end if; > > > end if; > > > end process; > > > > IP2Bus_Data(0 to 15) <= (others=>'0'); > > > IP2Bus_Data(16 to 31) <= conv_std_logic_vector(cnt,16); > > > ----------------------------------------------------------------------------------------------------------------------------- > > > SOFTWARE APPLICATION IN MICROBLAZE > > > > Xint DataRead; > > > > encoder_module_p = (Xuint32 *)XPAR_ENCODER_MODULE_0_BASEADDR; > > > XASSERT_NONVOID(encoder_module_p != XNULL); > > > encoder_module = (Xuint32 *)encoder_module_p; > > > > while(1){ > > > > DataRead = ENCODER_MODULE_mReadSlaveReg0(encoder_module, 0); > > > xil_printf("Received data: %d\r\n", DataRead); > > > > } > > > You only included part of your code, I don't see your library > > declarations and the other signal declarations. I guess IP2Bus_Data > > is an output maybe? > > > Your problem likely is in the numbering of your bus. How was it > > declared, 31 downto 0 (the most common convention) or 0 to 31 (not so > > common)? You are assigning the msb of the integer to bit 16 of your > > SLV which is in the middle of the vector. I can see why uBlaze is > > confused. > > > I also recommend that you not use std_logic_arith. This has been > > covered many, many times here and elsewhere. There are some sticky > > issues with using this package. It is highly recommended to use > > ieee.std_logic_1164 and ieee.numeric_std. I won't go into the details > > of why this is better, but if you continue to use std_logic_arith > > don't say you weren't warned. > > > Rick > > Here is my complete code: > > library ieee; > use ieee.std_logic_1164.all; > use ieee.std_logic_arith.all; > use ieee.std_logic_unsigned.all; > > library proc_common_v2_00_a; > use proc_common_v2_00_a.proc_common_pkg.all; > > -- DO NOT EDIT ABOVE THIS LINE -------------------- > > --USER libraries added here > > ------------------------------------------------------------------------------ > -- Entity section > ------------------------------------------------------------------------------ > -- Definition of Generics: > -- C_SLV_DWIDTH -- Slave interface data bus width > -- C_NUM_REG -- Number of software accessible > registers > -- > -- Definition of Ports: > -- Bus2IP_Clk -- Bus to IP clock > -- Bus2IP_Reset -- Bus to IP reset > -- Bus2IP_Data -- Bus to IP data bus > -- Bus2IP_BE -- Bus to IP byte enables > -- Bus2IP_RdCE -- Bus to IP read chip enable > -- Bus2IP_WrCE -- Bus to IP write chip enable > -- IP2Bus_Data -- IP to Bus data bus > -- IP2Bus_RdAck -- IP to Bus read transfer > acknowledgement > -- IP2Bus_WrAck -- IP to Bus write transfer > acknowledgement > -- IP2Bus_Error -- IP to Bus error response > ------------------------------------------------------------------------------ > > entity user_logic is > generic > ( > -- ADD USER GENERICS BELOW THIS LINE --------------- > --USER generics added here > -- ADD USER GENERICS ABOVE THIS LINE --------------- > > -- DO NOT EDIT BELOW THIS LINE --------------------- > -- Bus protocol parameters, do not add to or delete > C_SLV_DWIDTH : integer := 32; > C_NUM_REG : integer := 1 > -- DO NOT EDIT ABOVE THIS LINE --------------------- > ); > port > ( > -- ADD USER PORTS BELOW THIS LINE ------------------ > channel_A: in std_logic; > channel_B: in std_logic; > -- ADD USER PORTS ABOVE THIS LINE ------------------ > > -- DO NOT EDIT BELOW THIS LINE --------------------- > -- Bus protocol ports, do not add to or delete > Bus2IP_Clk : in std_logic; > Bus2IP_Reset : in std_logic; > Bus2IP_Data : in std_logic_vector(0 to > C_SLV_DWIDTH-1); > Bus2IP_BE : in std_logic_vector(0 to > C_SLV_DWIDTH/8-1); > Bus2IP_RdCE : in std_logic_vector(0 to > C_NUM_REG-1); > Bus2IP_WrCE : in std_logic_vector(0 to > C_NUM_REG-1); > IP2Bus_Data : out std_logic_vector(0 to > C_SLV_DWIDTH-1); > IP2Bus_RdAck : out std_logic; > IP2Bus_WrAck : out std_logic; > IP2Bus_Error : out std_logic > -- DO NOT EDIT ABOVE THIS LINE --------------------- > ); > > attribute SIGIS : string; > attribute SIGIS of Bus2IP_Clk : signal is "CLK"; > attribute SIGIS of Bus2IP_Reset : signal is "RST"; > > end entity user_logic; > > ------------------------------------------------------------------------------ > -- Architecture section > ------------------------------------------------------------------------------ > > architecture IMP of user_logic is > > --USER signal declarations added here, as needed for user logic > > ------------------------------------------ > -- Signals for user logic slave model s/w accessible register > example > ------------------------------------------ > signal slv_reg0 : std_logic_vector(0 to > C_SLV_DWIDTH-1); > signal slv_reg_write_sel : std_logic_vector(0 to 0); > signal slv_reg_read_sel : std_logic_vector(0 to 0); > signal slv_ip2bus_data : std_logic_vector(0 to > C_SLV_DWIDTH-1); > signal slv_read_ack : std_logic; > signal slv_write_ack : std_logic; > > signal cnt: integer range -1000 to 1000:=0; > signal direction: std_logic; > > begin > > --USER logic implementation added here > > ------------------------------------------ > -- Example code to read/write user logic slave model s/w accessible > registers > -- > -- Note: > -- The example code presented here is to show you one way of reading/ > writing > -- software accessible registers implemented in the user logic slave > model. > -- Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to > correspond > -- to one software accessible register by the top level template. > For example, > -- if you have four 32 bit software accessible registers in the user > logic, > -- you are basically operating on the following memory mapped > registers: > -- > -- Bus2IP_WrCE/Bus2IP_RdCE Memory Mapped Register > -- "1000" C_BASEADDR + 0x0 > -- "0100" C_BASEADDR + 0x4 > -- "0010" C_BASEADDR + 0x8 > -- "0001" C_BASEADDR + 0xC > -- > ------------------------------------------ > slv_reg_write_sel <= Bus2IP_WrCE(0 to 0); > slv_reg_read_sel <= Bus2IP_RdCE(0 to 0); > slv_write_ack <= Bus2IP_WrCE(0); > slv_read_ack <= Bus2IP_RdCE(0); > > -- Encoder Module Code > ----------------------------------------------- > > ---------------------------------------------------------------------- > > my_uut1:process(channel_A) is > begin > if(channel_A 'event and channel_A='1') then > direction<= '1' and channel_B; > end if; > end process; > > my_uut2:process(channel_A) is > begin > if(channel_A 'event and channel_A='1') then > if(direction='0') then > cnt<=cnt+1; > else > cnt<=cnt-1; > end if; > end if; > end process; > > ---------------------------------------------------------------------- > > ---------------------------------------------------------------------- > > -- implement slave model software accessible register(s) > SLAVE_REG_WRITE_PROC : process( Bus2IP_Clk ) is > begin > > if Bus2IP_Clk'event and Bus2IP_Clk = '1' then > if Bus2IP_Reset = '1' then > slv_reg0 <= (others => '0'); > else > case slv_reg_write_sel is > when "1" => > for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop > if ( Bus2IP_BE(byte_index) = '1' ) then > slv_reg0(byte_index*8 to byte_index*8+7) <= Bus2IP_Data > (byte_index*8 to byte_index*8+7); > end if; > end loop; > when others => null; > end case; > end if; > end if; > > end process SLAVE_REG_WRITE_PROC; > > -- implement slave model software accessible register(s) read mux > SLAVE_REG_READ_PROC : process( slv_reg_read_sel, slv_reg0 ) is > begin > > case slv_reg_read_sel is > when "1" => slv_ip2bus_data <= slv_reg0; > when others => slv_ip2bus_data <= (others => '0'); > end case; > > end process SLAVE_REG_READ_PROC; > > ------------------------------------------ > -- Example code to drive IP to Bus signals > ------------------------------------------ > --IP2Bus_Data <= slv_ip2bus_data when slv_read_ack = '1' else > --(others => '0'); > > -- my logic-------------------------------------------------------- > > ------------------------------------------------------------------- > IP2Bus_Data(0 to 15) <= (others=>'0'); > IP2Bus_Data(16 to 31) <= conv_std_logic_vector(cnt,16); > ------------------------------------------------------------------- > ------------------------------------------------------------------- > > IP2Bus_WrAck <= slv_write_ack; > IP2Bus_RdAck <= slv_read_ack; > IP2Bus_Error <= '0'; > > end IMP;
It looks like IP2Bus_Data is declared 0 to N rather than N downto 0. This is the signal that goes to the mBlaze, right? How does uBlaze declare this? Have you checked this in simulation? You should be able to see what is happening there. But like I said, I believe you are doing this wrong. You are putting the sign bit in the middle of the 32 bit word. Is that what you intended? Is uBlaze reading just a 16 bit quanity or do you need to sign extend the value? What values *are* being seen in the terminal display? Are they all positive? Do you see *any* negative numbers from this data path? I also suggest strongly that you replace use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; with use ieee.numeric_std.all; The conversion functions have different names, but they are easy to remember. to_integer() works for the types defined in numeric_std (signed and unsigned). to_signed() and to_unsigned() work for integer. To convert between integer and SLV you need to use to_integer, to_signed or to_unsigned to convert between integer and either signed or unsigned, then you can use "implicit type conversion" to convert between signed/unsigned and SLV. e.g. std_logic_vector (signed_signal) under numeric_std signed, unsigned and SLV are "closely related types" which do not need a function for conversion. They will be converted just by connecting the corresponding "wires" (elements of the array) between the two types. Since closely related types use the same element types, this is defined without requiring any "conversion" between them. The reason that you can't convert directly between integer and SLV is because that would require a specification of the format somehow. By converting to unsigned or signed in the middle, the format is specified clearly. Rick
On Oct 12, 1:04=A0pm, rickman <gnu...@gmail.com> wrote:
> On Oct 12, 1:08 pm, GrIsH <grishkun...@gmail.com> wrote: > > > On Oct 12, 9:02 am, rickman <gnu...@gmail.com> wrote: > > > > On Oct 11, 9:05 am, GrIsH <grishkun...@gmail.com> wrote: > > > > > I got the problem while receiving the value of "count" (i.e. of > > > > integer type with value positive as well as negative) in MICROBLAZE > > > > that was send from custom IP =A0named as encoder module using "User > > > > Logic Software Register" =A0IPIF. Encoder module counts the value o=
f
> > > > encoder pulses ranges from -5000 to +5000. > > > > > I assigned value of =A0 "count" =A0to =A0IP2Bus_Data by converting =
it to
> > > > std_logic_vector type and receive this value in microblaze software > > > > application using variable "Data_receive" of int type. and > > > > "Data_received" was displayed into Hyper Terminal But data received > > > > was not as expecting mainly the negative numbers.....so how this > > > > problem is resolved to get exact data, positive as well as negative=
.
> > > > > Can i receive the data in Microblaze application in std_logic_vecto=
r
> > > > form?? i mean std_logic_vector equivalent form.... > > > > > OR is there any easier method of transferring negative data ...?? > > > > > Another problem is...... i found SIGNED(N downto 0) is same as > > > > std_logic_vector except it represents +ve as well as -ve > > > > numbers....But it didn't work in my program...why?? > > > > > my code written in "user_logic".vhd template is given below..... > > > > -------------------------------------------------------------------=
-----------------------------------------------------------
> > > > signal cnt: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 integer range -5000 to 5000:=3D0;
> > > > > =A0my_uut1:process(channel_A) is > > > > =A0 =A0 begin > > > > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > > > > =A0 =A0 =A0 =A0 =A0 =A0 direction<=3D '1' and channel_B; > > > > =A0 =A0 =A0 =A0 end if; > > > > =A0 =A0 end process; > > > > > =A0 =A0 my_uut2:process(channel_A) is > > > > =A0 =A0 begin > > > > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > > > > =A0 =A0 =A0 =A0 =A0 =A0 if(direction=3D'0') then > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt+1; > > > > =A0 =A0 =A0 =A0 =A0 =A0 else > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt-1; > > > > =A0 =A0 =A0 =A0 =A0 =A0 end if; > > > > =A0 =A0 =A0 =A0 end if; > > > > =A0 =A0 end process; > > > > > IP2Bus_Data(0 to 15) =A0<=3D (others=3D>'0'); > > > > IP2Bus_Data(16 to 31) <=3D conv_std_logic_vector(cnt,16); > > > > -------------------------------------------------------------------=
----------------------------------------------------------
> > > > SOFTWARE APPLICATION IN MICROBLAZE > > > > > Xint DataRead; > > > > > encoder_module_p =3D (Xuint32 *)XPAR_ENCODER_MODULE_0_BASEADDR; > > > > XASSERT_NONVOID(encoder_module_p !=3D XNULL); > > > > encoder_module =3D (Xuint32 *)encoder_module_p; > > > > > =A0 =A0 =A0 =A0 while(1){ > > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DataRead =3D ENCODER_MODULE_mReadSl=
aveReg0(encoder_module, 0);
> > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 xil_printf("Received data: %d\r\n",=
DataRead);
> > > > > =A0 =A0 =A0 =A0 } > > > > You only included part of your code, I don't see your library > > > declarations and the other signal declarations. =A0I guess IP2Bus_Dat=
a
> > > is an output maybe? > > > > Your problem likely is in the numbering of your bus. =A0How was it > > > declared, 31 downto 0 (the most common convention) or 0 to 31 (not so > > > common)? =A0You are assigning the msb of the integer to bit 16 of you=
r
> > > SLV which is in the middle of the vector. =A0I can see why uBlaze is > > > confused. > > > > I also recommend that you not use std_logic_arith. =A0This has been > > > covered many, many times here and elsewhere. =A0There are some sticky > > > issues with using this package. =A0It is highly recommended to use > > > ieee.std_logic_1164 and ieee.numeric_std. =A0I won't go into the deta=
ils
> > > of why this is better, but if you continue to use std_logic_arith > > > don't say you weren't warned. > > > > Rick > > > Here is my complete code: > > > library ieee; > > use ieee.std_logic_1164.all; > > use ieee.std_logic_arith.all; > > use ieee.std_logic_unsigned.all; > > > library proc_common_v2_00_a; > > use proc_common_v2_00_a.proc_common_pkg.all; > > > -- DO NOT EDIT ABOVE THIS LINE -------------------- > > > --USER libraries added here > > > -----------------------------------------------------------------------=
-------
> > -- Entity section > > -----------------------------------------------------------------------=
-------
> > -- Definition of Generics: > > -- =A0 C_SLV_DWIDTH =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- Slave interface =
data bus width
> > -- =A0 C_NUM_REG =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- Number of so=
ftware accessible
> > registers > > -- > > -- Definition of Ports: > > -- =A0 Bus2IP_Clk =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- Bus to IP cloc=
k
> > -- =A0 Bus2IP_Reset =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- Bus to IP reset > > -- =A0 Bus2IP_Data =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- Bus to IP data=
bus
> > -- =A0 Bus2IP_BE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- Bus to IP by=
te enables
> > -- =A0 Bus2IP_RdCE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- Bus to IP read=
chip enable
> > -- =A0 Bus2IP_WrCE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- Bus to IP writ=
e chip enable
> > -- =A0 IP2Bus_Data =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- IP to Bus data=
bus
> > -- =A0 IP2Bus_RdAck =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- IP to Bus read t=
ransfer
> > acknowledgement > > -- =A0 IP2Bus_WrAck =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- IP to Bus write =
transfer
> > acknowledgement > > -- =A0 IP2Bus_Error =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- IP to Bus error =
response
> > -----------------------------------------------------------------------=
-------
> > > entity user_logic is > > =A0 generic > > =A0 ( > > =A0 =A0 -- ADD USER GENERICS BELOW THIS LINE --------------- > > =A0 =A0 --USER generics added here > > =A0 =A0 -- ADD USER GENERICS ABOVE THIS LINE --------------- > > > =A0 =A0 -- DO NOT EDIT BELOW THIS LINE --------------------- > > =A0 =A0 -- Bus protocol parameters, do not add to or delete > > =A0 =A0 C_SLV_DWIDTH =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : integer =A0 =
=A0 =A0 =A0 =A0 =A0 =A0:=3D 32;
> > =A0 =A0 C_NUM_REG =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: integer =
=A0 =A0 =A0 =A0 =A0 =A0 =A0:=3D 1
> > =A0 =A0 -- DO NOT EDIT ABOVE THIS LINE --------------------- > > =A0 ); > > =A0 port > > =A0 ( > > =A0 =A0 -- ADD USER PORTS BELOW THIS LINE ------------------ > > =A0 =A0 channel_A: =A0 =A0 =A0 =A0 =A0in std_logic; > > =A0 =A0 =A0 =A0 =A0channel_B: =A0 =A0 =A0 =A0 =A0 =A0 in std_logic; > > =A0 =A0 -- ADD USER PORTS ABOVE THIS LINE ------------------ > > > =A0 =A0 -- DO NOT EDIT BELOW THIS LINE --------------------- > > =A0 =A0 -- Bus protocol ports, do not add to or delete > > =A0 =A0 Bus2IP_Clk =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : in =A0std_=
logic;
> > =A0 =A0 Bus2IP_Reset =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : in =A0std_lo=
gic;
> > =A0 =A0 Bus2IP_Data =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: in =A0std_=
logic_vector(0 to
> > C_SLV_DWIDTH-1); > > =A0 =A0 Bus2IP_BE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: in =A0st=
d_logic_vector(0 to
> > C_SLV_DWIDTH/8-1); > > =A0 =A0 Bus2IP_RdCE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: in =A0std_=
logic_vector(0 to
> > C_NUM_REG-1); > > =A0 =A0 Bus2IP_WrCE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: in =A0std_=
logic_vector(0 to
> > C_NUM_REG-1); > > =A0 =A0 IP2Bus_Data =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: out std_lo=
gic_vector(0 to
> > C_SLV_DWIDTH-1); > > =A0 =A0 IP2Bus_RdAck =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : out std_logi=
c;
> > =A0 =A0 IP2Bus_WrAck =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : out std_logi=
c;
> > =A0 =A0 IP2Bus_Error =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : out std_logi=
c
> > =A0 =A0 -- DO NOT EDIT ABOVE THIS LINE --------------------- > > =A0 ); > > > =A0 attribute SIGIS : string; > > =A0 attribute SIGIS of Bus2IP_Clk =A0 =A0: signal is "CLK"; > > =A0 attribute SIGIS of Bus2IP_Reset =A0: signal is "RST"; > > > end entity user_logic; > > > -----------------------------------------------------------------------=
-------
> > -- Architecture section > > -----------------------------------------------------------------------=
-------
> > > architecture IMP of user_logic is > > > =A0 --USER signal declarations added here, as needed for user logic > > > =A0 ------------------------------------------ > > =A0 -- Signals for user logic slave model s/w accessible register > > example > > =A0 ------------------------------------------ > > =A0 signal slv_reg0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : std_l=
ogic_vector(0 to
> > C_SLV_DWIDTH-1); > > =A0 signal slv_reg_write_sel =A0 =A0 =A0 =A0 =A0 =A0 =A0: std_logic_vec=
tor(0 to 0);
> > =A0 signal slv_reg_read_sel =A0 =A0 =A0 =A0 =A0 =A0 =A0 : std_logic_vec=
tor(0 to 0);
> > =A0 signal slv_ip2bus_data =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: std_logic_v=
ector(0 to
> > C_SLV_DWIDTH-1); > > =A0 signal slv_read_ack =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : std_logic=
;
> > =A0 signal slv_write_ack =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: std_logic=
;
> > > =A0 signal cnt: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 integer range -1000 to 1000:=3D0;
> > =A0 signal direction: =A0 std_logic; > > > begin > > > =A0 --USER logic implementation added here > > > =A0 ------------------------------------------ > > =A0 -- Example code to read/write user logic slave model s/w accessible > > registers > > =A0 -- > > =A0 -- Note: > > =A0 -- The example code presented here is to show you one way of readin=
g/
> > writing > > =A0 -- software accessible registers implemented in the user logic slav=
e
> > model. > > =A0 -- Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to > > correspond > > =A0 -- to one software accessible register by the top level template. > > For example, > > =A0 -- if you have four 32 bit software accessible registers in the use=
r
> > logic, > > =A0 -- you are basically operating on the following memory mapped > > registers: > > =A0 -- > > =A0 -- =A0 =A0Bus2IP_WrCE/Bus2IP_RdCE =A0 Memory Mapped Register > > =A0 -- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "1000" =A0 C_BASEADDR + =
0x0
> > =A0 -- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "0100" =A0 C_BASEADDR + =
0x4
> > =A0 -- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "0010" =A0 C_BASEADDR + =
0x8
> > =A0 -- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "0001" =A0 C_BASEADDR + =
0xC
> > =A0 -- > > =A0 ------------------------------------------ > > =A0 slv_reg_write_sel <=3D Bus2IP_WrCE(0 to 0); > > =A0 slv_reg_read_sel =A0<=3D Bus2IP_RdCE(0 to 0); > > =A0 slv_write_ack =A0 =A0 <=3D Bus2IP_WrCE(0); > > =A0 slv_read_ack =A0 =A0 =A0<=3D Bus2IP_RdCE(0); > > > =A0 -- Encoder Module Code > > ----------------------------------------------- > > > ---------------------------------------------------------------------- > > > =A0 =A0 =A0 =A0 =A0my_uut1:process(channel_A) is > > =A0 =A0 begin > > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > > =A0 =A0 =A0 =A0 =A0 =A0 direction<=3D '1' and channel_B; > > =A0 =A0 =A0 =A0 end if; > > =A0 =A0 end process; > > > =A0 =A0 my_uut2:process(channel_A) is > > =A0 =A0 begin > > =A0 =A0 =A0 =A0 if(channel_A 'event and channel_A=3D'1') then > > =A0 =A0 =A0 =A0 =A0 =A0 if(direction=3D'0') then > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt+1; > > =A0 =A0 =A0 =A0 =A0 =A0 else > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt<=3Dcnt-1; > > =A0 =A0 =A0 =A0 =A0 =A0 end if; > > =A0 =A0 =A0 =A0 end if; > > =A0 =A0 end process; > > > ---------------------------------------------------------------------- > > > ---------------------------------------------------------------------- > > > =A0 -- implement slave model software accessible register(s) > > =A0 SLAVE_REG_WRITE_PROC : process( Bus2IP_Clk ) is > > =A0 begin > > > =A0 =A0 if Bus2IP_Clk'event and Bus2IP_Clk =3D '1' then > > =A0 =A0 =A0 if Bus2IP_Reset =3D '1' then > > =A0 =A0 =A0 =A0 slv_reg0 <=3D (others =3D> '0'); > > =A0 =A0 =A0 else > > =A0 =A0 =A0 =A0 case slv_reg_write_sel is > > =A0 =A0 =A0 =A0 =A0 when "1" =3D> > > =A0 =A0 =A0 =A0 =A0 =A0 for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ( Bus2IP_BE(byte_index) =3D '1' ) then > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 slv_reg0(byte_index*8 to byte_index*8+7=
) <=3D Bus2IP_Data
> > (byte_index*8 to byte_index*8+7); > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 end if; > > =A0 =A0 =A0 =A0 =A0 =A0 end loop; > > =A0 =A0 =A0 =A0 =A0 when others =3D> null; > > =A0 =A0 =A0 =A0 end case; > > =A0 =A0 =A0 end if; > > =A0 =A0 end if; > > > =A0 end process SLAVE_REG_WRITE_PROC; > > > =A0 -- implement slave model software accessible register(s) read mux > > =A0 SLAVE_REG_READ_PROC : process( slv_reg_read_sel, slv_reg0 ) is > > =A0 begin > > > =A0 =A0 case slv_reg_read_sel is > > =A0 =A0 =A0 when "1" =3D> slv_ip2bus_data <=3D slv_reg0; > > =A0 =A0 =A0 when others =3D> slv_ip2bus_data <=3D (others =3D> '0'); > > =A0 =A0 end case; > > > =A0 end process SLAVE_REG_READ_PROC; > > > =A0 ------------------------------------------ > > =A0 -- Example code to drive IP to Bus signals > > =A0 ------------------------------------------ > > =A0 --IP2Bus_Data =A0<=3D slv_ip2bus_data when slv_read_ack =3D '1' els=
e
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 --(others =3D> '0'); > > > =A0 -- my logic-------------------------------------------------------- > > > ------------------------------------------------------------------- > > =A0 IP2Bus_Data(0 to 15) =A0<=3D (others=3D>'0'); > > =A0 IP2Bus_Data(16 to 31) <=3D conv_std_logic_vector(cnt,16); > > =A0 ------------------------------------------------------------------- > > =A0 ------------------------------------------------------------------- > > > =A0 IP2Bus_WrAck <=3D slv_write_ack; > > =A0 IP2Bus_RdAck <=3D slv_read_ack; > > =A0 IP2Bus_Error <=3D '0'; > > > end IMP; > > It looks like IP2Bus_Data is declared 0 to N rather than N downto 0. > This is the signal that goes to the mBlaze, right? =A0How does uBlaze > declare this? =A0Have you checked this in simulation? =A0You should be > able to see what is happening there. =A0 But like I said, I believe you > are doing this wrong. =A0You are putting the sign bit in the middle of > the 32 bit word. =A0Is that what you intended? =A0Is uBlaze reading just =
a
> 16 bit quanity or do you need to sign extend the value?
As you mentioned above, IP2Bus_Data should be declare N downto 0 rather than 0 to N.....I tried this but got the error message IP2Bus_Data type can not be declared as DOWNTO .......i didn't have any simulation for this till now and i just check the received number in hyperterminal..... This time i hav used 32 bit instead of 16 bit format(i.e.IP2Bus_Data(0 to 31)<=3Dconv_std_logic_vector(cnt,32)) .........
> > What values *are* being seen in the terminal display? =A0Are they all > positive? =A0Do you see *any* negative numbers from this data path?
it shows positive as well as negative numbers but in random order....
> > I also suggest strongly that you replace > > use ieee.std_logic_arith.all; > use ieee.std_logic_unsigned.all; > > with > > use ieee.numeric_std.all; > > The conversion functions have different names, but they are easy to > remember. =A0to_integer() works for the types defined in numeric_std > (signed and unsigned). =A0to_signed() and to_unsigned() work for > integer. =A0To convert between integer and SLV you need to use > to_integer, to_signed or to_unsigned to convert between integer and > either signed or unsigned, then you can use "implicit type conversion" > to convert between signed/unsigned and SLV. =A0e.g. std_logic_vector > (signed_signal) > > under numeric_std signed, unsigned and SLV are "closely related types" > which do not need a function for conversion. =A0They will be converted > just by connecting the corresponding "wires" (elements of the array) > between the two types. =A0Since closely related types use the same > element types, this is defined without requiring any "conversion" > between them. > > The reason that you can't convert directly between integer and SLV is > because that would require a specification of the format somehow. =A0By > converting to unsigned or signed in the middle, the format is > specified clearly. >
I tried lots of data types and the conversion function but didn't get the result what i want...... So iam going to put my problem straight forward to you.......your any idea will be gr8ly appreciated.... Problem: 1. i need to count the pulses from quadrature encoder , value of count can be +ve as well as -ve depending upon direction of rotation of encoder... 2.This value is to be send to uBlaze.... 3.I have a code for counting the encoder pulses that is included in the "user_logic".... 4.I have used "user software register" method of transferring data from my custom IP to uBlaze.. 5.In phase of transferring the value of count from IP to uBlaze, the value of count must be mapped to IP2Bus_Data in SLV format data type.... 6.Here i had defined "count " that counts value of pulses as integer and it should be converted SLV while transferring... 7.But this method didn't work as i expected while receiving data in uBlaze..... So...Plz suggest me in.... what should be the data type of "count" that support +ve as well -ve numbers and supports operation count<=3Dcount+1/-1 ?? and how -ve values of count are represented in SLV format??
> Rick
On Oct 13, 1:06=A0am, GrIsH <grishkun...@gmail.com> wrote:
> > =A0 =A0I tried lots of data types and the conversion function but didn't > get the result what i want...... > So iam going to put my problem straight forward to you.......your any > idea will be gr8ly appreciated.... > > Problem: > 1. i need to count the pulses from quadrature encoder , value of count > can be +ve as well as -ve depending upon direction of rotation of > encoder... > 2.This value is to be send to uBlaze.... > 3.I have a code for counting the encoder pulses that is included in > the "user_logic".... > 4.I have used "user software register" method of transferring data > from my custom IP to uBlaze.. > 5.In phase of transferring the value of count from IP to uBlaze, the > value of count must be mapped to IP2Bus_Data in SLV format data > type.... > 6.Here i had defined "count " that counts value of pulses as integer > and it should be converted SLV while transferring... > 7.But this method didn't work as i expected while receiving data in > uBlaze..... > So...Plz suggest me in.... > > what should be the data type of "count" that support +ve as well -ve > numbers and supports operation count<=3Dcount+1/-1 > ?? > and how -ve values of count are represented in SLV format??
I don't know that your problem is one of converting data types. You clearly are placing the 16 bit data in an odd location on a 32 bit bus and you have not told me that you are certain that this is correct. I have not worked with the uBlaze, so I'm not familiar with its data bus numbering. Is it 0 to N or N downto 0? Have you simulated your design? Before putting a design into the chip, you should always simulate it first to get your logic right. Then you can load it into the chip and see if it works with the real hardware. If you don't answer my questions and follow my advice, I can't help you. To answer your last question, the SLV signal type does not know anything about numbers. It is just an array, or a bus, of std_logic signals. There is no intended interpretation of this bus as a number. That is why the signed and unsigned types were developed. They have an explicit representation of signed and unsigned numbers respectively. When you talk about "converting" a signed value to an SLV, there really is no conversion. It is more like just connecting the wires. So the SLV ends up receiving the exact same set of 1s and 0s that were in the signed signal, according to the way that they connected. I have never worked with SLV in the 0 to N direction. To be honest, I don't remember the details of how assignments are made between buses using different directions of indexes. I wouldn't expect any surprises, but then I have no experience with them. Is there a reason that you are using 0 to N numbering instead of N downto 0 on your SLV arrays? This may not be a problem, but if you are stuck, why use this uncommon convention? But before changing anything you need to simulate your design. That means you will need a testbench which can be automatically generated by many VHDL tools. Then edit the resulting testbench file to add stimulus to your inputs and you will be able to observe any signal in the design in the waveform window. That will let you see each and every change of data in the path from the counter to the uBlaze CPU. Rick
On Oct 14, 11:35=A0am, rickman <gnu...@gmail.com> wrote:
> On Oct 13, 1:06=A0am, GrIsH <grishkun...@gmail.com> wrote: > > > > > > > =A0 =A0I tried lots of data types and the conversion function but didn'=
t
> > get the result what i want...... > > So iam going to put my problem straight forward to you.......your any > > idea will be gr8ly appreciated.... > > > Problem: > > 1. i need to count the pulses from quadrature encoder , value of count > > can be +ve as well as -ve depending upon direction of rotation of > > encoder... > > 2.This value is to be send to uBlaze.... > > 3.I have a code for counting the encoder pulses that is included in > > the "user_logic".... > > 4.I have used "user software register" method of transferring data > > from my custom IP to uBlaze.. > > 5.In phase of transferring the value of count from IP to uBlaze, the > > value of count must be mapped to IP2Bus_Data in SLV format data > > type.... > > 6.Here i had defined "count " that counts value of pulses as integer > > and it should be converted SLV while transferring... > > 7.But this method didn't work as i expected while receiving data in > > uBlaze..... > > So...Plz suggest me in.... > > > what should be the data type of "count" that support +ve as well -ve > > numbers and supports operation count<=3Dcount+1/-1 > > ?? > > and how -ve values of count are represented in SLV format?? > > I don't know that your problem is one of converting data types. =A0You > clearly are placing the 16 bit data in an odd location on a 32 bit bus > and you have not told me that you are certain that this is correct. =A0I > have not worked with the uBlaze, so I'm not familiar with its data bus > numbering. =A0Is it 0 to N or N downto 0? > > Have you simulated your design? =A0Before putting a design into the > chip, you should always simulate it first to get your logic right. > Then you can load it into the chip and see if it works with the real > hardware. > > If you don't answer my questions and follow my advice, I can't help > you.
iam trying to simulate my design and lets see what will be the result...
> > To answer your last question, the SLV signal type does not know > anything about numbers. =A0It is just an array, or a bus, of std_logic > signals. =A0There is no intended interpretation of this bus as a > number. =A0That is why the signed and unsigned types were developed. > They have an explicit representation of signed and unsigned numbers > respectively. =A0When you talk about "converting" a signed value to an > SLV, there really is no conversion. =A0It is more like just connecting > the wires. =A0So the SLV ends up receiving the exact same set of 1s and > 0s that were in the signed signal, according to the way that they > connected. > > I have never worked with SLV in the 0 to N direction. =A0To be honest, I > don't remember the details of how assignments are made between buses > using different directions of indexes. =A0I wouldn't expect any > surprises, but then I have no experience with them. =A0Is there a reason > that you are using 0 to N numbering instead of N downto 0 on your SLV > arrays? =A0This may not be a problem, but if you are stuck, why use this > uncommon convention?
for IP2Bus_Data we are not allowed to make this convention of N downto 0 that's why i didn't use this convention.
> > But before changing anything you need to simulate your design. =A0That > means you will need a testbench which can be automatically generated > by many VHDL tools. =A0Then edit the resulting testbench file to add > stimulus to your inputs and you will be able to observe any signal in > the design in the waveform window. =A0That will let you see each and > every change of data in the path from the counter to the uBlaze CPU. > > Rick
On Oct 15, 12:51=A0am, GrIsH <grishkun...@gmail.com> wrote:
> On Oct 14, 11:35=A0am, rickman <gnu...@gmail.com> wrote: > > > I have never worked with SLV in the 0 to N direction. =A0To be honest, =
I
> > don't remember the details of how assignments are made between buses > > using different directions of indexes. =A0I wouldn't expect any > > surprises, but then I have no experience with them. =A0Is there a reaso=
n
> > that you are using 0 to N numbering instead of N downto 0 on your SLV > > arrays? =A0This may not be a problem, but if you are stuck, why use thi=
s
> > uncommon convention? > > =A0 =A0 for IP2Bus_Data we are not allowed to make this convention of N > downto 0 that's why i didn't use this convention.
Ok, it shouldn't matter really, as long as you use it correctly. Can you explain what this bus is and why it is 0 to 31? Is this a port on the uBlaze? Where exactly does this restriction come from. Why do you assign your counter result to bits 16 to 31? I don't know how the uBlaze reads memory, it's possible that it can read the low 16 bits of the bus as a 16 bit quantity... *if you are using the right instruction* to to read a 16 bit quantity, not 16 bits of a 32 bit quantity. If you are coding in C, you are relying on the compiler to generate the correct code. The easy way to fix this problem in hardware is to assign the upper 16 bits of the bus the value of the sign bit of your result instead of always using zeros. Of course, all of this assumes that bit 31 is the lsb. Do you know that for sure? How do you connect the IP2Bus_Data to the uBlaze data bus? That is what really matters. Rick
On Oct 15, 8:14=A0am, rickman <gnu...@gmail.com> wrote:
> On Oct 15, 12:51=A0am, GrIsH <grishkun...@gmail.com> wrote: > > > On Oct 14, 11:35=A0am, rickman <gnu...@gmail.com> wrote: > > > > I have never worked with SLV in the 0 to N direction. =A0To be honest=
, I
> > > don't remember the details of how assignments are made between buses > > > using different directions of indexes. =A0I wouldn't expect any > > > surprises, but then I have no experience with them. =A0Is there a rea=
son
> > > that you are using 0 to N numbering instead of N downto 0 on your SLV > > > arrays? =A0This may not be a problem, but if you are stuck, why use t=
his
> > > uncommon convention? > > > =A0 =A0 for IP2Bus_Data we are not allowed to make this convention of N > > downto 0 that's why i didn't use this convention. > > Ok, it shouldn't matter really, as long as you use it correctly. =A0Can > you explain what this bus is and why it is 0 to 31? =A0Is this a port on > the uBlaze? =A0Where exactly does this restriction come from. =A0Why do > you assign your counter result to bits 16 to 31?
MicroBlaze is big endian. Bits 16 to 31 are the two least significant bytes in a 32-bit word (bit 31 is the right-most bit). -a
On Oct 14, 9:51=A0pm, GrIsH <grishkun...@gmail.com> wrote:
> On Oct 14, 11:35=A0am, rickman <gnu...@gmail.com> wrote: > > I have never worked with SLV in the 0 to N direction. =A0To be honest, =
I
> > don't remember the details of how assignments are made between buses > > using different directions of indexes. =A0I wouldn't expect any > > surprises, but then I have no experience with them. =A0Is there a reaso=
n
> > that you are using 0 to N numbering instead of N downto 0 on your SLV > > arrays? =A0This may not be a problem, but if you are stuck, why use thi=
s
> > uncommon convention? > > =A0 =A0 for IP2Bus_Data we are not allowed to make this convention of N > downto 0 that's why i didn't use this convention.
You can freely assign little-endian (foo downto bar) vectors to big- endian vectors (bar to foo). You just have to remember that the bit lanes are always in the same order: foo(16 downto 0) <=3D bar(0 to 16); will put the least-significant bit (right-most bit) in bar (bit 16) into foo(0), and so forth. The only time you will have issues is when you use a loop to iterate over all bits in a vector and you don't pay attention to this (you don't want to assign bar(0) to foo(0), unless that's what you want to do!). -a