Forum Discussion

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

How to set content in a memory

............

5 Replies

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

    Thanks Alexandre,

    I've checked your suggestion, but what if I've 2 memories?

    Apparently, mif and hex just assign width and depth.

    How to appoint mif A and mif B?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Besides that,

    I've RAM infer, build in my project. Can I save a data on it in the same way with mif and hex??

    
    module SRAM_INFERS(CLK, WA, WE, DI, RA, DO, RA0, DO0, RA1, DO1, RA2, DO2, RA3, DO3);
    input CLK;
    /* 256 bit Write port */
    input WE;
    input WA;
    input  DI;
    /* 256 bit Read port */
    input RA;
    input  DO;
    /* 8 bit Read ports */
    input  RA0, RA1;
    input  RA2, RA3;
    output  DO0, DO1;
    output DO2, DO3;
    wire  DO0_tmp, DO1_tmp, DO2_tmp, DO3_tmp, DO_tmp;
    reg  DO0, DO1;
    reg  DO2, DO3;
    /* Memory */
    reg  Mem ;
    always @(posedge CLK)
    begin
    if(WE)
    Mem = DI;
    end
    assign DO_tmp = Mem;
    assign DO0_tmp = Mem];
    assign DO1_tmp = Mem];
    assign DO2_tmp = Mem];
    assign DO3_tmp = Mem];
    /* Subfield Extraction for 8 bit Read */
    always @(DO0_tmp or RA0)
    begin
    casex(RA0)
    5'b11111 : DO0 = DO0_tmp;
    5'b11110 : DO0 = DO0_tmp;
    5'b11101 : DO0 = DO0_tmp;
    5'b11100 : DO0 = DO0_tmp;
    5'b11011 : DO0 = DO0_tmp;
    .
    .
    .
    .
    end
    endmodule
    

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

    That won't infer RAM due to asynchronous read.

    That said, you can initialize the RAM contents with a "inital" block and a $readmem function to read data from a file.

    Another way is to use a ATLSYNCRAM function and point the INIT_FILE parameter to a .MIF or .HEX file.