Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Memory initialization file

Dear my best friends

My project use Cyclone II family (EP2C70F896C6 board)

The memory initialization file have 16bit (width)

This is my code for reading memory file:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
LIBRARY lpm;
USE lpm.LPM_COMPONENTS.ALL;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_signed.all;
ENTITY sin_cos625 IS
PORT (
	CLK				: IN STD_LOGIC:='0';
	CMD_ID,CMD_IQ, ADDRESS			: IN STD_LOGIC_VECTOR(15 downto 0):=(others =>'0');
	Vref1,Vref2,Vref3		: OUT STD_LOGIC_VECTOR(15 downto 0):=(others =>'0')
 	);
END sin_cos625;
ARCHITECTURE sin_cos625_arch OF sin_cos625 IS
	signal sin_addr, cos_addr : STD_LOGIC_vector(15 downto 0):=(others =>'0');
	signal sin_teta, cos_teta  : STD_LOGIC_VECTOR (15 downto 0):=(others =>'0');
    signal PO_SIN,PO_COS,NT_SIN: STD_LOGIC_VECTOR (15 downto 0):=(others =>'0');
	signal CNT				  : STD_LOGIC_VECTOR (7 DOWNTO 0):=(others =>'0');
	signal Adda, Addb, Addr, Mula, Mulb: STD_LOGIC_VECTOR (15 downto 0):=(others =>'0');
	signal Mulr					: STD_LOGIC_vector(31 downto 0):=(others =>'0');
	signal CMD_Vbeta, CMD_Vbetaa, CMD_Valpha: STD_LOGIC_vector(15 downto 0):=(others =>'0');
	signal Vrefx, Vrefy, Vrefz	: STD_LOGIC_vector(15 downto 0):=(others =>'0');
	
BEGIN
 u1 : lpm_rom 
     GENERIC MAP(lpm_width => 16, lpm_widthad => 16, lpm_file => "Sin.mif",
                 lpm_address_control => "REGISTERED", lpm_outdata => "UNREGISTERED")
     PORT MAP(ADDRESS => sin_addr, inclock => clk, q => sin_teta);
 u2 : lpm_rom 
     GENERIC MAP(lpm_width => 16, lpm_widthad => 16, lpm_file => "Cos.mif",
                 lpm_address_control => "REGISTERED", lpm_outdata => "UNREGISTERED")
     PORT MAP(ADDRESS => cos_addr, inclock => clk, q => cos_teta);
mull: lpm_mult
generic map(LPM_WIDTHA=>16,LPM_WIDTHB=>16,LPM_WIDTHS=>16,LPM_WIDTHP=>32,LPM_REPRESENTATION=>"SIGNED",LPM_PIPELINE=>1)
port map(dataa=> mula,datab=> mulb,clock=> clk,result=> mulr);
adder1: lpm_add_sub
generic map(lpm_width=>16,LPM_REPRESENTATION=>"SIGNED",lpm_pipeline=>1)
port map(dataa=>adda,datab=>addb,clock=> clk,result=>addr);
-- Enter sin_addr and cos_addr and lpm will give the value at sin_teta and cos_teta
GEN : block
begin
process (CLK)
begin
if CLK'event and CLK='1' then
	CNT<=cnt+1;
	IF CNT = x"00" then
		sin_addr <= ADDRESS;
		cos_addr <= ADDRESS;
	ELSIF CNT=x"02" THEN
		IF sin_teta = x"000" THEN
			NT_SIN <= x"FFF";
			PO_SIN <= x"000";
		ELSE
			NT_SIN <= -sin_teta;
			PO_SIN <= sin_teta;
		END IF;
		PO_COS <= cos_teta;
	ELSIF CNT=x"04" THEN
		MULA <= CMD_ID;
		MULB <= PO_SIN;
	ELSIF CNT=x"06" THEN
		ADDA <= MULR(15 DOWNTO 0);
		MULA <= CMD_IQ;
		MULB <= PO_COS;
	ELSIF CNT=x"08" THEN
		ADDB <= MULR(15 DOWNTO 0);
		MULA <= CMD_ID;
		MULB <= PO_COS;
	ELSIF CNT=x"0A" THEN
		MULA <= CMD_IQ;
		MULB <= NT_SIN;
		CMD_Vbeta <= ADDR;
		Vrefx <= ADDR;
		ADDA <= MULR(15 DOWNTO 0);
	ELSIF CNT=x"0C" THEN
		ADDB <= MULR(15 DOWNTO 0);
		CMD_Vbetaa <= CMD_Vbeta(15) &'0'& CMD_Vbeta(13 downto 0); 
	ELSIF CNT=x"0E" THEN
		CMD_Valpha <= ADDR;
		MULA <= ADDR;
		MULB <= x"06EE"; 
	ELSIF CNT=x"10" THEN
		ADDA <= -CMD_Vbetaa;
		ADDB <= MULR(15 DOWNTO 0);
	ELSIF CNT=x"12" THEN
		Vrefy <= ADDR;
		ADDA <= -CMD_Vbetaa;
		ADDB <= -MULR(15 DOWNTO 0);
	ELSIF CNT=x"14" THEN
		Vrefz <= ADDR;
	ELSIF CNT = x"16" THEN
		Vref1 <= Vrefx;
		Vref2 <= Vrefy;
		Vref3 <= Vrefz;
		CNT <= x"00";
	END IF;
END IF;
     end process;
end block GEN;
END sin_cos625_arch;

9 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This is my memory initialization file contents:

    -- Copyright (C) 1991-2007 Altera Corporation
    -- Your use of Altera Corporation's design tools, logic functions 
    -- and other software and tools, and its AMPP partner logic 
    -- functions, and any output files from any of the foregoing 
    -- (including device programming or simulation files), and any 
    -- associated documentation or information are expressly subject 
    -- to the terms and conditions of the Altera Program License 
    -- Subscription Agreement, Altera MegaCore Function License 
    -- Agreement, or other applicable license agreement, including, 
    -- without limitation, that your use is for the sole purpose of 
    -- programming logic devices manufactured by Altera and sold by 
    -- Altera or its authorized distributors.  Please refer to the 
    -- applicable agreement for further details.
    -- Quartus II generated Memory Initialization File (.mif)
    WIDTH=16;
    DEPTH=360;
    ADDRESS_RADIX=UNS;
    DATA_RADIX=HEX;
    CONTENT BEGIN
    	0    :   0000;
    	1    :   023C;
    	2    :   0477;
    	3    :   06B3;
    	4    :   08EE;
    	5    :   0B28;
    	6    :   0D61;
    	7    :   0F99;
    	8    :   11D0;
    	9    :   1406;
    	10   :   163A;
    	11   :   186C;
    	12   :   1A9D;
    	13   :   1CCB;
    	14   :   1EF7;
    	15   :   2121;
    	16   :   2348;
    	17   :   256C;
    	18   :   278E;
    	19   :   29AC;
    	20   :   2BC7;
    	21   :   2DDF;
    	22   :   2FF3;
    	23   :   3203;
    	24   :   3410;
    	25   :   3618;
    	26   :   381C;
    	27   :   3A1C;
    	28   :   3C17;
    	29   :   3E0E;
    	30   :   4000;
    	31   :   41ED;
    	32   :   43D4;
    	33   :   45B7;
    	34   :   4793;
    	35   :   496B;
    	36   :   4B3C;
    	37   :   4D08;
    	38   :   4ECE;
    	39   :   508D;
    	40   :   5247;
    	41   :   53FA;
    	42   :   55A6;
    	43   :   574C;
    	44   :   58EA;
    	45   :   5A82;
    	46   :   5C13;
    	47   :   5D9D;
    	48   :   5F1F;
    	49   :   609A;
    	50   :   620E;
    	51   :   6379;
    	52   :   64DD;
    	53   :   6639;
    	54   :   678E;
    	55   :   68DA;
    	56   :   6A1E;
    	57   :   6B59;
    	58   :   6C8D;
    	59   :   6DB7;
    	60   :   6EDA;
    	61   :   6FF3;
    	62   :   7104;
    	63   :   720C;
    	64   :   730B;
    	65   :   7402;
    	66   :   74EF;
    	67   :   75D3;
    	68   :   76AE;
    	69   :   777F;
    	70   :   7848;
    	71   :   7906;
    	72   :   79BC;
    	73   :   7A68;
    	74   :   7B0A;
    	75   :   7BA3;
    	76   :   7C32;
    	77   :   7CB8;
    	78   :   7D34;
    	79   :   7DA6;
    	80   :   7E0E;
    	81   :   7E6C;
    	82   :   7EC1;
    	83   :   7F0B;
    	84   :   7F4C;
    	85   :   7F83;
    	86   :   7FB0;
    	87   :   7FD3;
    	88   :   7FEC;
    	89   :   7FFB;
    	90   :   7FFF;
    	91   :   7FFB;
    	92   :   7FEC;
    	93   :   7FD3;
    	94   :   7FB0;
    	95   :   7F83;
    	96   :   7F4C;
    	97   :   7F0B;
    	98   :   7EC1;
    	99   :   7E6C;
    	100  :   7E0E;
    	101  :   7DA5;
    	102  :   7D33;
    	103  :   7CB8;
    	104  :   7C32;
    	105  :   7BA3;
    	106  :   7B0A;
    	107  :   7A68;
    	108  :   79BC;
    	109  :   7906;
    	110  :   7847;
    	111  :   777F;
    	112  :   76AD;
    	113  :   75D2;
    	114  :   74EE;
    	115  :   7401;
    	116  :   730B;
    	117  :   720C;
    	118  :   7104;
    	119  :   6FF3;
    	120  :   6ED9;
    	121  :   6DB7;
    	122  :   6C8C;
    	123  :   6B59;
    	124  :   6A1D;
    	125  :   68D9;
    	126  :   678D;
    	127  :   6639;
    	128  :   64DD;
    	129  :   6379;
    	130  :   620D;
    	131  :   6099;
    	132  :   5F1F;
    	133  :   5D9C;
    	134  :   5C12;
    	135  :   5A82;
    	136  :   58EA;
    	137  :   574B;
    	138  :   55A5;
    	139  :   53F9;
    	140  :   5246;
    	141  :   508D;
    	142  :   4ECD;
    	143  :   4D07;
    	144  :   4B3C;
    	145  :   496A;
    	146  :   4793;
    	147  :   45B6;
    	148  :   43D3;
    	149  :   41EC;
    	150  :   3FFF;
    	151  :   3E0D;
    	152  :   3C17;
    	153  :   3A1B;
    	154  :   381C;
    	155  :   3617;
    	156  :   340F;
    	157  :   3202;
    	158  :   2FF2;
    	159  :   2DDE;
    	160  :   2BC6;
    	161  :   29AB;
    	162  :   278D;
    	163  :   256B;
    	164  :   2347;
    	165  :   2120;
    	166  :   1EF6;
    	167  :   1CCA;
    	168  :   1A9C;
    	169  :   186B;
    	170  :   1639;
    	171  :   1405;
    	172  :   11CF;
    	173  :   0F98;
    	174  :   0D60;
    	175  :   0B27;
    	176  :   08ED;
    	177  :   06B2;
    	178  :   0476;
    	179  :   023B;
    	180  :   0000;
    	181  :   FDC4;
    	182  :   FB88;
    	183  :   F94D;
    	184  :   F712;
    	185  :   F4D8;
    	186  :   F29F;
    	187  :   F066;
    	188  :   EE2F;
    	189  :   EBFA;
    	190  :   E9C6;
    	191  :   E793;
    	192  :   E563;
    	193  :   E335;
    	194  :   E109;
    	195  :   DEDF;
    	196  :   DCB8;
    	197  :   DA93;
    	198  :   D872;
    	199  :   D654;
    	200  :   D439;
    	201  :   D221;
    	202  :   D00D;
    	203  :   CDFC;
    	204  :   CBF0;
    	205  :   C9E8;
    	206  :   C7E3;
    	207  :   C5E4;
    	208  :   C3E8;
    	209  :   C1F2;
    	210  :   C000;
    	211  :   BE13;
    	212  :   BC2C;
    	213  :   BA49;
    	214  :   B86C;
    	215  :   B695;
    	216  :   B4C3;
    	217  :   B2F8;
    	218  :   B132;
    	219  :   AF72;
    	220  :   ADB9;
    	221  :   AC06;
    	222  :   AA5A;
    	223  :   A8B4;
    	224  :   A715;
    	225  :   A57E;
    	226  :   A3ED;
    	227  :   A263;
    	228  :   A0E1;
    	229  :   9F66;
    	230  :   9DF2;
    	231  :   9C87;
    	232  :   9B23;
    	233  :   99C6;
    	234  :   9872;
    	235  :   9726;
    	236  :   95E2;
    	237  :   94A7;
    	238  :   9373;
    	239  :   9248;
    	240  :   9126;
    	241  :   900D;
    	242  :   8EFC;
    	243  :   8DF4;
    	244  :   8CF5;
    	245  :   8BFE;
    	246  :   8B11;
    	247  :   8A2D;
    	248  :   8952;
    	249  :   8881;
    	250  :   87B8;
    	251  :   86FA;
    	252  :   8644;
    	253  :   8598;
    	254  :   84F6;
    	255  :   845D;
    	256  :   83CE;
    	257  :   8348;
    	258  :   82CC;
    	259  :   825A;
    	260  :   81F2;
    	261  :   8194;
    	262  :   813F;
    	263  :   80F5;
    	264  :   80B4;
    	265  :   807D;
    	266  :   8050;
    	267  :   802D;
    	268  :   8014;
    	269  :   8005;
    	270  :   8001;
    	271  :   8006;
    	272  :   8014;
    	273  :   802D;
    	274  :   8050;
    	275  :   807D;
    	276  :   80B4;
    	277  :   80F5;
    	278  :   813F;
    	279  :   8194;
    	280  :   81F2;
    	281  :   825B;
    	282  :   82CD;
    	283  :   8349;
    	284  :   83CE;
    	285  :   845D;
    	286  :   84F6;
    	287  :   8599;
    	288  :   8645;
    	289  :   86FA;
    	290  :   87B9;
    	291  :   8881;
    	292  :   8953;
    	293  :   8A2E;
    	294  :   8B12;
    	295  :   8BFF;
    	296  :   8CF5;
    	297  :   8DF4;
    	298  :   8EFC;
    	299  :   900D;
    	300  :   9127;
    	301  :   9249;
    	302  :   9374;
    	303  :   94A7;
    	304  :   95E3;
    	305  :   9727;
    	306  :   9873;
    	307  :   99C7;
    	308  :   9B23;
    	309  :   9C87;
    	310  :   9DF3;
    	311  :   9F67;
    	312  :   A0E2;
    	313  :   A264;
    	314  :   A3EE;
    	315  :   A57F;
    	316  :   A716;
    	317  :   A8B5;
    	318  :   AA5B;
    	319  :   AC07;
    	320  :   ADBA;
    	321  :   AF74;
    	322  :   B133;
    	323  :   B2F9;
    	324  :   B4C5;
    	325  :   B696;
    	326  :   B86E;
    	327  :   BA4A;
    	328  :   BC2D;
    	329  :   BE14;
    	330  :   C001;
    	331  :   C1F3;
    	332  :   C3EA;
    	333  :   C5E5;
    	334  :   C7E5;
    	335  :   C9E9;
    	336  :   CBF1;
    	337  :   CDFE;
    	338  :   D00E;
    	339  :   D222;
    	340  :   D43A;
    	341  :   D655;
    	342  :   D873;
    	343  :   DA95;
    	344  :   DCB9;
    	345  :   DEE0;
    	346  :   E10A;
    	347  :   E336;
    	348  :   E564;
    	349  :   E795;
    	350  :   E9C7;
    	351  :   EBFB;
    	352  :   EE31;
    	353  :   F068;
    	354  :   F2A0;
    	355  :   F4D9;
    	356  :   F714;
    	357  :   F94E;
    	358  :   FB8A;
    	359  :   FDC5;
    END;
    

    When I compile this project, I got this error:

    Error: Selected device has 250 RAM location(s) of type M4K.  However, the current design needs more than 250 to successfully fit

    I did not know how to fix it. Please, could you help me?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The FPGA in your project does not have enough onchip memory. You need to either,

    1. Reduce memory required in your project

    OR

    2. Use a different FPGA with more onchip memory
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Dear Waiyung

    I'm new with FPGA. Could you help me? Which FPGA do you suggest for me?

    thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Dear Waiyung

    I'm new with FPGA. Could you help me? Which FPGA do you suggest for me?

    thanks

    --- Quote End ---

    Hi,

    did you use signaltap for debugging ?

    Kind regards

    GPK
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    did you use signaltap for debugging ?

    Kind regards

    GPK

    --- Quote End ---

    Dear pletz

    Could you tell me more about signaltap? I did not know about this tool. Thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Dear pletz

    Could you tell me more about signaltap? I did not know about this tool. Thanks

    --- Quote End ---

    Hi,

    signaltap is a tool for debugging. Have look to the Altera Web site for the documentation.

    It would require Memory resources of the FPGA. That was the reason why I asked about it.

    The only way for you is then to use a larger FPGA or maybe you reduce the word width of the ROM. Do you look for a solution for a real product or only for testing ?

    Kind regards

    GPK
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    in your code you instantiate two lp_roms, each 16 bit wide and 16 bit deep. These two roms need 262144 bytes of memory. In a Cyclone II device you would need 512 M4K blocks for these roms. The largest Cyclone II device has 250 M4K blocks. So Cyclone II is not the rigth choice. If you change to Cyclone III (e.g. EP3C55) or IV you only need half of the blocks due to the larger size of the blocks . An other possibility is to reduce the size of the roms.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    signaltap is a tool for debugging. Have look to the Altera Web site for the documentation.

    It would require Memory resources of the FPGA. That was the reason why I asked about it.

    The only way for you is then to use a larger FPGA or maybe you reduce the word width of the ROM. Do you look for a solution for a real product or only for testing ?

    Kind regards

    GPK

    --- Quote End ---

    Dear pletz

    I want to look for a solution for a real product. I'd already bought a DE2 board from Altera. When I make this project I had this error. Thank you very much.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    in your code you instantiate two lp_roms, each 16 bit wide and 16 bit deep. These two roms need 262144 bytes of memory. In a Cyclone II device you would need 512 M4K blocks for these roms. The largest Cyclone II device has 250 M4K blocks. So Cyclone II is not the rigth choice. If you change to Cyclone III (e.g. EP3C55) or IV you only need half of the blocks due to the larger size of the blocks . An other possibility is to reduce the size of the roms.

    --- Quote End ---

    Thank you very much. Your informations are very useful for me.