clear;
clc;
Vref = 3300;    %Vref in mV
bits = 12;      %ADC bits
binary_max = (2^bits) - 1;
min_voltage_step = (1/binary_max) * Vref;   %ADC reading of 1
count = 1;
data = zeros(1, binary_max+1);
for Vin = 0:min_voltage_step:Vref
    data(count) = ceil(Vin);
    count = count + 1;
end

%Make a .mif file
fileID = fopen('voltage.mif','w');
%header required for Altera .mif file
fprintf(fileID,'-- Subscription Agreement, the Altera Quartus Prime License Agreement,\n');
fprintf(fileID,'-- the Altera MegaCore Function License Agreement, or other \n');
fprintf(fileID,'-- applicable license agreement, including, without limitation, \n');
fprintf(fileID,'-- that your use is for the sole purpose of programming logic \n');
fprintf(fileID,'-- devices manufactured by Altera and sold by Altera or its \n');
fprintf(fileID,'-- authorized distributors.  Please refer to the applicable \n');
fprintf(fileID,'-- agreement for further details.\n');
fprintf(fileID,'-- Quartus Prime generated Memory Initialization File (.mif)\n');
fprintf(fileID,sprintf('WIDTH=%d;\n', bits));
fprintf(fileID,sprintf('DEPTH=%d;\n', binary_max + 1));
fprintf(fileID,'ADDRESS_RADIX=UNS;\n');
fprintf(fileID,'DATA_RADIX=UNS;\n');
fprintf(fileID,'CONTENT BEGIN\n');
%write data to file
for count = 0:1:binary_max
    fprintf(fileID,'	%i	:	%i;\n',count,data(count+1));
end
fprintf(fileID,'END;');
fclose(fileID);