├── README.md ├── matlab_code └── imageconvert2bin.m ├── python_code └── MNIST_Loader-checkpoint.ipynb ├── quartus_simulation_results ├── compilation_report.PNG └── maximum_freq_summary.PNG ├── validation_using_excel ├── validation_1.xlsx └── validation_2.xlsx ├── validation_using_modelsim ├── 1ST_STIM_WEIGH_PIX.txt ├── 2nd_STIM_WEIGH_PIX.txt └── out_stimulus_sim_rep.txt └── verilog_codes ├── RF_generation.v ├── RF_generation_tb.v ├── RF_top1.v ├── RF_top1_tb.v ├── fifo1.v ├── fifo1_tb.v ├── fifomem.v ├── glob_count_shift_reg.v ├── rptr_empty.v ├── rwg.v ├── rwg_tb.v ├── sync_r2w.v ├── sync_w2r.v ├── weigh_pix_par_add.v └── wptr_full.v /README.md: -------------------------------------------------------------------------------- 1 | # Fpga-Implementation-of-Precise-Convolutional-Neural-Network-for-Extreme-Learning-Machine 2 | If you find this useful, cite this paper below 3 | 4 | http://www.ijitee.org/wp-content/uploads/papers/v9i8/H6501069820.pdf 5 | 6 | Thank you !! 7 | 8 | 9 | -------------------------------------------------------------------------------- /matlab_code/imageconvert2bin.m: -------------------------------------------------------------------------------- 1 | % Image to text conversion 2 | % Read the image from the file 3 | [filename, pathname] = uigetfile('00002.png','C:\Users\Rajavarshini\Desktop\review1\bitmap image'); 4 | img = imread('C:\Users\Rajavarshini\Desktop\review1\bitmap image\00002.png'); 5 | img = imresize((img),[28 28]); 6 | [ row col p ] =size(img); 7 | if p == 3 8 | img = rgb2gray(img); 9 | end 10 | rectImg = img(1:28,1:28); 11 | % noise add 12 | rectImg = imnoise(rectImg,'salt & pepper', 0.02); 13 | img(1:28,1:28) = rectImg; 14 | % Image Transpose 15 | imgTrans = img'; 16 | %imgTrans = img'; 17 | % iD conversion 18 | img1D = imgTrans(:); 19 | %img1Da = reshape(img1D,[49,16]); 20 | % Decimal to Bin value conversion 21 | imgBin = dec2bin(img1D); 22 | %imgBin1= reshape(imgBin,[49,128]); 23 | % New txt file creation 24 | fid = fopen('C:\Users\Rajavarshini\Desktop\review1\bitmap image\inputBin5610.txt', 'wt'); 25 | % Bin value write to the txt file 26 | % repmat - repeat copies of array 27 | fprintf(fid, [repmat('%c',1,size(imgBin,2)) '\r\n'], imgBin.'); 28 | % Close the txt file 29 | fclose(fid) -------------------------------------------------------------------------------- /python_code/MNIST_Loader-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Data Loader for MNIST Database\n", 8 | "\n", 9 | "This tutorial shows you how to download the MNIST digit database and process it to make it ready for machine learning algorithms.\n", 10 | "\n", 11 | "## Topics to be covered\n", 12 | "\n", 13 | "1. Downloading the dataset.\n", 14 | "2. Processing the raw data to a easier data structure (numpy ndarray).\n", 15 | "3. Saving the images.\n", 16 | "4. Saving the dataset as a pickle file\n", 17 | "\n", 18 | "\n", 19 | "## Downloading the Dataset\n", 20 | "\n", 21 | "The dataset can be downloaded using a browser using the following downloadable links :\n", 22 | "\n", 23 | "* [Training Images](http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz)\n", 24 | "* [Training Labels](http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz)\n", 25 | "* [Testing Images](http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz)\n", 26 | "* [Testing Labels](http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz)\n", 27 | "\n", 28 | "Alternatively the code segment below can also be used to download the images to a specific dataset." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "scrolled": false 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "#IMPORTS\n", 40 | "import os,urllib.request\n", 41 | "\n", 42 | "\n", 43 | "# PROVIDE YOUR DOWNLOAD DIRECTORY HERE\n", 44 | "datapath = '../../Data/MNISTData/' \n", 45 | "\n", 46 | "# CREATING DOWNLOAD DIRECTORY\n", 47 | "if not os.path.exists(datapath):\n", 48 | " os.makedirs(datapath)\n", 49 | "\n", 50 | "# URLS TO DOWNLOAD FROM\n", 51 | "urls = ['http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz',\n", 52 | " 'http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz',\n", 53 | " 'http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz',\n", 54 | " 'http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz']\n", 55 | "\n", 56 | "for url in urls:\n", 57 | " filename = url.split('/')[-1] # GET FILENAME\n", 58 | " \n", 59 | " if os.path.exists(datapath+filename):\n", 60 | " print(filename, ' already exists') # CHECK IF FILE EXISTS\n", 61 | " else:\n", 62 | " print('Downloading ',filename)\n", 63 | " urllib.request.urlretrieve (url, datapath+filename) # DOWNLOAD FILE\n", 64 | " \n", 65 | "print('All files are available')" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## Extracting the downloaded files\n", 73 | "\n", 74 | "The downloaded files are in an archive format and needs to be extracted. It can be manually extracted using the GUI or the code segment below can also be used." 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "import os,gzip,shutil\n", 84 | "\n", 85 | "# PROVIDE YOUR DOWNLOAD DIRECTORY HERE\n", 86 | "datapath = '../../Data/MNISTData/' \n", 87 | "\n", 88 | "# LISTING ALL ARCHIVES IN THE DIRECTORY\n", 89 | "files = os.listdir(datapath)\n", 90 | "for file in files:\n", 91 | " if file.endswith('gz'):\n", 92 | " print('Extracting ',file)\n", 93 | " with gzip.open(datapath+file, 'rb') as f_in:\n", 94 | " with open(datapath+file.split('.')[0], 'wb') as f_out:\n", 95 | " shutil.copyfileobj(f_in, f_out)\n", 96 | "print('Extraction Complete')\n", 97 | "\n", 98 | "# OPTIONAL REMOVE THE ARCHIVES\n", 99 | "for file in files:\n", 100 | " print('Removing ',file)\n", 101 | " os.remove(datapath+file)\n", 102 | "print ('All archives removed')" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 3, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "data": { 112 | "text/html": [ 113 | "" 116 | ], 117 | "text/plain": [ 118 | "" 119 | ] 120 | }, 121 | "metadata": {}, 122 | "output_type": "display_data" 123 | } 124 | ], 125 | "source": [ 126 | "%%html\n", 127 | "\n" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "## Process the Files \n", 137 | "All the image files and labels of the MNIST dataset is encoded into these 4 files. We need to be able to extract the images from the files to work with them.\n", 138 | "\n", 139 | "### File descriptions\n", 140 | "Four files are provided:\n", 141 | "\n", 142 | "* Test Images : t10k-images-idx3-ubyte\n", 143 | "* Test Labels : t10k-labels-idx1-ubyte\n", 144 | "* Train Images : train-images-idx3-ubyte\n", 145 | "* Train Labels : train-labels-idx1-ubyte\n", 146 | "\n", 147 | "The IDX file format is a simple format for vectors and multidimensional matrices of various numerical types.\n", 148 | "\n", 149 | "#### The basic format for labels\n", 150 | " \n", 151 | "|Offset | Type | Value | Description |\n", 152 | "|-------|--------------------|-----------------|---------------------------------|\n", 153 | "|0000 |4 byte integer |0x00000801(2049) |magic number (MSB first) | \n", 154 | "|0004 |4 byte integer |10000 or 60000 |number of items (test or train) |\n", 155 | "|0008 |unsigned byte |?? |label |\n", 156 | "|0009 |unsigned byte |?? |label |\n", 157 | "|... |... |... |... |\n", 158 | "|xxxx |unsigned byte |?? |label |\n", 159 | "\n", 160 | "\n", 161 | "#### The basic format for images\n", 162 | "\n", 163 | "|Offset | Type | Value | Description |\n", 164 | "|-------|--------------------|-----------------|---------------------------------|\n", 165 | "|0000 |4 byte integer |0x00000801(2049) |magic number (MSB first) | \n", 166 | "|0004 |4 byte integer |10000 or 60000 |number of images (test or train) |\n", 167 | "|0008 |4 byte integer |28 |number of rows |\n", 168 | "|0012 |4 byte integer |28 |number of columns |\n", 169 | "|0016 |unsigned byte |?? |pixel intensity (0-255) |\n", 170 | "|0017 |unsigned byte |?? |pixel intensity (0-255) |\n", 171 | "|... |... |... |... | \n", 172 | "|xxxx |unsigned byte |?? |pixel intensity (0-255) |\n", 173 | "\n", 174 | "\n", 175 | "### Converting the ubyte files to numpy arrays for easy processing\n", 176 | "The following code converts the ubyte files into four numpy n dimensional arrays and stores them in a dictionary called `data_dict` which has four key, value pairs.\n", 177 | "\n", 178 | "| Key | Type |Shape |\n", 179 | "|---------------|--------------|--------------|\n", 180 | "|*train_images* |numpy ndarray |[60000,28,28] | \n", 181 | "|*train_labels* |numpy ndarray |[60000] |\n", 182 | "|*test_images* |numpy ndarray |[10000,28,28] |\n", 183 | "|*test_labels* |numpy ndarray |[10000] |\n" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "import os,codecs,numpy\n", 193 | "\n", 194 | "# PROVIDE YOUR DIRECTORY WITH THE EXTRACTED FILES HERE\n", 195 | "datapath = '../../Data/MNISTData/'\n", 196 | "\n", 197 | "files = os.listdir(datapath)\n", 198 | "\n", 199 | "def get_int(b): # CONVERTS 4 BYTES TO A INT\n", 200 | " return int(codecs.encode(b, 'hex'), 16)\n", 201 | "\n", 202 | "data_dict = {}\n", 203 | "for file in files:\n", 204 | " if file.endswith('ubyte'): # FOR ALL 'ubyte' FILES\n", 205 | " print('Reading ',file)\n", 206 | " with open (datapath+file,'rb') as f:\n", 207 | " data = f.read()\n", 208 | " type = get_int(data[:4]) # 0-3: THE MAGIC NUMBER TO WHETHER IMAGE OR LABEL\n", 209 | " length = get_int(data[4:8]) # 4-7: LENGTH OF THE ARRAY (DIMENSION 0)\n", 210 | " if (type == 2051):\n", 211 | " category = 'images'\n", 212 | " num_rows = get_int(data[8:12]) # NUMBER OF ROWS (DIMENSION 1)\n", 213 | " num_cols = get_int(data[12:16]) # NUMBER OF COLUMNS (DIMENSION 2)\n", 214 | " parsed = numpy.frombuffer(data,dtype = np.uint8, offset = 16) # READ THE PIXEL VALUES AS INTEGERS\n", 215 | " parsed = parsed.reshape(length,num_rows,num_cols) # RESHAPE THE ARRAY AS [NO_OF_SAMPLES x HEIGHT x WIDTH] \n", 216 | " elif(type == 2049):\n", 217 | " category = 'labels'\n", 218 | " parsed = np.frombuffer(data, dtype=np.uint8, offset=8) # READ THE LABEL VALUES AS INTEGERS\n", 219 | " parsed = parsed.reshape(length) # RESHAPE THE ARRAY AS [NO_OF_SAMPLES] \n", 220 | " if (length==10000):\n", 221 | " set = 'test'\n", 222 | " elif (length==60000):\n", 223 | " set = 'train'\n", 224 | " data_dict[set+'_'+category] = parsed # SAVE THE NUMPY ARRAY TO A CORRESPONDING KEY " 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": { 230 | "collapsed": true 231 | }, 232 | "source": [ 233 | "### Saving images from the dataset\n", 234 | "\n", 235 | "This code segment can be used to save the data of the numpy array as images in class specific directories." 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": null, 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [ 244 | "import os\n", 245 | "from skimage.io import imsave\n", 246 | "datapath = '../../Data/MNISTData/' # PATH WHERE IMAGES WILL BE SAVED\n", 247 | "\n", 248 | "sets = ['train','test']\n", 249 | "\n", 250 | "for set in sets: # FOR TRAIN AND TEST SET\n", 251 | " images = data_dict[set+'_images'] # IMAGES\n", 252 | " labels = data_dict[set+'_labels'] # LABELS\n", 253 | " no_of_samples = images.shape[0] # NUBMER OF SAMPLES\n", 254 | " for indx in range (no_of_samples): # FOR EVERY SAMPLE\n", 255 | " print(set, indx)\n", 256 | " image = images[indx] # GET IMAGE\n", 257 | " label = labels[indx] # GET LABEL\n", 258 | " if not os.path.exists(datapath+set+'/'+str(label)+'/'): # IF DIRECTORIES DO NOT EXIST THEN \n", 259 | " os.makedirs (datapath+set+'/'+str(label)+'/') # CREATE TRAIN/TEST DIRECTORY AND CLASS SPECIFIC SUBDIRECTORY\n", 260 | " filenumber = len(os.listdir(datapath+set+'/'+str(label)+'/')) # NUMBER OF FILES IN THE DIRECTORY FOR NAMING THE FILE\n", 261 | " imsave(datapath+set+'/'+str(label)+'/%05d.png'%(filenumber),image) # SAVE THE IMAGE WITH PROPER NAME\n", 262 | " " 263 | ] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "metadata": {}, 268 | "source": [ 269 | "### Saving the dictionary using pickle\n", 270 | "\n", 271 | "Python data structures can be directly saved as it is using the pickle package.\n", 272 | "The code segment below shows how to save the `data_dict` using `pickle.dump` and later loading it back using `pickle.load`" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 88, 278 | "metadata": {}, 279 | "outputs": [], 280 | "source": [ 281 | "import pickle\n", 282 | "\n", 283 | "datapath = '../../Data/MNISTData/'\n", 284 | "\n", 285 | "# DUMPING THE DICTIONARY INTO A PICKLE \n", 286 | "with open(datapath+'MNISTData.pkl', 'wb') as fp :\n", 287 | " pickle.dump(data_dict, fp)\n", 288 | "\n", 289 | "# LOADING THE DICTIONARY FROM A PICKLE\n", 290 | "with open(datapath+'MNISTData.pkl', 'rb') as fp :\n", 291 | " new_dict = pickle.load(fp)\n" 292 | ] 293 | } 294 | ], 295 | "metadata": { 296 | "kernelspec": { 297 | "display_name": "Python 3", 298 | "language": "python", 299 | "name": "python3" 300 | }, 301 | "language_info": { 302 | "codemirror_mode": { 303 | "name": "ipython", 304 | "version": 3 305 | }, 306 | "file_extension": ".py", 307 | "mimetype": "text/x-python", 308 | "name": "python", 309 | "nbconvert_exporter": "python", 310 | "pygments_lexer": "ipython3", 311 | "version": "3.6.4" 312 | } 313 | }, 314 | "nbformat": 4, 315 | "nbformat_minor": 2 316 | } 317 | -------------------------------------------------------------------------------- /quartus_simulation_results/compilation_report.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suburaaj/Fpga-Implementation-of-Precise-Convolutional-Neural-Network-for-Extreme-Learning-Machine/d64e8adc772da7190372d61b8236ce3e4d22db4a/quartus_simulation_results/compilation_report.PNG -------------------------------------------------------------------------------- /quartus_simulation_results/maximum_freq_summary.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suburaaj/Fpga-Implementation-of-Precise-Convolutional-Neural-Network-for-Extreme-Learning-Machine/d64e8adc772da7190372d61b8236ce3e4d22db4a/quartus_simulation_results/maximum_freq_summary.PNG -------------------------------------------------------------------------------- /validation_using_excel/validation_1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suburaaj/Fpga-Implementation-of-Precise-Convolutional-Neural-Network-for-Extreme-Learning-Machine/d64e8adc772da7190372d61b8236ce3e4d22db4a/validation_using_excel/validation_1.xlsx -------------------------------------------------------------------------------- /validation_using_excel/validation_2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suburaaj/Fpga-Implementation-of-Precise-Convolutional-Neural-Network-for-Extreme-Learning-Machine/d64e8adc772da7190372d61b8236ce3e4d22db4a/validation_using_excel/validation_2.xlsx -------------------------------------------------------------------------------- /validation_using_modelsim/1ST_STIM_WEIGH_PIX.txt: -------------------------------------------------------------------------------- 1 | # 1358000000 | weighted_pixel[0] = 0 | weighted_pixel[1] = 256 | weighted_pixel[2] = 0 | weighted_pixel[3] = 0 | weighted_pixel[4] = 256 | 2 | # weighted_pixel[5] = 256 | weighted_pixel[6] = 256 | weighted_pixel[7] = 0 | weighted_pixel[8] = 256 | weighted_pixel[9] = 0 | weighted_pixel[10] = 0 3 | 4 | # 1371000000 | weighted_pixel[11] = 256 | weighted_pixel[12] = 0 | weighted_pixel[13] = 0 | weighted_pixel[14] = 0 | weighted_pixel[15] = 256 | 5 | # weighted_pixel[16] = 256 | weighted_pixel[17] = 256 | weighted_pixel[18] = 0 | weighted_pixel[19] = 256 | weighted_pixel[20] = 0 | weighted_pixel[21] = 0 6 | 7 | # 1384000000 | weighted_pixel[22] = 256 | weighted_pixel[23] = 0 | weighted_pixel[24] = 256 | weighted_pixel[25] = 0 | weighted_pixel[26] = 0 | 8 | # weighted_pixel[27] = 256 | weighted_pixel[28] = 256 | weighted_pixel[29] = 256 | weighted_pixel[30] = 0 | weighted_pixel[31] = 256 | weighted_pixel[32] = 0 9 | 10 | # 1397000000 | weighted_pixel[33] = 256 | weighted_pixel[34] = 256 | weighted_pixel[35] = 0 | weighted_pixel[36] = 256 | weighted_pixel[37] = 0 | 11 | # weighted_pixel[38] = 0 | weighted_pixel[39] = 256 | weighted_pixel[40] = 256 | weighted_pixel[41] = 256 | weighted_pixel[42] = 0 | weighted_pixel[43] = 0 12 | 13 | # 1410000000 | weighted_pixel[44] = 256 | weighted_pixel[45] = 256 | weighted_pixel[46] = 256 | weighted_pixel[47] = 0 | weighted_pixel[48] = 256 | 14 | # weighted_pixel[49] = 0 | weighted_pixel[50] = 0 | weighted_pixel[51] = 256 | weighted_pixel[52] = 256 | weighted_pixel[53] = 256 | weighted_pixel[54] = 0 15 | 16 | # 1423000000 | weighted_pixel[55] = 0 | weighted_pixel[56] = 256 | weighted_pixel[57] = 256 | weighted_pixel[58] = 256 | weighted_pixel[59] = 0 | 17 | # weighted_pixel[60] = 256 | weighted_pixel[61] = 0 | weighted_pixel[62] = 0 | weighted_pixel[63] = 256 | weighted_pixel[64] = 256 | weighted_pixel[65] = 0 18 | 19 | # 1436000000 | weighted_pixel[66] = 0 | weighted_pixel[67] = 0 | weighted_pixel[68] = 256 | weighted_pixel[69] = 256 | weighted_pixel[70] = 256 | 20 | # weighted_pixel[71] = 0 | weighted_pixel[72] = 256 | weighted_pixel[73] = 0 | weighted_pixel[74] = 0 | weighted_pixel[75] = 256 | weighted_pixel[76] = 0 21 | 22 | # 1449000000 | weighted_pixel[77] = 256 | weighted_pixel[78] = 0 | weighted_pixel[79] = 0 | weighted_pixel[80] = 256 | weighted_pixel[81] = 256 | 23 | # weighted_pixel[82] = 256 | weighted_pixel[83] = 0 | weighted_pixel[84] = 256 | weighted_pixel[85] = 0 | weighted_pixel[86] = 0 | weighted_pixel[87] = 0 24 | 25 | # 1462000000 | weighted_pixel[88] = 0 | weighted_pixel[89] = 256 | weighted_pixel[90] = 0 | weighted_pixel[91] = 0 | weighted_pixel[92] = 256 | 26 | # weighted_pixel[93] = 256 | weighted_pixel[94] = 256 | weighted_pixel[95] = 0 | weighted_pixel[96] = 256 | weighted_pixel[97] = 0 | weighted_pixel[98] = 0 27 | 28 | # 1475000000 | weighted_pixel[99] = 256 | weighted_pixel[100] = 0 | weighted_pixel[101] = 256 | weighted_pixel[102] = 0 | weighted_pixel[103] = 0 | 29 | # weighted_pixel[104] = 256 | weighted_pixel[105] = 256 | weighted_pixel[106] = 256 | weighted_pixel[107] = 0 | weighted_pixel[108] = 256 | weighted_pixel[109] = 0 30 | 31 | # 1488000000 | weighted_pixel[110] = 256 | weighted_pixel[111] = 256 | weighted_pixel[112] = 0 | weighted_pixel[113] = 256 | weighted_pixel[114] = 0 | 32 | # weighted_pixel[115] = 0 | weighted_pixel[116] = 256 | weighted_pixel[117] = 256 | weighted_pixel[118] = 256 | weighted_pixel[119] = 0 | weighted_pixel[120] = 0 33 | 34 | # 1501000000 | weighted_pixel[121] = 256 | weighted_pixel[122] = 256 | weighted_pixel[123] = 256 | weighted_pixel[124] = 0 | weighted_pixel[125] = 256 | 35 | # weighted_pixel[126] = 0 | weighted_pixel[127] = 0 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /validation_using_modelsim/2nd_STIM_WEIGH_PIX.txt: -------------------------------------------------------------------------------- 1 | # time = 2254000000 | weighted_pixel[0] = 8 | weighted_pixel[1] = 64 | weighted_pixel[2] = 360 | weighted_pixel[3] = 320 | weighted_pixel[4] = 264 | 2 | # weighted_pixel[5] = 10 | weighted_pixel[6] = 272 | weighted_pixel[7] = 8 | weighted_pixel[8] = 8 | weighted_pixel[9] = 320 | weighted_pixel[10] = 0 3 | 4 | # time = 2267000000 | weighted_pixel[11] = 386 | weighted_pixel[12] = 66 | weighted_pixel[13] = 16 | weighted_pixel[14] = 464 | weighted_pixel[15] = 272 | 5 | # weighted_pixel[16] = 402 | weighted_pixel[17] = 146 | weighted_pixel[18] = 402 | weighted_pixel[19] = 80 | weighted_pixel[20] = 0 | weighted_pixel[21] = 0 6 | 7 | # time = 2280000000 | weighted_pixel[22] = 400 | weighted_pixel[23] = 272 | weighted_pixel[24] = 16 | weighted_pixel[25] = 402 | weighted_pixel[26] = 2 | 8 | # weighted_pixel[27] = 128 | weighted_pixel[28] = 416 | weighted_pixel[29] = 258 | weighted_pixel[30] = 256 | weighted_pixel[31] = 32 | weighted_pixel[32] = 0 9 | 10 | # time = 2293000000 | weighted_pixel[33] = 128 | weighted_pixel[34] = 128 | weighted_pixel[35] = 294 | weighted_pixel[36] = 292 | weighted_pixel[37] = 288 | 11 | # weighted_pixel[38] = 2 | weighted_pixel[39] = 294 | weighted_pixel[40] = 36 | weighted_pixel[41] = 0 | weighted_pixel[42] = 256 | weighted_pixel[43] = 256 12 | 13 | # time = 2306000000 | weighted_pixel[44] = 256 | weighted_pixel[45] = 6 | weighted_pixel[46] = 262 | weighted_pixel[47] = 36 | weighted_pixel[48] = 0 | 14 | # weighted_pixel[49] = 292 | weighted_pixel[50] = 290 | weighted_pixel[51] = 262 | weighted_pixel[52] = 38 | weighted_pixel[53] = 256 | weighted_pixel[54] = 0 15 | 16 | # time = 2319000000 | weighted_pixel[55] = 32 | weighted_pixel[56] = 288 | weighted_pixel[57] = 0 | weighted_pixel[58] = 34 | weighted_pixel[59] = 256 | 17 | # weighted_pixel[60] = 290 | weighted_pixel[61] = 256 | weighted_pixel[62] = 0 | weighted_pixel[63] = 384 | weighted_pixel[64] = 128 | weighted_pixel[65] = 256 18 | 19 | # time = 2332000000 | weighted_pixel[66] = 0 | weighted_pixel[67] = 0 | weighted_pixel[68] = 0 | weighted_pixel[69] = 128 | weighted_pixel[70] = 0 | 20 | # weighted_pixel[71] = 128 | weighted_pixel[72] = 136 | weighted_pixel[73] = 8 | weighted_pixel[74] = 0 | weighted_pixel[75] = 0 | weighted_pixel[76] = 256 21 | 22 | # time = 2345000000 | weighted_pixel[77] = 256 | weighted_pixel[78] = 256 | weighted_pixel[79] = 392 | weighted_pixel[80] = 136 | weighted_pixel[81] = 384 | 23 | # weighted_pixel[82] = 136 | weighted_pixel[83] = 136 | weighted_pixel[84] = 392 | weighted_pixel[85] = 384 | weighted_pixel[86] = 264 | weighted_pixel[87] = 256 24 | 25 | # time = 2358000000 | weighted_pixel[88] = 0 | weighted_pixel[89] = 384 | weighted_pixel[90] = 256 | weighted_pixel[91] = 256 | weighted_pixel[92] = 0 | 26 | # weighted_pixel[93] = 384 | weighted_pixel[94] = 0 | weighted_pixel[95] = 0 | weighted_pixel[96] = 384 | weighted_pixel[97] = 256 | weighted_pixel[98] = 0 27 | 28 | # time = 2371000000 | weighted_pixel[99] = 0 | weighted_pixel[100] = 256 | weighted_pixel[101] = 256 | weighted_pixel[102] = 256 | weighted_pixel[103] = 0 | 29 | # weighted_pixel[104] = 256 | weighted_pixel[105] = 0 | weighted_pixel[106] = 0 | weighted_pixel[107] = 256 | weighted_pixel[108] = 256 | weighted_pixel[109] = 0 30 | 31 | # time = 2384000000 | weighted_pixel[110] = 0 | weighted_pixel[111] = 0 | weighted_pixel[112] = 256 | weighted_pixel[113] = 256 | weighted_pixel[114] = 256 | 32 | # weighted_pixel[115] = 0 | weighted_pixel[116] = 256 | weighted_pixel[117] = 0 | weighted_pixel[118] = 0 | weighted_pixel[119] = 256 | weighted_pixel[120] = 256 33 | 34 | # time = 2397000000 | weighted_pixel[121] = 32 | weighted_pixel[122] = 0 | weighted_pixel[123] = 256 | weighted_pixel[124] = 288 | weighted_pixel[125] = 288 | 35 | # weighted_pixel[126] = 0 | weighted_pixel[127] = 256 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /validation_using_modelsim/out_stimulus_sim_rep.txt: -------------------------------------------------------------------------------- 1 | run 2 | # time = 0, out_stimulus = 0 3 | run 4 | # time = 1357000000, out_stimulus = 256 5 | # time = 1359000000, out_stimulus = 768 6 | # time = 1360000000, out_stimulus = 1024 7 | # time = 1364000000, out_stimulus = 1280 8 | # time = 1368000000, out_stimulus = 1536 9 | # time = 1370000000, out_stimulus = 1792 10 | # time = 1374000000, out_stimulus = 2048 11 | # time = 1375000000, out_stimulus = 2304 12 | # time = 1376000000, out_stimulus = 2560 13 | # time = 1380000000, out_stimulus = 2816 14 | # time = 1383000000, out_stimulus = 3072 15 | # time = 1385000000, out_stimulus = 3328 16 | # time = 1386000000, out_stimulus = 3840 17 | # time = 1387000000, out_stimulus = 4096 18 | # time = 1395000000, out_stimulus = 4352 19 | # time = 1396000000, out_stimulus = 4608 20 | # time = 1397000000, out_stimulus = 4864 21 | # time = 1398000000, out_stimulus = 5120 22 | # time = 1402000000, out_stimulus = 5376 23 | # time = 1403000000, out_stimulus = 5632 24 | # time = 1404000000, out_stimulus = 5888 25 | # time = 1407000000, out_stimulus = 6400 26 | # time = 1408000000, out_stimulus = 6656 27 | # time = 1412000000, out_stimulus = 6912 28 | # time = 1414000000, out_stimulus = 7168 29 | # time = 1415000000, out_stimulus = 7680 30 | # time = 1421000000, out_stimulus = 7936 31 | # time = 1422000000, out_stimulus = 8192 32 | # time = 1423000000, out_stimulus = 8448 33 | # time = 1424000000, out_stimulus = 8704 34 | # time = 1425000000, out_stimulus = 8960 35 | # time = 1430000000, out_stimulus = 9216 36 | # time = 1431000000, out_stimulus = 9472 37 | # time = 1435000000, out_stimulus = 9984 38 | # time = 1436000000, out_stimulus = 10240 39 | # time = 1440000000, out_stimulus = 10496 40 | # time = 1442000000, out_stimulus = 10752 41 | # time = 1443000000, out_stimulus = 11008 42 | # time = 1445000000, out_stimulus = 11264 43 | # time = 1450000000, out_stimulus = 11520 44 | # time = 1451000000, out_stimulus = 11776 45 | # time = 1452000000, out_stimulus = 12032 46 | # time = 1453000000, out_stimulus = 12288 47 | # time = 1454000000, out_stimulus = 12544 48 | # time = 1460000000, out_stimulus = 12800 49 | # time = 1462000000, out_stimulus = 13312 50 | # time = 1463000000, out_stimulus = 13568 51 | # time = 1467000000, out_stimulus = 13824 52 | # time = 1471000000, out_stimulus = 14080 53 | # time = 1472000000, out_stimulus = 14336 54 | # time = 1477000000, out_stimulus = 14592 55 | # time = 1478000000, out_stimulus = 14848 56 | # time = 1479000000, out_stimulus = 15104 57 | # time = 1480000000, out_stimulus = 15360 58 | # time = 1483000000, out_stimulus = 15872 59 | # time = 1488000000, out_stimulus = 16128 60 | # time = 1490000000, out_stimulus = 16640 61 | # time = 1491000000, out_stimulus = 16896 ---------------------- 62 | # time = 1494000000, out_stimulus = 17152 63 | # time = 1497000000, out_stimulus = 17408 64 | # time = 1498000000, out_stimulus = 17920 65 | # time = 1499000000, out_stimulus = 18176 66 | run 67 | # time = 2252000000, out_stimulus = 18184 68 | # time = 2253000000, out_stimulus = 17992 69 | # time = 2254000000, out_stimulus = 18672 70 | # time = 2255000000, out_stimulus = 18434 71 | # time = 2256000000, out_stimulus = 18458 72 | # time = 2260000000, out_stimulus = 18210 73 | # time = 2261000000, out_stimulus = 18530 74 | # time = 2262000000, out_stimulus = 18810 75 | # time = 2264000000, out_stimulus = 18940 76 | # time = 2265000000, out_stimulus = 19022 77 | # time = 2266000000, out_stimulus = 19502 78 | # time = 2270000000, out_stimulus = 19648 79 | # time = 2271000000, out_stimulus = 19538 80 | # time = 2272000000, out_stimulus = 19764 81 | # time = 2273000000, out_stimulus = 20180 82 | # time = 2276000000, out_stimulus = 20596 83 | # time = 2279000000, out_stimulus = 20356 84 | # time = 2280000000, out_stimulus = 20758 85 | # time = 2281000000, out_stimulus = 20632 86 | # time = 2282000000, out_stimulus = 20794 87 | # time = 2283000000, out_stimulus = 20826 88 | # time = 2288000000, out_stimulus = 21116 89 | # time = 2291000000, out_stimulus = 20988 90 | # time = 2292000000, out_stimulus = 21154 91 | # time = 2293000000, out_stimulus = 21478 92 | # time = 2294000000, out_stimulus = 21518 93 | # time = 2298000000, out_stimulus = 21298 94 | # time = 2299000000, out_stimulus = 21042 95 | # time = 2300000000, out_stimulus = 21332 96 | # time = 2303000000, out_stimulus = 21082 97 | # time = 2304000000, out_stimulus = 21124 98 | # time = 2308000000, out_stimulus = 20868 99 | # time = 2309000000, out_stimulus = 21160 100 | # time = 2310000000, out_stimulus = 21456 101 | # time = 2311000000, out_stimulus = 21238 102 | # time = 2312000000, out_stimulus = 21400--------- 103 | # time = 2314000000, out_stimulus = 21432 104 | # time = 2317000000, out_stimulus = 21464 105 | # time = 2318000000, out_stimulus = 21208 106 | # time = 2319000000, out_stimulus = 21242 107 | # time = 2320000000, out_stimulus = 21532 108 | # time = 2321000000, out_stimulus = 21660 109 | # time = 2326000000, out_stimulus = 21532 110 | # time = 2327000000, out_stimulus = 21276 111 | # time = 2331000000, out_stimulus = 20892 112 | # time = 2332000000, out_stimulus = 20764 113 | # time = 2336000000, out_stimulus = 20644 114 | # time = 2337000000, out_stimulus = 20652 115 | # time = 2338000000, out_stimulus = 20396 116 | # time = 2339000000, out_stimulus = 20276 117 | # time = 2342000000, out_stimulus = 20924 118 | # time = 2346000000, out_stimulus = 20804 119 | # time = 2347000000, out_stimulus = 20932 120 | # time = 2348000000, out_stimulus = 20948 121 | # time = 2349000000, out_stimulus = 21468 122 | # time = 2350000000, out_stimulus = 21604 123 | # time = 2356000000, out_stimulus = 21732 124 | # time = 2357000000, out_stimulus = 22244 125 | # time = 2358000000, out_stimulus = 22116 126 | # time = 2359000000, out_stimulus = 21860 127 | # time = 2363000000, out_stimulus = 21988 128 | # time = 2364000000, out_stimulus = 22244 129 | # time = 2365000000, out_stimulus = 22500 130 | # time = 2367000000, out_stimulus = 22244 131 | # time = 2368000000, out_stimulus = 22500 132 | # time = 2369000000, out_stimulus = 22756 133 | # time = 2374000000, out_stimulus = 22500 134 | # time = 2376000000, out_stimulus = 22756 135 | # time = 2379000000, out_stimulus = 22244 136 | # time = 2383000000, out_stimulus = 22500 137 | # time = 2385000000, out_stimulus = 22756 138 | # time = 2386000000, out_stimulus = 22500 139 | # time = 2393000000, out_stimulus = 22276 140 | # time = 2394000000, out_stimulus = 22020 141 | # time = 2395000000, out_stimulus = 22340 142 | # time = 2396000000, out_stimulus = 22596 -------------------------------------------------------------------------------- /verilog_codes/RF_generation.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 1ps 2 | 3 | module RF_generation(clk1, reset_an1, pattern); 4 | 5 | reg [7:0] mem[0:783]; 6 | 7 | reg [7:0]region[0:127]; 8 | integer step_region = 0; //step size for iterating over region array 9 | integer region_index; // represents index of the region array 10 | 11 | output reg [127:0]pattern; 12 | integer pat_bit_index; //index of 128-bit pattern array 13 | integer pix_index; // represents index of 8-bit pixel array 14 | 15 | input clk1, reset_an1; //clk1 to wclk in fifo, asynchronous negative reset 16 | 17 | initial 18 | begin 19 | 20 | #10 21 | //$readmemb("\/home\/userdata\/18mvd0072\/thesis\/inputBin5.txt",mem);// reads text file and store it in 22 | //mem array ----------------->(ASIC CHANGES) 23 | $readmemb("C:\\Users\\Rajavarshini\\Desktop\\hardware implementation\\inputBin5.txt",mem);// reads text file and store it in mem array 24 | end 25 | 26 | // **---------------------------------------------------------------------------------------------------** 27 | // ** GENERATING INPUT PATTERN ** 28 | // **---------------------------------------------------------------------------------------------------** 29 | 30 | always @(posedge clk1 or negedge reset_an1) 31 | begin 32 | if (!reset_an1 == 1) 33 | begin 34 | for(region_index = 0;region_index <=127;region_index = region_index + 1) 35 | begin 36 | for(pix_index = 7;pix_index >= 0;pix_index = pix_index - 1) 37 | begin 38 | region[region_index][pix_index] <= 0; 39 | 40 | end 41 | 42 | end 43 | end 44 | else 45 | begin 46 | 47 | 48 | for(region_index = 0;region_index <=127;region_index = region_index + 1) 49 | begin 50 | for(pix_index = 7;pix_index >= 0;pix_index = pix_index - 1) 51 | begin 52 | region[region_index][pix_index] <= mem[region_index + step_region][pix_index]; //In every postive edge of clock, 128 pixels are 53 | //copied to region array 54 | //$display("%b", region[region_index][pix_index]); 55 | end 56 | //$display("%b", region[region_index]); 57 | end 58 | step_region <= step_region + 16; 59 | if (step_region == 784) //16(step size) multiplied by 49 (maximum no. of shift) is 784 60 | begin 61 | 62 | step_region <= 0; 63 | 64 | end 65 | end 66 | 67 | end 68 | /* 69 | always @(posedge clk1 or posedge reset_an1) //NOT SUPPORTED IN FPGA 70 | begin 71 | if (!reset_an1 == 0) 72 | begin 73 | if (step_region == 784) //16(step size) multiplied by 49 (maximum no. of shift) is 784 74 | begin 75 | 76 | step_region <= 0; 77 | 78 | end 79 | end 80 | end 81 | */ 82 | always @(posedge clk1 or negedge reset_an1) 83 | begin 84 | if (!reset_an1 == 1) 85 | begin 86 | for (pat_bit_index = 0;pat_bit_index <= 127;pat_bit_index = pat_bit_index + 1) 87 | begin 88 | pattern[pat_bit_index] <= 0; 89 | end 90 | end 91 | else 92 | begin 93 | 94 | pattern <= {region[0], region[1], region[2], region[3], 95 | region[4], region[5], region[6], region[7], 96 | region[8], region[9], region[10], region[11], 97 | region[12], region[13], region[14], region[15]}; //In every positive edge of clock, 16 pixels are copied to pattern 98 | //$display("%b", pattern); 99 | end 100 | 101 | end 102 | 103 | endmodule -------------------------------------------------------------------------------- /verilog_codes/RF_generation_tb.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 1ps 2 | 3 | module RF_generation_tb(); 4 | /////reg [7:0] mem[0:783]; 5 | /////reg [7:0] region[0:127]; 6 | reg clk1, reset_an1; 7 | 8 | wire [127:0] pattern; 9 | 10 | RF_generation t1(.clk1(clk1), .reset_an1(reset_an1), .pattern(pattern)); 11 | 12 | initial 13 | begin 14 | clk1 = 0; 15 | reset_an1 = 1; 16 | end 17 | 18 | always 19 | begin 20 | #10 clk1 = ~clk1; 21 | end 22 | 23 | endmodule 24 | -------------------------------------------------------------------------------- /verilog_codes/RF_top1.v: -------------------------------------------------------------------------------- 1 | 2 | `timescale 1ns / 1ps 3 | 4 | module RF_top1(clk1, clk2, reset_an1, reset_an2, fifo_readcounter, fifo_writecounter, pattern, fifo_dataout, wfull, rempty, 5 | lfsr_random, out_stimulus, en_lfsr, en_lfsr1, en_lfsr2, en_lfsr3, en_lfsr4, en_lfsr5, en_lfsr6, en_lfsr7, en_lfsr8, 6 | en_lfsr9, en_lfsr10, en_lfsr11); ////, init_lfsr, lfsr_random, adder_out 7 | 8 | // **---------------------------------------------------------------------------------------------------** 9 | // ** DECLARATION AND INITIALIZATION ** 10 | // **---------------------------------------------------------------------------------------------------** 11 | 12 | output [127:0]pattern; 13 | 14 | input clk1, clk2, reset_an1, reset_an2; //asynchronous negative reset 15 | 16 | output [127:0] fifo_dataout; 17 | output wfull, rempty; 18 | output [10:0] lfsr_random; 19 | 20 | //input fifo_write, fifo_read; 21 | input fifo_readcounter;//it is required to get output 22 | input fifo_writecounter;//=4'b0 23 | 24 | input en_lfsr; 25 | input en_lfsr1; 26 | input en_lfsr2; 27 | input en_lfsr3; 28 | input en_lfsr4; 29 | input en_lfsr5; 30 | input en_lfsr6; 31 | input en_lfsr7; 32 | input en_lfsr8; 33 | input en_lfsr9; 34 | input en_lfsr10; 35 | input en_lfsr11; 36 | 37 | output [15:0] out_stimulus; 38 | 39 | // **---------------------------------------------------------------------------------------------------** 40 | // ** GENERATING INPUT PATTERN ** 41 | // **---------------------------------------------------------------------------------------------------** 42 | 43 | RF_generation r1 (.clk1(clk1), .reset_an1(reset_an1), .pattern(pattern)); 44 | 45 | // **---------------------------------------------------------------------------------------------------** 46 | // ** FIFO ** 47 | // **---------------------------------------------------------------------------------------------------** 48 | 49 | fifo1 f1 (.rdata(fifo_dataout), .wfull(wfull), .rempty(rempty), .wdata(pattern), .winc(fifo_writecounter), .wclk(clk1), .wrst_n(reset_an1), 50 | .rinc(fifo_readcounter), .rclk(clk2), .rrst_n(reset_an2));//incomplete port connection 51 | 52 | // **---------------------------------------------------------------------------------------------------** 53 | // ** SHIFT REGISTERS, GLOBAL COUNTER, RANDOM WEIGHT GENERATOR, WEIGHTED PIXEL ARRAY, PARALLEL ADDER ** 54 | // **---------------------------------------------------------------------------------------------------** 55 | 56 | rwg g1 (.clk2(clk2), .en_lfsr(en_lfsr), .en_lfsr1(en_lfsr1), .en_lfsr2(en_lfsr2), .en_lfsr3(en_lfsr3), .en_lfsr4(en_lfsr4), .en_lfsr5(en_lfsr5), 57 | .en_lfsr6(en_lfsr6), .en_lfsr7(en_lfsr7), .en_lfsr8(en_lfsr8), .en_lfsr9(en_lfsr9), .en_lfsr10(en_lfsr10), .en_lfsr11(en_lfsr11), 58 | .lfsr_random(lfsr_random)); 59 | 60 | weigh_pix_par_add w1 (.clk2(clk2), .reset_an2(reset_an2), .fifo_dataout(fifo_dataout), .lfsr_random(lfsr_random), .out_stimulus(out_stimulus)); 61 | 62 | endmodule 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /verilog_codes/RF_top1_tb.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 1ps 2 | 3 | module RF_top1_tb(); 4 | 5 | reg clk1, clk2, reset_an1, reset_an2;//req 6 | //reg [127:0] fifo_read, fifo_write;//read 7 | reg en_lfsr; 8 | reg en_lfsr1; 9 | reg en_lfsr2; 10 | reg en_lfsr3; 11 | reg en_lfsr4; 12 | reg en_lfsr5; 13 | reg en_lfsr6; 14 | reg en_lfsr7; 15 | reg en_lfsr8; 16 | reg en_lfsr9; 17 | reg en_lfsr10; 18 | reg en_lfsr11; 19 | reg fifo_readcounter, fifo_writecounter;//req 20 | 21 | /////wire 22 | wire [127:0] pattern;//req 23 | wire [127:0] fifo_dataout;// 24 | wire wfull, rempty;//req 25 | wire [10:0] lfsr_random;//new 26 | wire [15:0] out_stimulus; 27 | 28 | RF_top1 r1 (.clk1(clk1), .clk2(clk2), .reset_an1(reset_an1), .reset_an2(reset_an2), .fifo_readcounter(fifo_readcounter), .fifo_writecounter(fifo_writecounter), 29 | .pattern(pattern),.en_lfsr(en_lfsr), .en_lfsr1(en_lfsr1), .en_lfsr2(en_lfsr2), .en_lfsr3(en_lfsr3), .en_lfsr4(en_lfsr4), .en_lfsr5(en_lfsr5), .en_lfsr6(en_lfsr6), 30 | .en_lfsr7(en_lfsr7), .en_lfsr8(en_lfsr8), .en_lfsr9(en_lfsr9), .en_lfsr10(en_lfsr10), .en_lfsr11(en_lfsr11), .fifo_dataout(fifo_dataout), .wfull(wfull), .rempty(rempty), 31 | .lfsr_random(lfsr_random), .out_stimulus(out_stimulus)); 32 | 33 | initial 34 | begin 35 | 36 | clk1 = 0; 37 | clk2 = 0; 38 | reset_an1 = 0; 39 | reset_an2 = 0; 40 | //fifo_write = 0; 41 | //fifo_read = 0; 42 | fifo_readcounter = 0; 43 | fifo_writecounter = 0; 44 | 45 | end 46 | 47 | always 48 | begin 49 | #64000 clk1 = ~clk1; 50 | clk2 = 1'b0; 51 | end 52 | 53 | always 54 | begin 55 | #500 clk2 = ~clk2;//64000 / 500 = 128 (can we change it ?) 56 | end 57 | 58 | initial 59 | #5000 reset_an1=1; 60 | 61 | initial 62 | #5000 reset_an2=1; 63 | 64 | initial 65 | #5000 fifo_writecounter=1'b1; 66 | 67 | initial 68 | #50000 fifo_readcounter=1'b1; 69 | /* 70 | initial 71 | begin 72 | #1000000000 $finish; 73 | end 74 | */ 75 | 76 | initial 77 | $monitor( "time = %t, out_stimulus = %d ", $time, out_stimulus); 78 | 79 | initial 80 | begin 81 | //$set_gate_level_monitoring ("on"); 82 | //$set_toggle_region ("r1"); 83 | //$toggle_start(); 84 | //#4000 fifo_write = 1; 85 | //#20000 fifo_read = 1;fifo_write = 0; 86 | //#18000 fifo_read = 0; 87 | #321000; 88 | #128000; 89 | #128000; 90 | #128000; 91 | #128000; 92 | #128000; 93 | #128000; 94 | #128000; 95 | #2000 en_lfsr=0; //$finish; 96 | #1000 en_lfsr=1; 97 | #11000 //$finish; 98 | #1000 en_lfsr1=0; 99 | #1000 en_lfsr1=1; 100 | #11000 //$finish; 101 | #1000 en_lfsr2=0; 102 | #1000 en_lfsr2=1; 103 | #11000 //$finish; 104 | #1000 en_lfsr3=0; 105 | #1000 en_lfsr3=1; 106 | #11000 //$finish; 107 | #1000 en_lfsr4=0; 108 | #1000 en_lfsr4=1; 109 | #11000 //$finish; 110 | #1000 en_lfsr5=0; 111 | #1000 en_lfsr5=1; 112 | #11000 //$finish; 113 | #1000 en_lfsr6=0; 114 | #1000 en_lfsr6=1; 115 | #11000 //$finish; 116 | #1000 en_lfsr7=0; 117 | #1000 en_lfsr7=1; 118 | #11000 //$finish; 119 | #1000 en_lfsr8=0; 120 | #1000 en_lfsr8=1; 121 | #11000 //$finish; 122 | #1000 en_lfsr9=0; 123 | #1000 en_lfsr9=1; 124 | #11000 //$finish; 125 | #1000 en_lfsr10=0; 126 | #1000 en_lfsr10=1; 127 | #11000 //$finish; 128 | #1000 en_lfsr11=0; 129 | #1000 en_lfsr11=1; 130 | #8000; 131 | 132 | #4000; 133 | 134 | 135 | #98000; 136 | #128000; 137 | #128000; 138 | #128000; 139 | #128000; 140 | #128000; 141 | #128000; 142 | 143 | 144 | #2000 en_lfsr=0; //$finish; 145 | #1000 en_lfsr=1; 146 | #11000 //$finish; 147 | #1000 en_lfsr1=0; 148 | #1000 en_lfsr1=1; 149 | #11000 //$finish; 150 | #1000 en_lfsr2=0; 151 | #1000 en_lfsr2=1; 152 | #11000 //$finish; 153 | #1000 en_lfsr3=0; 154 | #1000 en_lfsr3=1; 155 | #11000 //$finish; 156 | #1000 en_lfsr4=0; 157 | #1000 en_lfsr4=1; 158 | #11000 //$finish; 159 | #1000 en_lfsr5=0; 160 | #1000 en_lfsr5=1; 161 | #11000 //$finish; 162 | #1000 en_lfsr6=0; 163 | #1000 en_lfsr6=1; 164 | #11000 //$finish; 165 | #1000 en_lfsr7=0; 166 | #1000 en_lfsr7=1; 167 | #11000 //$finish; 168 | #1000 en_lfsr8=0; 169 | #1000 en_lfsr8=1; 170 | #11000 //$finish; 171 | #1000 en_lfsr9=0; 172 | #1000 en_lfsr9=1; 173 | #11000 //$finish; 174 | #1000 en_lfsr10=0; 175 | #1000 en_lfsr10=1; 176 | #11000 //$finish; 177 | #1000 en_lfsr11=0; 178 | #1000 en_lfsr11=1; 179 | #8000; 180 | 181 | #4000; 182 | 183 | end 184 | 185 | 186 | //$toggle_stop; 187 | //$toggle_report ("RF_top2.saif", 1.0e-9, "t1"); 188 | 189 | 190 | 191 | 192 | endmodule 193 | 194 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /verilog_codes/fifo1.v: -------------------------------------------------------------------------------- 1 | module fifo1 (rdata, wfull, rempty, wdata, winc, wclk, wrst_n, rinc, rclk, rrst_n); 2 | 3 | parameter DSIZE = 128; 4 | parameter ASIZE = 9; // 2^9 = 512 5 | 6 | output [DSIZE-1:0] rdata;//fifo dataout 7 | output wfull; 8 | output rempty; 9 | 10 | input [DSIZE-1:0] wdata;//fifo datain 11 | input winc, wclk, wrst_n;//winc = fifo_writecounter, clk1 12 | input rinc, rclk, rrst_n;//rinc = fifo_readcounter 13 | 14 | wire [ASIZE-1:0] waddr, raddr; 15 | wire [ASIZE:0] wptr, rptr, wq2_rptr, rq2_wptr; 16 | 17 | sync_r2w sync_r2w (.wq2_rptr(wq2_rptr), .rptr(rptr), .wclk(wclk), .wrst_n(wrst_n)); 18 | 19 | sync_w2r sync_w2r (.rq2_wptr(rq2_wptr), .wptr(wptr), .rclk(rclk), .rrst_n(rrst_n)); 20 | 21 | fifomem fifomem (.rdata(rdata), .wdata(wdata), .waddr(waddr), .raddr(raddr), .wclken(winc), .wfull(wfull), .wclk(wclk)); 22 | 23 | rptr_empty rptr_empty (.rempty(rempty), .raddr(raddr), .rptr(rptr), .rq2_wptr(rq2_wptr), .rinc(rinc), .rclk(rclk), .rrst_n(rrst_n)); 24 | 25 | wptr_full wptr_full (.wfull(wfull), .waddr(waddr), .wptr(wptr), .wq2_rptr(wq2_rptr), .winc(winc), .wclk(wclk), .wrst_n(wrst_n)); 26 | 27 | endmodule -------------------------------------------------------------------------------- /verilog_codes/fifo1_tb.v: -------------------------------------------------------------------------------- 1 | module fifo1_tb(); 2 | reg wclk,rclk; 3 | reg[127:0] wdata; 4 | wire[127:0] rdata; 5 | wire rempty,wfull; 6 | reg rrst_n; 7 | reg wrst_n; 8 | reg winc,rinc; 9 | fifo1 f1(.wdata(wdata), 10 | .rdata(rdata), 11 | .wclk(wclk), 12 | .rclk(rclk), 13 | .wrst_n(wrst_n), 14 | .rrst_n(rrst_n), 15 | .winc(winc) , 16 | .rinc(rinc), 17 | .rempty(rempty), 18 | .wfull(wfull)); 19 | initial 20 | begin 21 | #0 wdata=8'h0; 22 | #128_000 wdata=8'h1; // DATA WHICH IS SUPPLIED 23 | #128_000 wdata=8'h2; 24 | #128_000 wdata=8'h3; 25 | #128_000 wdata=8'h4; 26 | #128_000 wdata=8'h5; 27 | #128_000 wdata=8'h6; 28 | #128_000 wdata=8'h7; 29 | #128_000 wdata=8'h8; 30 | #128_000 wdata=8'h9; 31 | #128_000 wdata=8'hA; 32 | #128_000 wdata=8'hB; 33 | #128_000 wdata=8'hC; 34 | #128_000 wdata=8'hD; 35 | #128_000 wdata=8'hE; 36 | #128_000 wdata=8'hF; 37 | #128_000 wdata=8'h10; 38 | #128_000 wdata=8'h11; 39 | #128_000 wdata=8'h12; 40 | #128_000 wdata=8'h13; 41 | #128_000 wdata=8'h14; 42 | #128_000 wdata=8'h15; 43 | #128_000 wdata=8'h16; 44 | #128_000 wdata=8'h17; // DATA WHICH IS SUPPLIED 45 | #128_000 wdata=8'h18; 46 | #128_000 wdata=8'h19; 47 | #128_000 wdata=8'h1A; 48 | #128_000 wdata=8'h1B; 49 | #128_000 wdata=8'h1C; 50 | #128_000 wdata=8'h1D; 51 | #128_000 wdata=8'h1E; 52 | #128_000 wdata=8'h1F; 53 | #128_000 wdata=8'h20; 54 | #128_000 wdata=8'h21; 55 | #128_000 wdata=8'h22; 56 | #128_000 wdata=8'h23; 57 | #128_000 wdata=8'h24; 58 | #128_000 wdata=8'h25; 59 | #128_000 wdata=8'h26; 60 | #128_000 wdata=8'h27; 61 | #128_000 wdata=8'h28; 62 | #128_000 wdata=8'h29; 63 | #128_000 wdata=8'h2A; 64 | #128_000 wdata=8'h2B; 65 | #128_000 wdata=8'h2C; 66 | #128_000 wdata=8'h2D; 67 | #128_000 wdata=8'h2E; 68 | #128_000 wdata=8'h2F; 69 | #128_000 wdata=8'h30; 70 | #128_000 wdata=8'h31; 71 | #128_000 wdata=8'h32; 72 | #128_000 wdata=8'h33; // DATA WHICH IS SUPPLIED 73 | #128_000 wdata=8'h34; 74 | #128_000 wdata=8'h35; 75 | #128_000 wdata=8'h36; 76 | #128_000 wdata=8'h37; 77 | #128_000 wdata=8'h38; 78 | #128_000 wdata=8'h39; 79 | #128_000 wdata=8'h3A; 80 | #128_000 wdata=8'h3B; 81 | #128_000 wdata=8'h3C; 82 | #128_000 wdata=8'h3D; 83 | #128_000 wdata=8'h3E; 84 | #128_000 wdata=8'h3F; 85 | #128_000 wdata=8'h40; 86 | #128_000 wdata=8'h41; 87 | #128_000 wdata=8'h42; 88 | #128_000 wdata=8'h43; 89 | #128_000 wdata=8'h44; 90 | #128_000 wdata=8'h45; 91 | #128_000 wdata=8'h46; 92 | #128_000 wdata=8'h47; 93 | #128_000 wdata=8'h48; 94 | #128_000 wdata=8'h49; // DATA WHICH IS SUPPLIED 95 | #128_000 wdata=8'h4A; 96 | #128_000 wdata=8'h4B; 97 | #128_000 wdata=8'h4C; 98 | #128_000 wdata=8'h4D; 99 | #128_000 wdata=8'h4E; 100 | #128_000 wdata=8'h4F; 101 | #128_000 wdata=8'h50; 102 | #128_000 wdata=8'h51; 103 | #128_000 wdata=8'h52; 104 | #128_000 wdata=8'h53; 105 | #128_000 wdata=8'h54; 106 | #128_000 wdata=8'h55; 107 | #128_000 wdata=8'h56; 108 | #128_000 wdata=8'h57; 109 | #128_000 wdata=8'h58; 110 | #128_000 wdata=8'h59; 111 | #128_000 wdata=8'h5A; 112 | #128_000 wdata=8'h5B; 113 | #128_000 wdata=8'h5C; 114 | #128_000 wdata=8'h5D; 115 | #128_000 wdata=8'h5E; 116 | #128_000 wdata=8'h5F; 117 | #128_000 wdata=8'h60; 118 | #128_000 wdata=8'h61; 119 | #128_000 wdata=8'h62; 120 | #128_000 wdata=8'h63; 121 | #128_000 wdata=8'h64; 122 | #128_000 wdata=8'h65; // DATA WHICH IS SUPPLIED 123 | #128_000 wdata=8'h66; 124 | #128_000 wdata=8'h67; 125 | #128_000 wdata=8'h68; 126 | #128_000 wdata=8'h69; 127 | #128_000 wdata=8'h6A; 128 | #128_000 wdata=8'h6B; 129 | #128_000 wdata=8'h6C; 130 | #128_000 wdata=8'h6D; 131 | #128_000 wdata=8'h6E; 132 | #128_000 wdata=8'h6F; 133 | #128_000 wdata=8'h70; 134 | #128_000 wdata=8'h71; 135 | #128_000 wdata=8'h72; 136 | #128_000 wdata=8'h73; 137 | #128_000 wdata=8'h74; 138 | #128_000 wdata=8'h75; 139 | #128_000 wdata=8'h76; 140 | #128_000 wdata=8'h77; 141 | #128_000 wdata=8'h78; 142 | #128_000 wdata=8'h79; 143 | #128_000 wdata=8'h7A; 144 | #128_000 wdata=8'h7B; 145 | #128_000 wdata=8'h7C; 146 | #128_000 wdata=8'h7D; 147 | #128_000 wdata=8'h7E; 148 | #128_000 wdata=8'h7F; 149 | #128_000 wdata=8'h80; 150 | #128_000 wdata=8'h81; // DATA WHICH IS SUPPLIED 151 | #128_000 wdata=8'h82; 152 | #128_000 wdata=8'h83; 153 | #128_000 wdata=8'h84; 154 | #128_000 wdata=8'h85; 155 | #128_000 wdata=8'h86; 156 | #128_000 wdata=8'h87; 157 | #128_000 wdata=8'h88; 158 | #128_000 wdata=8'h89; 159 | #128_000 wdata=8'h8A; 160 | #128_000 wdata=8'h8B; 161 | #128_000 wdata=8'h8C; 162 | #128_000 wdata=8'h8D; 163 | #128_000 wdata=8'h8E; 164 | #128_000 wdata=8'h8F; 165 | #128_000 wdata=8'h90; 166 | #128_000 wdata=8'h91; 167 | #128_000 wdata=8'h92; 168 | #128_000 wdata=8'h93; 169 | #128_000 wdata=8'h94; 170 | #128_000 wdata=8'h95; 171 | #128_000 wdata=8'h96; 172 | #128_000 wdata=8'h97; // DATA WHICH IS SUPPLIED 173 | #128_000 wdata=8'h98; 174 | #128_000 wdata=8'h99; 175 | #128_000 wdata=8'h9A; 176 | #128_000 wdata=8'h9B; 177 | #128_000 wdata=8'h9C; 178 | #128_000 wdata=8'h9D; 179 | #128_000 wdata=8'h9E; 180 | #128_000 wdata=8'h9F; 181 | #128_000 wdata=8'hA0; 182 | #128_000 wdata=8'hA1; 183 | #128_000 wdata=8'hA2; 184 | #128_000 wdata=8'hA3; 185 | #128_000 wdata=8'hA4; 186 | #128_000 wdata=8'hA5; 187 | #128_000 wdata=8'hA6; 188 | #128_000 wdata=8'hA7; // DATA WHICH IS SUPPLIED 189 | #128_000 wdata=8'hA8; 190 | #128_000 wdata=8'hA9; 191 | #128_000 wdata=8'hAA; 192 | #128_000 wdata=8'hAB; 193 | #128_000 wdata=8'hAC; 194 | #128_000 wdata=8'hAD; 195 | #128_000 wdata=8'hAE; 196 | #128_000 wdata=8'hAF; 197 | #128_000 wdata=8'hB0; 198 | #128_000 wdata=8'hB1; 199 | #128_000 wdata=8'hB2; 200 | #128_000 wdata=8'hB3; 201 | #128_000 wdata=8'hB4; 202 | #128_000 wdata=8'hB5; 203 | #128_000 wdata=8'hB6; 204 | #128_000 wdata=8'hB7; // DATA WHICH IS SUPPLIED 205 | #128_000 wdata=8'hB8; 206 | #128_000 wdata=8'hB9; 207 | #128_000 wdata=8'hBA; 208 | #128_000 wdata=8'hBB; 209 | #128_000 wdata=8'hBC; 210 | #128_000 wdata=8'hBD; 211 | #128_000 wdata=8'hBE; 212 | #128_000 wdata=8'hBF; 213 | #128_000 wdata=8'hC0; 214 | #128_000 wdata=8'hC1; 215 | #128_000 wdata=8'hC2; 216 | #128_000 wdata=8'hC3; 217 | #128_000 wdata=8'hC4; 218 | #128_000 wdata=8'hC5; 219 | #128_000 wdata=8'hC6; 220 | #128_000 wdata=8'hC7; // DATA WHICH IS SUPPLIED 221 | #128_000 wdata=8'hC8; 222 | #128_000 wdata=8'hC9; 223 | #128_000 wdata=8'hCA; 224 | #128_000 wdata=8'hCB; 225 | #128_000 wdata=8'hCC; 226 | #128_000 wdata=8'hCD; 227 | #128_000 wdata=8'hCE; 228 | #128_000 wdata=8'hCF; 229 | #128_000 wdata=8'hD0; 230 | #128_000 wdata=8'hD1; 231 | #128_000 wdata=8'hD2; 232 | #128_000 wdata=8'hD3; 233 | #128_000 wdata=8'hD4; 234 | #128_000 wdata=8'hD5; 235 | #128_000 wdata=8'hD6; 236 | #128_000 wdata=8'hD7; // DATA WHICH IS SUPPLIED 237 | #128_000 wdata=8'hD8; 238 | #128_000 wdata=8'hD9; 239 | #128_000 wdata=8'hDA; 240 | #128_000 wdata=8'hDB; 241 | #128_000 wdata=8'hDC; 242 | #128_000 wdata=8'hDD; 243 | #128_000 wdata=8'hDE; 244 | #128_000 wdata=8'hDF; 245 | #128_000 wdata=8'hE0; 246 | #128_000 wdata=8'hE1; 247 | #128_000 wdata=8'hE2; 248 | #128_000 wdata=8'hE3; 249 | #128_000 wdata=8'hE4; 250 | #128_000 wdata=8'hE5; 251 | #128_000 wdata=8'hE6; 252 | #128_000 wdata=8'hE7; // DATA WHICH IS SUPPLIED 253 | #128_000 wdata=8'hE8; 254 | #128_000 wdata=8'hE9; 255 | #128_000 wdata=8'hEA; 256 | #128_000 wdata=8'hEB; 257 | #128_000 wdata=8'hEC; 258 | #128_000 wdata=8'hED; 259 | #128_000 wdata=8'hEE; 260 | #128_000 wdata=8'hEF; 261 | #128_000 wdata=8'hF0; 262 | #128_000 wdata=8'hF1; 263 | #128_000 wdata=8'hF2; 264 | #128_000 wdata=8'hF3; 265 | #128_000 wdata=8'hF4; 266 | #128_000 wdata=8'hF5; 267 | #128_000 wdata=8'hF6; 268 | #128_000 wdata=8'hF7; // DATA WHICH IS SUPPLIED 269 | #128_000 wdata=8'hF8; 270 | #128_000 wdata=8'hF9; 271 | #128_000 wdata=8'hFA; 272 | #128_000 wdata=8'hFB; 273 | #128_000 wdata=8'hFC; 274 | #128_000 wdata=8'hFD; 275 | #128_000 wdata=8'hFE; 276 | #128_000 wdata=8'hFF; 277 | #128_000 wdata=12'h100; 278 | #128_000 wdata=12'h101; 279 | #128_000 wdata=12'h102; 280 | #128_000 wdata=12'h103; 281 | #128_000 wdata=12'h104; 282 | #128_000 wdata=12'h105; 283 | #128_000 wdata=12'h106; 284 | #128_000 wdata=12'h107; 285 | #128_000 wdata=12'h108; 286 | #128_000 wdata=12'h109; 287 | #128_000 wdata=12'h10A; 288 | #128_000 wdata=12'h10B; 289 | #128_000 wdata=12'h10C; 290 | #128_000 wdata=12'h10D; 291 | #128_000 wdata=12'h10E; 292 | #128_000 wdata=12'h10F; 293 | #128_000 wdata=12'h110; 294 | #128_000 wdata=12'h111; 295 | #128_000 wdata=12'h112; 296 | #128_000 wdata=12'h113; // DATA WHICH IS SUPPLIED 297 | #128_000 wdata=12'h114; 298 | #128_000 wdata=12'h115; 299 | #128_000 wdata=12'h116; 300 | #128_000 wdata=12'h117; 301 | #128_000 wdata=12'h118; 302 | #128_000 wdata=12'h119; 303 | #128_000 wdata=12'h11A; 304 | #128_000 wdata=12'h11B; 305 | #128_000 wdata=12'h11C; 306 | #128_000 wdata=12'h11D; 307 | #128_000 wdata=12'h11E; 308 | #128_000 wdata=12'h11F; 309 | #128_000 wdata=12'h120; 310 | #128_000 wdata=12'h121; 311 | #128_000 wdata=12'h122; 312 | #128_000 wdata=12'h123; 313 | #128_000 wdata=12'h124; 314 | #128_000 wdata=12'h125; 315 | #128_000 wdata=12'h126; 316 | #128_000 wdata=12'h127; 317 | #128_000 wdata=12'h128; 318 | #128_000 wdata=12'h129; // DATA WHICH IS SUPPLIED 319 | #128_000 wdata=12'h12A; 320 | #128_000 wdata=12'h12B; 321 | #128_000 wdata=12'h12C; 322 | #128_000 wdata=12'h12D; 323 | #128_000 wdata=12'h12E; 324 | #128_000 wdata=12'h12F; 325 | #128_000 wdata=12'h130; 326 | #128_000 wdata=12'h131; 327 | #128_000 wdata=12'h132; 328 | #128_000 wdata=12'h133; 329 | #128_000 wdata=12'h134; 330 | #128_000 wdata=12'h135; 331 | #128_000 wdata=12'h136; 332 | #128_000 wdata=12'h137; 333 | #128_000 wdata=12'h138; 334 | #128_000 wdata=12'h139; 335 | #128_000 wdata=12'h13A; 336 | #128_000 wdata=12'h13B; 337 | #128_000 wdata=12'h13C; 338 | #128_000 wdata=12'h13D; 339 | #128_000 wdata=12'h13E; 340 | #128_000 wdata=12'h13F; 341 | #128_000 wdata=12'h140; 342 | #128_000 wdata=12'h141; 343 | #128_000 wdata=12'h142; 344 | #128_000 wdata=12'h143; 345 | #128_000 wdata=12'h144; 346 | #128_000 wdata=12'h145; // DATA WHICH IS SUPPLIED 347 | #128_000 wdata=12'h146; 348 | #128_000 wdata=12'h147; 349 | #128_000 wdata=12'h148; 350 | #128_000 wdata=12'h149; 351 | #128_000 wdata=12'h14A; 352 | #128_000 wdata=12'h14B; 353 | #128_000 wdata=12'h14C; 354 | #128_000 wdata=12'h14D; 355 | #128_000 wdata=12'h14E; 356 | #128_000 wdata=12'h14F; 357 | #128_000 wdata=12'h150; 358 | #128_000 wdata=12'h151; 359 | #128_000 wdata=12'h152; 360 | #128_000 wdata=12'h153; 361 | #128_000 wdata=12'h154; 362 | #128_000 wdata=12'h155; 363 | #128_000 wdata=12'h156; 364 | #128_000 wdata=12'h157; 365 | #128_000 wdata=12'h158; 366 | #128_000 wdata=12'h159; 367 | #128_000 wdata=12'h15A; 368 | #128_000 wdata=12'h15B; 369 | #128_000 wdata=12'h15C; 370 | #128_000 wdata=12'h15D; 371 | #128_000 wdata=12'h15E; 372 | #128_000 wdata=12'h15F; 373 | #128_000 wdata=12'h160; 374 | #128_000 wdata=12'h161; // DATA WHICH IS SUPPLIED 375 | #128_000 wdata=12'h162; 376 | #128_000 wdata=12'h163; 377 | #128_000 wdata=12'h164; 378 | #128_000 wdata=12'h165; 379 | #128_000 wdata=12'h166; 380 | #128_000 wdata=12'h167; 381 | #128_000 wdata=12'h168; 382 | #128_000 wdata=12'h169; 383 | #128_000 wdata=12'h16A; 384 | #128_000 wdata=12'h16B; 385 | #128_000 wdata=12'h16C; 386 | #128_000 wdata=12'h16D; 387 | #128_000 wdata=12'h16E; 388 | #128_000 wdata=12'h16F; 389 | #128_000 wdata=12'h170; 390 | #128_000 wdata=12'h171; 391 | #128_000 wdata=12'h172; 392 | #128_000 wdata=12'h173; 393 | #128_000 wdata=12'h174; 394 | #128_000 wdata=12'h175; 395 | #128_000 wdata=12'h176; // DATA WHICH IS SUPPLIED 396 | #128_000 wdata=12'h177; 397 | #128_000 wdata=12'h178; 398 | #128_000 wdata=12'h179; 399 | #128_000 wdata=12'h17A; 400 | #128_000 wdata=12'h17B; 401 | #128_000 wdata=12'h17C; 402 | #128_000 wdata=12'h17D; 403 | #128_000 wdata=12'h17E; 404 | #128_000 wdata=12'h17F; 405 | #128_000 wdata=12'h180; 406 | #128_000 wdata=12'h181; 407 | #128_000 wdata=12'h182; 408 | #128_000 wdata=12'h183; 409 | #128_000 wdata=12'h184; 410 | #128_000 wdata=12'h185; 411 | #128_000 wdata=12'h186; 412 | #128_000 wdata=12'h187; 413 | #128_000 wdata=12'h188; 414 | #128_000 wdata=12'h189; 415 | #128_000 wdata=12'h18A; 416 | #128_000 wdata=12'h18B; 417 | #128_000 wdata=12'h18C; 418 | #128_000 wdata=12'h18D; 419 | #128_000 wdata=12'h18E; 420 | #128_000 wdata=12'h18F; 421 | #128_000 wdata=12'h190; 422 | #128_000 wdata=12'h191; 423 | #128_000 wdata=12'h192; // DATA WHICH IS SUPPLIED 424 | #128_000 wdata=12'h193; 425 | #128_000 wdata=12'h194; 426 | #128_000 wdata=12'h195; 427 | #128_000 wdata=12'h196; 428 | #128_000 wdata=12'h197; 429 | #128_000 wdata=12'h198; 430 | #128_000 wdata=12'h199; 431 | #128_000 wdata=12'h19A; 432 | #128_000 wdata=12'h19B; 433 | #128_000 wdata=12'h19C; 434 | #128_000 wdata=12'h19D; 435 | #128_000 wdata=12'h19E; 436 | #128_000 wdata=12'h19F; 437 | #128_000 wdata=12'h1A0; 438 | #128_000 wdata=12'h1A1; 439 | #128_000 wdata=12'h1A2; 440 | #128_000 wdata=12'h1A3; 441 | #128_000 wdata=12'h1A4; 442 | #128_000 wdata=12'h1A5; 443 | #128_000 wdata=12'h1A6; 444 | #128_000 wdata=12'h1A7; // DATA WHICH IS SUPPLIED 445 | #128_000 wdata=12'h1A8; 446 | #128_000 wdata=12'h1A9; 447 | #128_000 wdata=12'h1AA; 448 | #128_000 wdata=12'h1AB; 449 | #128_000 wdata=12'h1AC; 450 | #128_000 wdata=12'h1AD; 451 | #128_000 wdata=12'h1AE; 452 | #128_000 wdata=12'h1AF; 453 | #128_000 wdata=12'h1B0; 454 | #128_000 wdata=12'h1B1; 455 | #128_000 wdata=12'h1B2; 456 | #128_000 wdata=12'h1B3; 457 | #128_000 wdata=12'h1B4; 458 | #128_000 wdata=12'h1B5; 459 | #128_000 wdata=12'h1B6; 460 | #128_000 wdata=12'h1B7; // DATA WHICH IS SUPPLIED 461 | #128_000 wdata=12'h1B8; 462 | #128_000 wdata=12'h1B9; 463 | #128_000 wdata=12'h1BA; 464 | #128_000 wdata=12'h1BB; 465 | #128_000 wdata=12'h1BC; 466 | #128_000 wdata=12'h1BD; 467 | #128_000 wdata=12'h1BE; 468 | #128_000 wdata=12'h1BF; 469 | #128_000 wdata=12'h1C0; 470 | #128_000 wdata=12'h1C1; 471 | #128_000 wdata=12'h1C2; 472 | #128_000 wdata=12'h1C3; 473 | #128_000 wdata=12'h1C4; 474 | #128_000 wdata=12'h1C5; 475 | #128_000 wdata=12'h1C6; 476 | #128_000 wdata=12'h1C7; // DATA WHICH IS SUPPLIED 477 | #128_000 wdata=12'h1C8; 478 | #128_000 wdata=12'h1C9; 479 | #128_000 wdata=12'h1CA; 480 | #128_000 wdata=12'h1CB; 481 | #128_000 wdata=12'h1CC; 482 | #128_000 wdata=12'h1CD; 483 | #128_000 wdata=12'h1CE; 484 | #128_000 wdata=12'h1CF; 485 | #128_000 wdata=12'h1D0; 486 | #128_000 wdata=12'h1D1; 487 | #128_000 wdata=12'h1D2; 488 | #128_000 wdata=12'h1D3; 489 | #128_000 wdata=12'h1D4; 490 | #128_000 wdata=12'h1D5; 491 | #128_000 wdata=12'h1D6; 492 | #128_000 wdata=12'h1D7; // DATA WHICH IS SUPPLIED 493 | #128_000 wdata=12'h1D8; 494 | #128_000 wdata=12'h1D9; 495 | #128_000 wdata=12'h1DA; 496 | #128_000 wdata=12'h1DB; 497 | #128_000 wdata=12'h1DC; 498 | #128_000 wdata=12'h1DD; 499 | #128_000 wdata=12'h1DE; 500 | #128_000 wdata=12'h1DF; 501 | #128_000 wdata=12'h1E0; 502 | #128_000 wdata=12'h1E1; 503 | #128_000 wdata=12'h1E2; 504 | #128_000 wdata=12'h1E3; 505 | #128_000 wdata=12'h1E4; 506 | #128_000 wdata=12'h1E5; 507 | #128_000 wdata=12'h1E6; 508 | #128_000 wdata=12'h1E7; // DATA WHICH IS SUPPLIED 509 | #128_000 wdata=12'h1E8; 510 | #128_000 wdata=12'h1E9; 511 | #128_000 wdata=12'h1EA; 512 | #128_000 wdata=12'h1EB; 513 | #128_000 wdata=12'h1EC; 514 | #128_000 wdata=12'h1ED; 515 | #128_000 wdata=12'h1EE; 516 | #128_000 wdata=12'h1EF; 517 | #128_000 wdata=12'h1F0; 518 | #128_000 wdata=12'h1F1; 519 | #128_000 wdata=12'h1F2; 520 | #128_000 wdata=12'h1F3; 521 | #128_000 wdata=12'h1F4; 522 | #128_000 wdata=12'h1F5; 523 | #128_000 wdata=12'h1F6; 524 | #128_000 wdata=12'h1F7; // DATA WHICH IS SUPPLIED 525 | #128_000 wdata=12'h1F8; 526 | #128_000 wdata=12'h1F9; 527 | #128_000 wdata=12'h1FA; 528 | #128_000 wdata=12'h1FB; 529 | #128_000 wdata=12'h1FC; 530 | #128_000 wdata=12'h1FD; 531 | #128_000 wdata=12'h1FE; 532 | #128_000 wdata=12'h1FF; 533 | #128_000 wdata=12'h200; 534 | $finish; 535 | end 536 | 537 | initial 538 | begin 539 | wclk=1'b0; 540 | winc=1'b0; 541 | rinc=1'b0; 542 | end 543 | 544 | //initial 545 | always 546 | begin 547 | #64000 wclk=~wclk; //end // READ AND WRITE CLOCK GENERATION 548 | rclk=1'b0; 549 | end 550 | 551 | //initial 552 | //begin 553 | always 554 | #500 rclk=~rclk; 555 | //end 556 | 557 | initial 558 | rrst_n=1'b0; 559 | //begin 560 | 561 | initial 562 | #5000 rrst_n=1'b1; 563 | //end 564 | 565 | initial 566 | wrst_n =1'b0; 567 | 568 | initial 569 | #5000 wrst_n=1'b1; 570 | 571 | initial 572 | #5000 winc=1'b1; 573 | 574 | initial 575 | # 50000 rinc=1'b1; 576 | 577 | //initial 578 | //begin 579 | //#1000000000 $finish; 580 | //end 581 | 582 | initial 583 | $monitor( "$time wdata, rdata = %d %d",$time, wdata, rdata); 584 | 585 | endmodule -------------------------------------------------------------------------------- /verilog_codes/fifomem.v: -------------------------------------------------------------------------------- 1 | module fifomem (rdata, wdata, waddr, raddr, wclken, wfull, wclk); 2 | 3 | parameter ADDRSIZE = 9; // Number of mem address bits 4 | parameter DATASIZE = 128; // Memory data word width 5 | 6 | output [DATASIZE-1:0] rdata; 7 | input [DATASIZE-1:0] wdata; 8 | input [ADDRSIZE-1:0] waddr, raddr; 9 | input wclken, wfull, wclk; 10 | //`ifdef VENDORRAM 11 | // instantiation of a vendor's dual-port RAM 12 | //vendor_ram mem (.dout(rdata), .din(wdata), 13 | //.waddr(waddr), .raddr(raddr), 14 | //.wclken(wclken), 15 | //.wclken_n(wfull), .clk(wclk)); 16 | //`else 17 | // RTL Verilog memory model 18 | localparam DEPTH = 1<=24 && wt_pix <= 34 : begin 282 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], 283 | shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 284 | //$display("%b", weighted_pixel[wt_pix_pos]); 285 | wt_pix_pos <= wt_pix_pos + 1; 286 | end 287 | wt_pix >=37 && wt_pix <= 47 : begin 288 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], 289 | shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 290 | //$display("%b", weighted_pixel[wt_pix_pos]); 291 | wt_pix_pos <= wt_pix_pos + 1; 292 | end 293 | wt_pix >=50 && wt_pix <= 60 : begin 294 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], 295 | shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 296 | //$display("%b", weighted_pixel[wt_pix_pos]); 297 | wt_pix_pos <= wt_pix_pos + 1; 298 | end 299 | wt_pix >=63 && wt_pix <= 73 : begin 300 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], 301 | shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 302 | //$display("%b", weighted_pixel[wt_pix_pos]); 303 | wt_pix_pos <= wt_pix_pos + 1; 304 | end 305 | wt_pix >=76 && wt_pix <= 86 : begin 306 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 307 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 308 | //$display("%b", weighted_pixel[wt_pix_pos]); 309 | wt_pix_pos <= wt_pix_pos + 1; 310 | end 311 | wt_pix >=89 && wt_pix <= 99 : begin 312 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 313 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 314 | //$display("%b", weighted_pixel[wt_pix_pos]); 315 | wt_pix_pos <= wt_pix_pos + 1; 316 | end 317 | wt_pix >=102 && wt_pix <= 112 : begin 318 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 319 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 320 | //$display("%b", weighted_pixel[wt_pix_pos]); 321 | wt_pix_pos <= wt_pix_pos + 1; 322 | end 323 | wt_pix >=115 && wt_pix <= 125 : begin 324 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 325 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 326 | //$display("%b", weighted_pixel[wt_pix_pos]); 327 | wt_pix_pos <= wt_pix_pos + 1; 328 | end 329 | wt_pix >=128 && wt_pix <= 138 : begin 330 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 331 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 332 | //$display("%b", weighted_pixel[wt_pix_pos]); 333 | wt_pix_pos <= wt_pix_pos + 1; 334 | end 335 | wt_pix >=141 && wt_pix <= 151 : begin 336 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 337 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 338 | //$display("%b", weighted_pixel[wt_pix_pos]); 339 | wt_pix_pos <= wt_pix_pos + 1; 340 | end 341 | wt_pix >=154 && wt_pix <= 164 : begin 342 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 343 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 344 | //$display("%b", weighted_pixel[wt_pix_pos]); 345 | wt_pix_pos <= wt_pix_pos + 1; 346 | end 347 | wt_pix >=167 && wt_pix <= 173 : begin 348 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], 349 | shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 350 | //$display("%b", weighted_pixel[wt_pix_pos]); 351 | wt_pix_pos <= wt_pix_pos + 1; 352 | end 353 | default : begin 354 | //weighted_pixel[wt_pix_pos] <= 9'bx; 355 | //$display(" "); 356 | //wt_pix_pos <= 9'bx; 357 | end 358 | endcase 359 | 360 | end 361 | 362 | end 363 | 364 | // **---------------------------------------------------------------------------------------------------** 365 | // ** PARALLEL ADDER ** 366 | // **---------------------------------------------------------------------------------------------------** 367 | 368 | always @(posedge clk2 or negedge reset_an2) 369 | begin 370 | if (!reset_an2 == 1) 371 | begin 372 | sum00 <= 0; 373 | sum01 <= 0; 374 | sum02 <= 0; 375 | sum03 <= 0; 376 | end 377 | else 378 | begin 379 | sum00 <= weighted_pixel[0] + weighted_pixel[1]+weighted_pixel[2]; 380 | sum01 <= sum00 + weighted_pixel[3]+weighted_pixel[4]; 381 | sum02 <= sum01+ weighted_pixel[5]+weighted_pixel[6]; 382 | sum03 <= sum02 + weighted_pixel[7]; 383 | 384 | //$display ("%b", sum01); 385 | end 386 | end 387 | 388 | always @(posedge clk2 or negedge reset_an2) 389 | begin 390 | if (!reset_an2 == 1) 391 | begin 392 | sum10 <= 0; 393 | sum11 <= 0; 394 | sum12 <= 0; 395 | sum13 <= 0; 396 | end 397 | else 398 | begin 399 | sum10 <= weighted_pixel[8] + weighted_pixel[9]+weighted_pixel[10]; 400 | sum11 <= sum10 + weighted_pixel[11]+weighted_pixel[12]; 401 | sum12 <= sum11+ weighted_pixel[13]+weighted_pixel[14]; 402 | sum13 <= sum12 + weighted_pixel[15]; 403 | 404 | //$display ("%b", sum13); 405 | end 406 | end 407 | 408 | always @(posedge clk2 or negedge reset_an2) 409 | begin 410 | if (!reset_an2 == 1) 411 | begin 412 | sum20 <= 0; 413 | sum21 <= 0; 414 | sum22 <= 0; 415 | sum23 <= 0; 416 | end 417 | else 418 | begin 419 | sum20 <= weighted_pixel[16] + weighted_pixel[17]+weighted_pixel[18]; 420 | sum21 <= sum20 + weighted_pixel[19]+weighted_pixel[20]; 421 | sum22 <= sum21+ weighted_pixel[21]+weighted_pixel[22]; 422 | sum23 <= sum22 + weighted_pixel[23]; 423 | 424 | //$display ("%b", sum23); 425 | end 426 | end 427 | 428 | always @(posedge clk2 or negedge reset_an2) 429 | begin 430 | if (!reset_an2 == 1) 431 | begin 432 | sum30 <= 0; 433 | sum31 <= 0; 434 | sum32 <= 0; 435 | sum33 <= 0; 436 | end 437 | else 438 | begin 439 | sum30 <= weighted_pixel[24] + weighted_pixel[25]+weighted_pixel[26]; 440 | sum31 <= sum30 + weighted_pixel[27]+weighted_pixel[28]; 441 | sum32 <= sum31+ weighted_pixel[29]+weighted_pixel[30]; 442 | sum33 <= sum32 + weighted_pixel[31]; 443 | 444 | //$display ("%b", sum33); 445 | end 446 | end 447 | 448 | always @(posedge clk2 or negedge reset_an2) 449 | begin 450 | if (!reset_an2 == 1) 451 | begin 452 | sum40 <= 0; 453 | sum41 <= 0; 454 | sum42 <= 0; 455 | sum43 <= 0; 456 | end 457 | else 458 | begin 459 | sum40 <= weighted_pixel[32] + weighted_pixel[33]+weighted_pixel[34]; 460 | sum41 <= sum40 + weighted_pixel[35]+weighted_pixel[36]; 461 | sum42 <= sum41+ weighted_pixel[37]+weighted_pixel[38]; 462 | sum43 <= sum42 + weighted_pixel[39]; 463 | 464 | //$display ("%b", sum43); 465 | end 466 | end 467 | 468 | always @(posedge clk2 or negedge reset_an2) 469 | begin 470 | if (!reset_an2 == 1) 471 | begin 472 | sum50 <= 0; 473 | sum51 <= 0; 474 | sum52 <= 0; 475 | sum53 <= 0; 476 | end 477 | else 478 | begin 479 | sum50 <= weighted_pixel[40] + weighted_pixel[41]+weighted_pixel[42]; 480 | sum51 <= sum50 + weighted_pixel[43]+weighted_pixel[44]; 481 | sum52 <= sum51+ weighted_pixel[45]+weighted_pixel[46]; 482 | sum53 <= sum52 + weighted_pixel[47]; 483 | 484 | //$display ("%b", sum53); 485 | end 486 | end 487 | 488 | always @(posedge clk2 or negedge reset_an2) 489 | begin 490 | if (!reset_an2 == 1) 491 | begin 492 | sum60 <= 0; 493 | sum61 <= 0; 494 | sum62 <= 0; 495 | sum63 <= 0; 496 | end 497 | else 498 | begin 499 | sum60 <= weighted_pixel[48] + weighted_pixel[49]+weighted_pixel[50]; 500 | sum61 <= sum60 + weighted_pixel[51]+weighted_pixel[52]; 501 | sum62 <= sum61+ weighted_pixel[53]+weighted_pixel[54]; 502 | sum63 <= sum62 + weighted_pixel[55]; 503 | 504 | //$display ("%b", sum63); 505 | end 506 | end 507 | 508 | always @(posedge clk2 or negedge reset_an2) 509 | begin 510 | if (!reset_an2 == 1) 511 | begin 512 | sum70 <= 0; 513 | sum71 <= 0; 514 | sum72 <= 0; 515 | sum73 <= 0; 516 | end 517 | else 518 | begin 519 | sum70 <= weighted_pixel[56] + weighted_pixel[57]+weighted_pixel[58]; 520 | sum71 <= sum70 + weighted_pixel[59]+weighted_pixel[60]; 521 | sum72 <= sum71+ weighted_pixel[61]+weighted_pixel[62]; 522 | sum73 <= sum72 + weighted_pixel[63]; 523 | 524 | //$display ("%b", sum73); 525 | end 526 | end 527 | 528 | always @(posedge clk2 or negedge reset_an2) 529 | begin 530 | if (!reset_an2 == 1) 531 | begin 532 | sum80 <= 0; 533 | sum81 <= 0; 534 | sum82 <= 0; 535 | sum83 <= 0; 536 | end 537 | else 538 | begin 539 | sum80 <= weighted_pixel[64] + weighted_pixel[65]+weighted_pixel[66]; 540 | sum81 <= sum80 + weighted_pixel[67]+weighted_pixel[68]; 541 | sum82 <= sum81+ weighted_pixel[69]+weighted_pixel[70]; 542 | sum83 <= sum82 + weighted_pixel[71]; 543 | 544 | //$display ("%b", sum83); 545 | end 546 | end 547 | 548 | always @(posedge clk2 or negedge reset_an2) 549 | begin 550 | if (!reset_an2 == 1) 551 | begin 552 | sum90 <= 0; 553 | sum91 <= 0; 554 | sum92 <= 0; 555 | sum93 <= 0; 556 | end 557 | else 558 | begin 559 | sum90 <= weighted_pixel[72] + weighted_pixel[73]+weighted_pixel[74]; 560 | sum91 <= sum90 + weighted_pixel[75]+weighted_pixel[76]; 561 | sum92 <= sum91+ weighted_pixel[77]+weighted_pixel[78]; 562 | sum93 <= sum92 + weighted_pixel[79]; 563 | 564 | //$display ("%b", sum93); 565 | end 566 | end 567 | 568 | always @(posedge clk2 or negedge reset_an2) 569 | begin 570 | if (!reset_an2 == 1) 571 | begin 572 | sum100 <= 0; 573 | sum101 <= 0; 574 | sum102 <= 0; 575 | sum103 <= 0; 576 | end 577 | else 578 | begin 579 | sum100 <= weighted_pixel[80] + weighted_pixel[81]+weighted_pixel[82]; 580 | sum101 <= sum100 + weighted_pixel[83]+weighted_pixel[84]; 581 | sum102 <= sum101+ weighted_pixel[85]+weighted_pixel[86]; 582 | sum103 <= sum102 + weighted_pixel[87]; 583 | 584 | //$display ("%b", sum103); 585 | end 586 | end 587 | 588 | always @(posedge clk2 or negedge reset_an2) 589 | begin 590 | if (!reset_an2 == 1) 591 | begin 592 | sum110 <= 0; 593 | sum111 <= 0; 594 | sum112 <= 0; 595 | sum113 <= 0; 596 | end 597 | else 598 | begin 599 | sum110 <= weighted_pixel[88] + weighted_pixel[89]+weighted_pixel[90]; 600 | sum111 <= sum110 + weighted_pixel[91]+weighted_pixel[92]; 601 | sum112 <= sum111+ weighted_pixel[93]+weighted_pixel[94]; 602 | sum113 <= sum112 + weighted_pixel[95]; 603 | 604 | //$display ("%b", sum113); 605 | end 606 | end 607 | 608 | always @(posedge clk2 or negedge reset_an2) 609 | begin 610 | if (!reset_an2 == 1) 611 | begin 612 | sum120 <= 0; 613 | sum121 <= 0; 614 | sum122 <= 0; 615 | sum123 <= 0; 616 | end 617 | else 618 | begin 619 | sum120 <= weighted_pixel[96] + weighted_pixel[97]+weighted_pixel[98]; 620 | sum121 <= sum120 + weighted_pixel[99]+weighted_pixel[100]; 621 | sum122 <= sum121+ weighted_pixel[101]+weighted_pixel[102]; 622 | sum123 <= sum122 + weighted_pixel[103]; 623 | 624 | //$display ("%b", sum123); 625 | end 626 | end 627 | 628 | always @(posedge clk2 or negedge reset_an2) 629 | begin 630 | if (!reset_an2 == 1) 631 | begin 632 | sum130 <= 0; 633 | sum131 <= 0; 634 | sum132 <= 0; 635 | sum133 <= 0; 636 | end 637 | else 638 | begin 639 | sum130 <= weighted_pixel[104] + weighted_pixel[105]+weighted_pixel[106]; 640 | sum131 <= sum130 + weighted_pixel[107]+weighted_pixel[108]; 641 | sum132 <= sum131+ weighted_pixel[109]+weighted_pixel[110]; 642 | sum133 <= sum132 + weighted_pixel[111]; 643 | 644 | //$display ("%b", sum133); 645 | end 646 | end 647 | 648 | always @(posedge clk2 or negedge reset_an2) 649 | begin 650 | if (!reset_an2 == 1) 651 | begin 652 | sum140 <= 0; 653 | sum141 <= 0; 654 | sum142 <= 0; 655 | sum143 <= 0; 656 | end 657 | else 658 | begin 659 | sum140 <= weighted_pixel[112] + weighted_pixel[113]+weighted_pixel[114]; 660 | sum141 <= sum140 + weighted_pixel[115]+weighted_pixel[116]; 661 | sum142 <= sum141+ weighted_pixel[117]+weighted_pixel[118]; 662 | sum143 <= sum142 + weighted_pixel[119]; 663 | 664 | //$display ("%b", sum143); 665 | end 666 | end 667 | 668 | always @(posedge clk2 or negedge reset_an2) 669 | begin 670 | if (!reset_an2 == 1) 671 | begin 672 | sum150 <= 0; 673 | sum151 <= 0; 674 | sum152 <= 0; 675 | sum153 <= 0; 676 | end 677 | else 678 | begin 679 | sum150 <= weighted_pixel[120] + weighted_pixel[121]+weighted_pixel[122]; 680 | sum151 <= sum150 + weighted_pixel[123]+weighted_pixel[124]; 681 | sum152 <= sum151+ weighted_pixel[125]+weighted_pixel[126]; 682 | sum153 <= sum152 + weighted_pixel[127]; 683 | 684 | //$display ("%b", sum153); 685 | end 686 | end 687 | 688 | always @(posedge clk2 or negedge reset_an2) 689 | begin 690 | if (!reset_an2 == 1) 691 | begin 692 | sum160 <= 0; 693 | sum161 <= 0; 694 | end 695 | else 696 | begin 697 | 698 | sum160 <= sum03 + sum13+ sum23; 699 | sum161 <= sum160 +sum33; 700 | 701 | end 702 | end 703 | always @(posedge clk2 or negedge reset_an2) 704 | begin 705 | if (!reset_an2 == 1) 706 | begin 707 | sum170 <= 0; 708 | sum171 <= 0; 709 | end 710 | else 711 | begin 712 | 713 | sum170 <= sum43 + sum53+ sum63; 714 | sum171 <= sum170 +sum73; 715 | 716 | end 717 | end 718 | 719 | always @(posedge clk2 or negedge reset_an2) 720 | begin 721 | if (!reset_an2 == 1) 722 | begin 723 | sum180 <= 0; 724 | sum181 <= 0; 725 | end 726 | else 727 | begin 728 | 729 | sum180 <= sum83 + sum93+ sum103; 730 | sum181 <= sum180 +sum113; 731 | 732 | end 733 | end 734 | 735 | always @(posedge clk2 or negedge reset_an2) 736 | begin 737 | if (!reset_an2 == 1) 738 | begin 739 | sum190 <= 0; 740 | sum191 <= 0; 741 | end 742 | else 743 | begin 744 | 745 | sum190 <= sum123 + sum133+ sum143; 746 | sum191 <= sum190 +sum153; 747 | 748 | end 749 | end 750 | 751 | always @(posedge clk2 or negedge reset_an2) 752 | begin 753 | if (!reset_an2 == 1) 754 | begin 755 | sum200 <= 0; 756 | out_stimulus <= 0; 757 | end 758 | else 759 | begin 760 | 761 | sum200 <= sum161 + sum171+ sum181; 762 | out_stimulus <= sum200 +sum191; 763 | //$display("%b", out_stimulus); 764 | end 765 | end 766 | 767 | endmodule -------------------------------------------------------------------------------- /verilog_codes/rptr_empty.v: -------------------------------------------------------------------------------- 1 | module rptr_empty (rempty, raddr, rptr, rq2_wptr, rinc, rclk, rrst_n); 2 | 3 | parameter ADDRSIZE = 9; 4 | 5 | output reg rempty; 6 | output [ADDRSIZE-1:0] raddr; 7 | output reg [ADDRSIZE :0] rptr; 8 | input [ADDRSIZE :0] rq2_wptr; 9 | input rinc, rclk, rrst_n; 10 | 11 | reg [ADDRSIZE:0] rbin; 12 | wire [ADDRSIZE:0] rgraynext, rbinnext; 13 | //------------------- 14 | // GRAYSTYLE2 pointer 15 | //------------------- 16 | always @(posedge rclk or negedge rrst_n) 17 | 18 | begin 19 | if (!rrst_n) {rbin, rptr} <= 0; 20 | else {rbin, rptr} <= {rbinnext, rgraynext}; 21 | end 22 | 23 | // Memory read-address pointer (okay to use binary to address memory) 24 | assign raddr = rbin[ADDRSIZE-1:0]; 25 | assign rbinnext = rbin + (rinc & ~rempty); 26 | assign rgraynext = (rbinnext>>1) ^ rbinnext; 27 | 28 | //--------------------------------------------------------------- 29 | // FIFO empty when the next rptr == synchronized wptr or on reset 30 | //--------------------------------------------------------------- 31 | 32 | assign rempty_val = (rgraynext == rq2_wptr); 33 | 34 | always @(posedge rclk or negedge rrst_n) 35 | 36 | begin 37 | if (!rrst_n) rempty <= 1'b1; 38 | else rempty <= rempty_val; 39 | end 40 | 41 | endmodule -------------------------------------------------------------------------------- /verilog_codes/rwg.v: -------------------------------------------------------------------------------- 1 | 2 | `timescale 1ns / 1ps 3 | module rwg (clk2, en_lfsr, en_lfsr1, en_lfsr2, en_lfsr3, en_lfsr4, en_lfsr5, en_lfsr6, en_lfsr7, en_lfsr8, en_lfsr9, en_lfsr10, en_lfsr11, lfsr_random); 4 | 5 | input clk2; 6 | 7 | input en_lfsr; 8 | input en_lfsr1; 9 | input en_lfsr2; 10 | input en_lfsr3; 11 | input en_lfsr4; 12 | input en_lfsr5; 13 | input en_lfsr6; 14 | input en_lfsr7; 15 | input en_lfsr8; 16 | input en_lfsr9; 17 | input en_lfsr10; 18 | input en_lfsr11; 19 | 20 | output reg [10:0] lfsr_random; 21 | wire lfsr_feedback = lfsr_random[10] ^ lfsr_random[8]; 22 | integer lfsr_count; 23 | 24 | always @ (posedge clk2 or negedge en_lfsr or negedge en_lfsr1 or negedge en_lfsr2 or negedge en_lfsr3 or negedge en_lfsr4 or negedge en_lfsr5 25 | or negedge en_lfsr6 or negedge en_lfsr7 or negedge en_lfsr8 or negedge en_lfsr9 or negedge en_lfsr10 or negedge en_lfsr11) 26 | begin 27 | 28 | if (!en_lfsr == 1) 29 | begin 30 | 31 | lfsr_random <= 11'b01011010110; //An LFSR cannot have an all 0 state, thus reset to FF // seed value = all 128 bits are 1's 32 | lfsr_count <= 0; 33 | 34 | end 35 | else if (!en_lfsr1 == 1) 36 | begin 37 | lfsr_random <= 11'b10100101001; 38 | lfsr_count <= 11; 39 | end 40 | else if (!en_lfsr2 == 1) 41 | begin 42 | lfsr_random <= 11'b11000110010; 43 | lfsr_count <= 22; 44 | end 45 | else if (!en_lfsr3 == 1) 46 | begin 47 | lfsr_random <= 11'b01010111011; 48 | lfsr_count <= 33; 49 | end 50 | else if (!en_lfsr4 == 1) 51 | begin 52 | lfsr_random <= 11'b11101000100; 53 | lfsr_count <= 44; 54 | end 55 | else if (!en_lfsr5 == 1) 56 | begin 57 | lfsr_random <= 11'b01111001101; 58 | lfsr_count <= 55; 59 | end 60 | else if (!en_lfsr6 == 1) 61 | begin 62 | lfsr_random <= 11'b00001010110; 63 | lfsr_count <= 66; 64 | end 65 | else if (!en_lfsr7 == 1) 66 | begin 67 | lfsr_random <= 11'b10011011111; 68 | lfsr_count <= 77; 69 | end 70 | else if (!en_lfsr8 == 1) 71 | begin 72 | lfsr_random <= 11'b00101100000; 73 | lfsr_count <= 88; 74 | end 75 | else if (!en_lfsr9 == 1) 76 | begin 77 | lfsr_random <= 11'b00111101001; 78 | lfsr_count <= 99; 79 | end 80 | else if (!en_lfsr10 == 1) 81 | begin 82 | lfsr_random <= 11'b01001110010; 83 | lfsr_count <= 110; 84 | end 85 | else if (!en_lfsr11 == 1) 86 | begin 87 | lfsr_random <= 11'b01011111011; 88 | lfsr_count <= 121; 89 | end 90 | else 91 | begin 92 | 93 | lfsr_random <= {lfsr_feedback, lfsr_random[10:1]}; //shift right the xor'd every posedge clock 94 | //$display("%b", lfsr_random); 95 | lfsr_count <= lfsr_count + 1; 96 | //lfsr_count <= lfsr_count_next; 97 | /* 98 | if (lfsr_count == 11) 99 | begin 100 | 101 | lfsr_count <= 0; 102 | 103 | end 104 | 105 | end 106 | */ 107 | 108 | end 109 | end 110 | 111 | endmodule -------------------------------------------------------------------------------- /verilog_codes/rwg_tb.v: -------------------------------------------------------------------------------- 1 | module rwg_tb(); 2 | 3 | reg clk2; 4 | 5 | reg en_lfsr; 6 | reg en_lfsr1; 7 | reg en_lfsr2; 8 | reg en_lfsr3; 9 | reg en_lfsr4; 10 | reg en_lfsr5; 11 | reg en_lfsr6; 12 | reg en_lfsr7; 13 | reg en_lfsr8; 14 | reg en_lfsr9; 15 | reg en_lfsr10; 16 | reg en_lfsr11; 17 | 18 | wire [10:0] lfsr_random; 19 | 20 | rwg r1 (.clk2(clk2), .en_lfsr(en_lfsr), .en_lfsr1(en_lfsr1), .en_lfsr2(en_lfsr2), .en_lfsr3(en_lfsr3), .en_lfsr4(en_lfsr4), .en_lfsr5(en_lfsr5), .en_lfsr6(en_lfsr6), 21 | .en_lfsr7(en_lfsr7), .en_lfsr8(en_lfsr8), .en_lfsr9(en_lfsr9), .en_lfsr10(en_lfsr10), .en_lfsr11(en_lfsr11), .lfsr_random(lfsr_random)); 22 | 23 | initial 24 | begin 25 | clk2 = 1'b0; 26 | end 27 | 28 | always 29 | begin 30 | #500 clk2 = ~clk2; 31 | end 32 | 33 | initial 34 | begin 35 | 36 | #1000 en_lfsr=0; //$finish; 37 | #1000 en_lfsr=1; 38 | #11000 //$finish; 39 | #1000 en_lfsr1=0; 40 | #1000 en_lfsr1=1; 41 | #11000 //$finish; 42 | #1000 en_lfsr2=0; 43 | #1000 en_lfsr2=1; 44 | #11000 //$finish; 45 | #1000 en_lfsr3=0; 46 | #1000 en_lfsr3=1; 47 | #11000 //$finish; 48 | #1000 en_lfsr4=0; 49 | #1000 en_lfsr4=1; 50 | #11000 //$finish; 51 | #1000 en_lfsr5=0; 52 | #1000 en_lfsr5=1; 53 | #11000 //$finish; 54 | #1000 en_lfsr6=0; 55 | #1000 en_lfsr6=1; 56 | #11000 //$finish; 57 | #1000 en_lfsr7=0; 58 | #1000 en_lfsr7=1; 59 | #11000 //$finish; 60 | #1000 en_lfsr8=0; 61 | #1000 en_lfsr8=1; 62 | #11000 //$finish; 63 | #1000 en_lfsr9=0; 64 | #1000 en_lfsr9=1; 65 | #11000 //$finish; 66 | #1000 en_lfsr10=0; 67 | #1000 en_lfsr10=1; 68 | #11000 //$finish; 69 | #1000 en_lfsr11=0; 70 | #1000 en_lfsr11=1; 71 | #11000 //$finish; 72 | 73 | #1000 en_lfsr=0; //$finish; 74 | #1000 en_lfsr=1; 75 | #11000 //$finish; 76 | #1000 en_lfsr1=0; 77 | #1000 en_lfsr1=1; 78 | #11000 //$finish; 79 | #1000 en_lfsr2=0; 80 | #1000 en_lfsr2=1; 81 | #11000 //$finish; 82 | #1000 en_lfsr3=0; 83 | #1000 en_lfsr3=1; 84 | #11000 //$finish; 85 | #1000 en_lfsr4=0; 86 | #1000 en_lfsr4=1; 87 | #11000 //$finish; 88 | #1000 en_lfsr5=0; 89 | #1000 en_lfsr5=1; 90 | #11000 //$finish; 91 | #1000 en_lfsr6=0; 92 | #1000 en_lfsr6=1; 93 | #11000 //$finish; 94 | #1000 en_lfsr7=0; 95 | #1000 en_lfsr7=1; 96 | #11000 //$finish; 97 | #1000 en_lfsr8=0; 98 | #1000 en_lfsr8=1; 99 | #11000 //$finish; 100 | #1000 en_lfsr9=0; 101 | #1000 en_lfsr9=1; 102 | #11000 //$finish; 103 | #1000 en_lfsr10=0; 104 | #1000 en_lfsr10=1; 105 | #11000 //$finish; 106 | #1000 en_lfsr11=0; 107 | #1000 en_lfsr11=1; 108 | #11000 //$finish; 109 | 110 | #1000 en_lfsr=0; //$finish; 111 | #1000 en_lfsr=1; 112 | #11000 //$finish; 113 | #1000 en_lfsr1=0; 114 | #1000 en_lfsr1=1; 115 | #11000 //$finish; 116 | #1000 en_lfsr2=0; 117 | #1000 en_lfsr2=1; 118 | #11000 //$finish; 119 | #1000 en_lfsr3=0; 120 | #1000 en_lfsr3=1; 121 | #11000 //$finish; 122 | #1000 en_lfsr4=0; 123 | #1000 en_lfsr4=1; 124 | #11000 //$finish; 125 | #1000 en_lfsr5=0; 126 | #1000 en_lfsr5=1; 127 | #11000 //$finish; 128 | #1000 en_lfsr6=0; 129 | #1000 en_lfsr6=1; 130 | #11000 //$finish; 131 | #1000 en_lfsr7=0; 132 | #1000 en_lfsr7=1; 133 | #11000 //$finish; 134 | #1000 en_lfsr8=0; 135 | #1000 en_lfsr8=1; 136 | #11000 //$finish; 137 | #1000 en_lfsr9=0; 138 | #1000 en_lfsr9=1; 139 | #11000 //$finish; 140 | #1000 en_lfsr10=0; 141 | #1000 en_lfsr10=1; 142 | #11000 //$finish; 143 | #1000 en_lfsr11=0; 144 | #1000 en_lfsr11=1; 145 | #11000 //$finish; 146 | 147 | #1000 en_lfsr=0; //$finish; 148 | #1000 en_lfsr=1; 149 | #11000 //$finish; 150 | #1000 en_lfsr1=0; 151 | #1000 en_lfsr1=1; 152 | #11000 //$finish; 153 | #1000 en_lfsr2=0; 154 | #1000 en_lfsr2=1; 155 | #11000 //$finish; 156 | #1000 en_lfsr3=0; 157 | #1000 en_lfsr3=1; 158 | #11000 //$finish; 159 | #1000 en_lfsr4=0; 160 | #1000 en_lfsr4=1; 161 | #11000 //$finish; 162 | #1000 en_lfsr5=0; 163 | #1000 en_lfsr5=1; 164 | #11000 //$finish; 165 | #1000 en_lfsr6=0; 166 | #1000 en_lfsr6=1; 167 | #11000 //$finish; 168 | #1000 en_lfsr7=0; 169 | #1000 en_lfsr7=1; 170 | #11000 //$finish; 171 | #1000 en_lfsr8=0; 172 | #1000 en_lfsr8=1; 173 | #11000 //$finish; 174 | #1000 en_lfsr9=0; 175 | #1000 en_lfsr9=1; 176 | #11000 //$finish; 177 | #1000 en_lfsr10=0; 178 | #1000 en_lfsr10=1; 179 | #11000 //$finish; 180 | #1000 en_lfsr11=0; 181 | #1000 en_lfsr11=1; 182 | #11000 //$finish; 183 | 184 | #1000 en_lfsr=0; //$finish; 185 | #1000 en_lfsr=1; 186 | #11000 //$finish; 187 | #1000 en_lfsr1=0; 188 | #1000 en_lfsr1=1; 189 | #11000 //$finish; 190 | #1000 en_lfsr2=0; 191 | #1000 en_lfsr2=1; 192 | #11000 //$finish; 193 | #1000 en_lfsr3=0; 194 | #1000 en_lfsr3=1; 195 | #11000 //$finish; 196 | #1000 en_lfsr4=0; 197 | #1000 en_lfsr4=1; 198 | #11000 //$finish; 199 | #1000 en_lfsr5=0; 200 | #1000 en_lfsr5=1; 201 | #11000 //$finish; 202 | #1000 en_lfsr6=0; 203 | #1000 en_lfsr6=1; 204 | #11000 //$finish; 205 | #1000 en_lfsr7=0; 206 | #1000 en_lfsr7=1; 207 | #11000 //$finish; 208 | #1000 en_lfsr8=0; 209 | #1000 en_lfsr8=1; 210 | #11000 //$finish; 211 | #1000 en_lfsr9=0; 212 | #1000 en_lfsr9=1; 213 | #11000 //$finish; 214 | #1000 en_lfsr10=0; 215 | #1000 en_lfsr10=1; 216 | #11000 //$finish; 217 | #1000 en_lfsr11=0; 218 | #1000 en_lfsr11=1; 219 | #11000 $finish; 220 | 221 | end 222 | 223 | initial 224 | $monitor( "$time lfsr_random = %b",lfsr_random); 225 | 226 | endmodule -------------------------------------------------------------------------------- /verilog_codes/sync_r2w.v: -------------------------------------------------------------------------------- 1 | module sync_r2w (wq2_rptr, rptr, wclk, wrst_n); 2 | 3 | parameter ADDRSIZE = 9; 4 | 5 | output reg [ADDRSIZE:0] wq2_rptr; 6 | input [ADDRSIZE:0] rptr; 7 | input wclk, wrst_n; 8 | 9 | reg [ADDRSIZE:0] wq1_rptr; 10 | 11 | always @(posedge wclk or negedge wrst_n) 12 | begin 13 | 14 | if (!wrst_n) {wq2_rptr,wq1_rptr} <= 0; 15 | else {wq2_rptr,wq1_rptr} <= {wq1_rptr,rptr}; 16 | 17 | end 18 | 19 | endmodule -------------------------------------------------------------------------------- /verilog_codes/sync_w2r.v: -------------------------------------------------------------------------------- 1 | module sync_w2r (rq2_wptr, wptr, rclk, rrst_n); 2 | 3 | parameter ADDRSIZE = 9; 4 | 5 | output reg [ADDRSIZE:0] rq2_wptr; 6 | input [ADDRSIZE:0] wptr; 7 | input rclk, rrst_n; 8 | 9 | reg [ADDRSIZE:0] rq1_wptr; 10 | 11 | always @(posedge rclk or negedge rrst_n) 12 | 13 | begin 14 | if (!rrst_n) {rq2_wptr,rq1_wptr} <= 0; 15 | else {rq2_wptr,rq1_wptr} <= {rq1_wptr,wptr}; 16 | end 17 | 18 | endmodule -------------------------------------------------------------------------------- /verilog_codes/weigh_pix_par_add.v: -------------------------------------------------------------------------------- 1 | module weigh_pix_par_add (clk2, reset_an2, fifo_dataout, lfsr_random, out_stimulus); 2 | 3 | input clk2; 4 | input reset_an2; 5 | input [127:0] fifo_dataout; 6 | input [10:0] lfsr_random; 7 | output reg [15:0] out_stimulus; 8 | 9 | integer global_count=0; 10 | reg [1023:0] shift_reg; 11 | reg [1023:0] shift_reg_next; 12 | 13 | integer wt_pix_index; 14 | 15 | reg [8:0] weighted_pixel[0:127]; 16 | integer wt_pix_pos = 0; 17 | integer wt_pix = 0; 18 | 19 | reg [10:0] sum00; 20 | reg [11:0] sum01; 21 | reg [11:0] sum02; 22 | reg [11:0] sum03; 23 | 24 | reg [10:0] sum10; 25 | reg [11:0] sum11; 26 | reg [11:0] sum12; 27 | reg [11:0] sum13; 28 | 29 | reg [10:0] sum20; 30 | reg [11:0] sum21; 31 | reg [11:0] sum22; 32 | reg [11:0] sum23; 33 | 34 | reg [10:0] sum30; 35 | reg [11:0] sum31; 36 | reg [11:0] sum32; 37 | reg [11:0] sum33; 38 | 39 | reg [10:0] sum40; 40 | reg [11:0] sum41; 41 | reg [11:0] sum42; 42 | reg [11:0] sum43; 43 | 44 | reg [10:0] sum50; 45 | reg [11:0] sum51; 46 | reg [11:0] sum52; 47 | reg [11:0] sum53; 48 | 49 | reg [10:0] sum60; 50 | reg [11:0] sum61; 51 | reg [11:0] sum62; 52 | reg [11:0] sum63; 53 | 54 | reg [10:0] sum70; 55 | reg [11:0] sum71; 56 | reg [11:0] sum72; 57 | reg [11:0] sum73; 58 | 59 | reg [10:0] sum80; 60 | reg [11:0] sum81; 61 | reg [11:0] sum82; 62 | reg [11:0] sum83; 63 | 64 | reg [10:0] sum90; 65 | reg [11:0] sum91; 66 | reg [11:0] sum92; 67 | reg [11:0] sum93; 68 | 69 | reg [10:0] sum100; 70 | reg [11:0] sum101; 71 | reg [11:0] sum102; 72 | reg [11:0] sum103; 73 | 74 | reg [10:0] sum110; 75 | reg [11:0] sum111; 76 | reg [11:0] sum112; 77 | reg [11:0] sum113; 78 | 79 | reg [10:0] sum120; 80 | reg [11:0] sum121; 81 | reg [11:0] sum122; 82 | reg [11:0] sum123; 83 | 84 | reg [10:0] sum130; 85 | reg [11:0] sum131; 86 | reg [11:0] sum132; 87 | reg [11:0] sum133; 88 | 89 | reg [10:0] sum140; 90 | reg [11:0] sum141; 91 | reg [11:0] sum142; 92 | reg [11:0] sum143; 93 | 94 | reg [10:0] sum150; 95 | reg [11:0] sum151; 96 | reg [11:0] sum152; 97 | reg [11:0] sum153; 98 | 99 | reg [13:0] sum160; 100 | reg [14:0] sum161; 101 | 102 | reg [13:0] sum170; 103 | reg [14:0] sum171; 104 | 105 | reg [13:0] sum180; 106 | reg [14:0] sum181; 107 | 108 | reg [13:0] sum190; 109 | reg [14:0] sum191; 110 | 111 | reg [15:0] sum200; 112 | 113 | always @(posedge clk2 or negedge reset_an2) 114 | begin 115 | 116 | 117 | if (!reset_an2 == 1) 118 | begin 119 | //for (shift_reg_index = 0;shift_reg_index <= 1023; shift_reg_index = shift_reg_index + 1) 120 | //begin 121 | shift_reg <= 1024'b0;//////////////////////check this statement after synthesis 122 | //end 123 | end 124 | else 125 | begin 126 | if (global_count < 2237)//128 + 8 = 136 so <137 127 | begin 128 | 129 | //shift_reg1 <= shift_reg; 130 | global_count = global_count + 1; 131 | if ((global_count == 316 ) || (global_count == 444 ) || (global_count == 572 ) || (global_count == 700 ) || (global_count == 828 ) 132 | || (global_count == 956) || (global_count == 1084) || (global_count == 1212) || (global_count == 1340) || (global_count == 1468) || (global_count == 1596) 133 | || (global_count == 1724) || (global_count == 1852) || (global_count == 1980) || (global_count == 2108) || (global_count == 2236))//(global_count == 60 ) || (global_count == 188 ) || || (global_count == 1468) 134 | begin //first cycle and second cycle= global reset 135 | 136 | shift_reg_next <= {fifo_dataout, shift_reg_next[1023:128]}; 137 | //$display("%b", shift_reg_next); 138 | //$display("%t, %b", $time, fifo_dataout); 139 | shift_reg <= shift_reg_next; 140 | //$display("%d", global_count); 141 | end 142 | //$display("%b", fifo_dataout); 143 | end 144 | else 145 | begin 146 | shift_reg <= {1'b0, shift_reg[1023:896], 1'b0, shift_reg[895:768], 1'b0, shift_reg[767:640], 1'b0, shift_reg[639:512], 1'b0, 147 | shift_reg[511:384], 1'b0, shift_reg[383:256], 1'b0, shift_reg[255:128], 1'b0, shift_reg[127:0]};//no of bits need to get truncated from 1032 to 1024 148 | 149 | //shift_reg <= shift_reg_next; 150 | global_count = global_count + 1; 151 | //$display("%b", shift_reg); 152 | end 153 | //$display("%b", shift_reg); 154 | 155 | 156 | 157 | end 158 | 159 | 160 | 161 | end 162 | 163 | always @(posedge clk2 or negedge reset_an2) 164 | begin 165 | 166 | if (!reset_an2 == 1) 167 | begin 168 | 169 | for (wt_pix_index = 0;wt_pix_index <= 127;wt_pix_index = wt_pix_index + 1) 170 | begin 171 | weighted_pixel[wt_pix_index] <= 9'b0; 172 | end 173 | 174 | end 175 | else 176 | begin 177 | wt_pix <= wt_pix + 1; 178 | 179 | case(1) 180 | wt_pix >=1342 && wt_pix <= 1352 : begin//1 181 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 182 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 183 | /* 184 | $display("%t | weighted_pixel[0] = %d | weighted_pixel[1] = %d | weighted_pixel[2] = %d | weighted_pixel[3] = %d | weighted_pixel[4] = %d | ", 185 | $time , weighted_pixel[0], weighted_pixel[1], weighted_pixel[2], weighted_pixel[3], weighted_pixel[4]); 186 | $display("weighted_pixel[5] = %d | weighted_pixel[6] = %d | weighted_pixel[7] = %d | weighted_pixel[8] = %d | weighted_pixel[9] = %d | weighted_pixel[10] = %d ", 187 | weighted_pixel[5], weighted_pixel[6], weighted_pixel[7], weighted_pixel[8], weighted_pixel[9], weighted_pixel[10]); 188 | */ 189 | wt_pix_pos <= wt_pix_pos + 1; 190 | end 191 | wt_pix >=1355 && wt_pix <= 1365 : begin//2 192 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 193 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 194 | /* 195 | $display("%t | weighted_pixel[11] = %d | weighted_pixel[12] = %d | weighted_pixel[13] = %d | weighted_pixel[14] = %d | weighted_pixel[15] = %d | ", 196 | $time , weighted_pixel[11], weighted_pixel[12], weighted_pixel[13], weighted_pixel[14], weighted_pixel[15]); 197 | $display("weighted_pixel[16] = %d | weighted_pixel[17] = %d | weighted_pixel[18] = %d | weighted_pixel[19] = %d | weighted_pixel[20] = %d | weighted_pixel[21] = %d ", 198 | weighted_pixel[16], weighted_pixel[17], weighted_pixel[18], weighted_pixel[19], weighted_pixel[20], weighted_pixel[21]); 199 | */ 200 | wt_pix_pos <= wt_pix_pos + 1; 201 | end 202 | wt_pix >=1368 && wt_pix <= 1378 : begin//3 203 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 204 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 205 | /* 206 | $display("%t | weighted_pixel[22] = %d | weighted_pixel[23] = %d | weighted_pixel[24] = %d | weighted_pixel[25] = %d | weighted_pixel[26] = %d | ", 207 | $time , weighted_pixel[22], weighted_pixel[23], weighted_pixel[24], weighted_pixel[25], weighted_pixel[26]); 208 | $display("weighted_pixel[27] = %d | weighted_pixel[28] = %d | weighted_pixel[29] = %d | weighted_pixel[30] = %d | weighted_pixel[31] = %d | weighted_pixel[32] = %d ", 209 | weighted_pixel[27], weighted_pixel[28], weighted_pixel[29], weighted_pixel[30], weighted_pixel[31], weighted_pixel[32]); 210 | */ 211 | wt_pix_pos <= wt_pix_pos + 1; 212 | end 213 | wt_pix >=1381 && wt_pix <= 1391 : begin//4 214 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 215 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 216 | /* 217 | $display("%t | weighted_pixel[33] = %d | weighted_pixel[34] = %d | weighted_pixel[35] = %d | weighted_pixel[36] = %d | weighted_pixel[37] = %d | ", 218 | $time , weighted_pixel[33], weighted_pixel[34], weighted_pixel[35], weighted_pixel[36], weighted_pixel[37]); 219 | $display("weighted_pixel[38] = %d | weighted_pixel[39] = %d | weighted_pixel[40] = %d | weighted_pixel[41] = %d | weighted_pixel[42] = %d | weighted_pixel[43] = %d ", 220 | weighted_pixel[38], weighted_pixel[39], weighted_pixel[40], weighted_pixel[41], weighted_pixel[42], weighted_pixel[43]); 221 | */ 222 | wt_pix_pos <= wt_pix_pos + 1; 223 | end 224 | wt_pix >=1394 && wt_pix <= 1404 : begin//5 225 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 226 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 227 | /* 228 | $display("%t | weighted_pixel[44] = %d | weighted_pixel[45] = %d | weighted_pixel[46] = %d | weighted_pixel[47] = %d | weighted_pixel[48] = %d | ", 229 | $time , weighted_pixel[44], weighted_pixel[45], weighted_pixel[46], weighted_pixel[47], weighted_pixel[48]); 230 | $display("weighted_pixel[49] = %d | weighted_pixel[50] = %d | weighted_pixel[51] = %d | weighted_pixel[52] = %d | weighted_pixel[53] = %d | weighted_pixel[54] = %d ", 231 | weighted_pixel[49], weighted_pixel[50], weighted_pixel[51], weighted_pixel[52], weighted_pixel[53], weighted_pixel[54]); 232 | */ 233 | wt_pix_pos <= wt_pix_pos + 1; 234 | end 235 | wt_pix >=1407 && wt_pix <= 1417 : begin//6 236 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 237 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 238 | /* 239 | $display("%t | weighted_pixel[55] = %d | weighted_pixel[56] = %d | weighted_pixel[57] = %d | weighted_pixel[58] = %d | weighted_pixel[59] = %d | ", 240 | $time , weighted_pixel[55], weighted_pixel[56], weighted_pixel[57], weighted_pixel[58], weighted_pixel[59]); 241 | $display("weighted_pixel[60] = %d | weighted_pixel[61] = %d | weighted_pixel[62] = %d | weighted_pixel[63] = %d | weighted_pixel[64] = %d | weighted_pixel[65] = %d ", 242 | weighted_pixel[60], weighted_pixel[61], weighted_pixel[62], weighted_pixel[63], weighted_pixel[64], weighted_pixel[65]); 243 | */ 244 | wt_pix_pos <= wt_pix_pos + 1; 245 | end 246 | wt_pix >=1420 && wt_pix <= 1430 : begin//7 247 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 248 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 249 | /* 250 | $display("%t | weighted_pixel[66] = %d | weighted_pixel[67] = %d | weighted_pixel[68] = %d | weighted_pixel[69] = %d | weighted_pixel[70] = %d | ", 251 | $time , weighted_pixel[66], weighted_pixel[67], weighted_pixel[68], weighted_pixel[69], weighted_pixel[70]); 252 | $display("weighted_pixel[71] = %d | weighted_pixel[72] = %d | weighted_pixel[73] = %d | weighted_pixel[74] = %d | weighted_pixel[75] = %d | weighted_pixel[76] = %d ", 253 | weighted_pixel[71], weighted_pixel[72], weighted_pixel[73], weighted_pixel[74], weighted_pixel[75], weighted_pixel[76]); 254 | */ 255 | wt_pix_pos <= wt_pix_pos + 1; 256 | end 257 | wt_pix >=1433 && wt_pix <= 1443 : begin//8 258 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 259 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 260 | /* 261 | $display("%t | weighted_pixel[77] = %d | weighted_pixel[78] = %d | weighted_pixel[79] = %d | weighted_pixel[80] = %d | weighted_pixel[81] = %d | ", 262 | $time , weighted_pixel[77], weighted_pixel[78], weighted_pixel[79], weighted_pixel[80], weighted_pixel[81]); 263 | $display("weighted_pixel[82] = %d | weighted_pixel[83] = %d | weighted_pixel[84] = %d | weighted_pixel[85] = %d | weighted_pixel[86] = %d | weighted_pixel[87] = %d ", 264 | weighted_pixel[82], weighted_pixel[83], weighted_pixel[84], weighted_pixel[85], weighted_pixel[86], weighted_pixel[87]); 265 | */ 266 | wt_pix_pos <= wt_pix_pos + 1; 267 | end 268 | wt_pix >=1446 && wt_pix <= 1456 : begin//9 269 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 270 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 271 | /* 272 | $display("%t | weighted_pixel[88] = %d | weighted_pixel[89] = %d | weighted_pixel[90] = %d | weighted_pixel[91] = %d | weighted_pixel[92] = %d | ", 273 | $time , weighted_pixel[88], weighted_pixel[89], weighted_pixel[90], weighted_pixel[91], weighted_pixel[92]); 274 | $display("weighted_pixel[93] = %d | weighted_pixel[94] = %d | weighted_pixel[95] = %d | weighted_pixel[96] = %d | weighted_pixel[97] = %d | weighted_pixel[98] = %d ", 275 | weighted_pixel[93], weighted_pixel[94], weighted_pixel[95], weighted_pixel[96], weighted_pixel[97], weighted_pixel[98]); 276 | */ 277 | wt_pix_pos <= wt_pix_pos + 1; 278 | end 279 | wt_pix >=1459 && wt_pix <= 1469 : begin//10 280 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 281 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 282 | /* 283 | $display("%t | weighted_pixel[99] = %d | weighted_pixel[100] = %d | weighted_pixel[101] = %d | weighted_pixel[102] = %d | weighted_pixel[103] = %d | ", 284 | $time , weighted_pixel[99], weighted_pixel[100], weighted_pixel[101], weighted_pixel[102], weighted_pixel[103]); 285 | $display("weighted_pixel[104] = %d | weighted_pixel[105] = %d | weighted_pixel[106] = %d | weighted_pixel[107] = %d | weighted_pixel[108] = %d | weighted_pixel[109] = %d ", 286 | weighted_pixel[104], weighted_pixel[105], weighted_pixel[106], weighted_pixel[107], weighted_pixel[108], weighted_pixel[109]); 287 | */ 288 | wt_pix_pos <= wt_pix_pos + 1; 289 | end 290 | wt_pix >=1472 && wt_pix <= 1482 : begin//11 291 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 292 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 293 | /* 294 | $display("%t | weighted_pixel[110] = %d | weighted_pixel[111] = %d | weighted_pixel[112] = %d | weighted_pixel[113] = %d | weighted_pixel[114] = %d | ", 295 | $time , weighted_pixel[110], weighted_pixel[111], weighted_pixel[112], weighted_pixel[113], weighted_pixel[114]); 296 | $display("weighted_pixel[115] = %d | weighted_pixel[116] = %d | weighted_pixel[117] = %d | weighted_pixel[118] = %d | weighted_pixel[119] = %d | weighted_pixel[120] = %d ", 297 | weighted_pixel[115], weighted_pixel[116], weighted_pixel[117], weighted_pixel[118], weighted_pixel[119], weighted_pixel[120]); 298 | */ 299 | wt_pix_pos <= wt_pix_pos + 1; 300 | end 301 | wt_pix >=1485 && wt_pix <= 1495 : begin//12 302 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 303 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 304 | /* 305 | $display("%t | weighted_pixel[121] = %d | weighted_pixel[122] = %d | weighted_pixel[123] = %d | weighted_pixel[124] = %d | weighted_pixel[125] = %d | ", 306 | $time , weighted_pixel[121], weighted_pixel[122], weighted_pixel[123], weighted_pixel[124], weighted_pixel[125]); 307 | $display("weighted_pixel[126] = %d | weighted_pixel[127] = %d ",weighted_pixel[126], weighted_pixel[127]); 308 | */ 309 | wt_pix_pos <= wt_pix_pos + 1; 310 | end 311 | wt_pix >=1496 && wt_pix <= 2237 : begin 312 | //weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 313 | //$display("%t %b", $time, weighted_pixel[wt_pix_pos]); 314 | wt_pix_pos <= 0; 315 | end 316 | wt_pix >=2238 && wt_pix <= 2248 : begin//1 317 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 318 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 319 | /* 320 | $display("time = %t | weighted_pixel[0] = %d | weighted_pixel[1] = %d | weighted_pixel[2] = %d | weighted_pixel[3] = %d | weighted_pixel[4] = %d | ", 321 | $time , weighted_pixel[0], weighted_pixel[1], weighted_pixel[2], weighted_pixel[3], weighted_pixel[4]); 322 | $display("weighted_pixel[5] = %d | weighted_pixel[6] = %d | weighted_pixel[7] = %d | weighted_pixel[8] = %d | weighted_pixel[9] = %d | weighted_pixel[10] = %d ", 323 | weighted_pixel[5], weighted_pixel[6], weighted_pixel[7], weighted_pixel[8], weighted_pixel[9], weighted_pixel[10]); 324 | */ 325 | wt_pix_pos <= wt_pix_pos + 1; 326 | end 327 | wt_pix >=2251 && wt_pix <= 2261 : begin//2 328 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 329 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 330 | /* 331 | $display("%t | weighted_pixel[11] = %d | weighted_pixel[12] = %d | weighted_pixel[13] = %d | weighted_pixel[14] = %d | weighted_pixel[15] = %d | ", 332 | $time , weighted_pixel[11], weighted_pixel[12], weighted_pixel[13], weighted_pixel[14], weighted_pixel[15]); 333 | $display("weighted_pixel[16] = %d | weighted_pixel[17] = %d | weighted_pixel[18] = %d | weighted_pixel[19] = %d | weighted_pixel[20] = %d | weighted_pixel[21] = %d ", 334 | weighted_pixel[16], weighted_pixel[17], weighted_pixel[18], weighted_pixel[19], weighted_pixel[20], weighted_pixel[21]); 335 | */ 336 | wt_pix_pos <= wt_pix_pos + 1; 337 | end 338 | wt_pix >=2264 && wt_pix <= 2274 : begin//3 339 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 340 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 341 | /* 342 | $display("time = %t | weighted_pixel[22] = %d | weighted_pixel[23] = %d | weighted_pixel[24] = %d | weighted_pixel[25] = %d | weighted_pixel[26] = %d | ", 343 | $time , weighted_pixel[22], weighted_pixel[23], weighted_pixel[24], weighted_pixel[25], weighted_pixel[26]); 344 | $display("weighted_pixel[27] = %d | weighted_pixel[28] = %d | weighted_pixel[29] = %d | weighted_pixel[30] = %d | weighted_pixel[31] = %d | weighted_pixel[32] = %d ", 345 | weighted_pixel[27], weighted_pixel[28], weighted_pixel[29], weighted_pixel[30], weighted_pixel[31], weighted_pixel[32]); 346 | */ 347 | wt_pix_pos <= wt_pix_pos + 1; 348 | end 349 | wt_pix >=2277 && wt_pix <= 2287 : begin//4 350 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 351 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 352 | /* 353 | $display("time = %t | weighted_pixel[33] = %d | weighted_pixel[34] = %d | weighted_pixel[35] = %d | weighted_pixel[36] = %d | weighted_pixel[37] = %d | ", 354 | $time , weighted_pixel[33], weighted_pixel[34], weighted_pixel[35], weighted_pixel[36], weighted_pixel[37]); 355 | $display("weighted_pixel[38] = %d | weighted_pixel[39] = %d | weighted_pixel[40] = %d | weighted_pixel[41] = %d | weighted_pixel[42] = %d | weighted_pixel[43] = %d ", 356 | weighted_pixel[38], weighted_pixel[39], weighted_pixel[40], weighted_pixel[41], weighted_pixel[42], weighted_pixel[43]); 357 | */ 358 | wt_pix_pos <= wt_pix_pos + 1; 359 | end 360 | wt_pix >=2290 && wt_pix <= 2300 : begin//5 361 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 362 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 363 | /* 364 | $display("time = %t | weighted_pixel[44] = %d | weighted_pixel[45] = %d | weighted_pixel[46] = %d | weighted_pixel[47] = %d | weighted_pixel[48] = %d | ", 365 | $time , weighted_pixel[44], weighted_pixel[45], weighted_pixel[46], weighted_pixel[47], weighted_pixel[48]); 366 | $display("weighted_pixel[49] = %d | weighted_pixel[50] = %d | weighted_pixel[51] = %d | weighted_pixel[52] = %d | weighted_pixel[53] = %d | weighted_pixel[54] = %d ", 367 | weighted_pixel[49], weighted_pixel[50], weighted_pixel[51], weighted_pixel[52], weighted_pixel[53], weighted_pixel[54]); 368 | */ 369 | wt_pix_pos <= wt_pix_pos + 1; 370 | end 371 | wt_pix >=2303 && wt_pix <= 2313 : begin//6 372 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 373 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 374 | /* 375 | $display("time = %t | weighted_pixel[55] = %d | weighted_pixel[56] = %d | weighted_pixel[57] = %d | weighted_pixel[58] = %d | weighted_pixel[59] = %d | ", 376 | $time , weighted_pixel[55], weighted_pixel[56], weighted_pixel[57], weighted_pixel[58], weighted_pixel[59]); 377 | $display("weighted_pixel[60] = %d | weighted_pixel[61] = %d | weighted_pixel[62] = %d | weighted_pixel[63] = %d | weighted_pixel[64] = %d | weighted_pixel[65] = %d ", 378 | weighted_pixel[60], weighted_pixel[61], weighted_pixel[62], weighted_pixel[63], weighted_pixel[64], weighted_pixel[65]); 379 | */ 380 | wt_pix_pos <= wt_pix_pos + 1; 381 | end 382 | wt_pix >=2316 && wt_pix <= 2326 : begin//7 383 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 384 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 385 | /* 386 | $display("time = %t | weighted_pixel[66] = %d | weighted_pixel[67] = %d | weighted_pixel[68] = %d | weighted_pixel[69] = %d | weighted_pixel[70] = %d | ", 387 | $time , weighted_pixel[66], weighted_pixel[67], weighted_pixel[68], weighted_pixel[69], weighted_pixel[70]); 388 | $display("weighted_pixel[71] = %d | weighted_pixel[72] = %d | weighted_pixel[73] = %d | weighted_pixel[74] = %d | weighted_pixel[75] = %d | weighted_pixel[76] = %d ", 389 | weighted_pixel[71], weighted_pixel[72], weighted_pixel[73], weighted_pixel[74], weighted_pixel[75], weighted_pixel[76]); 390 | */ 391 | wt_pix_pos <= wt_pix_pos + 1; 392 | end 393 | wt_pix >=2329 && wt_pix <= 2339 : begin//8 394 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 395 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 396 | /* 397 | $display("time = %t | weighted_pixel[77] = %d | weighted_pixel[78] = %d | weighted_pixel[79] = %d | weighted_pixel[80] = %d | weighted_pixel[81] = %d | ", 398 | $time , weighted_pixel[77], weighted_pixel[78], weighted_pixel[79], weighted_pixel[80], weighted_pixel[81]); 399 | $display("weighted_pixel[82] = %d | weighted_pixel[83] = %d | weighted_pixel[84] = %d | weighted_pixel[85] = %d | weighted_pixel[86] = %d | weighted_pixel[87] = %d ", 400 | weighted_pixel[82], weighted_pixel[83], weighted_pixel[84], weighted_pixel[85], weighted_pixel[86], weighted_pixel[87]); 401 | */ 402 | wt_pix_pos <= wt_pix_pos + 1; 403 | end 404 | wt_pix >=2342 && wt_pix <= 2352 : begin//9 405 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 406 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 407 | /* 408 | $display("time = %t | weighted_pixel[88] = %d | weighted_pixel[89] = %d | weighted_pixel[90] = %d | weighted_pixel[91] = %d | weighted_pixel[92] = %d | ", 409 | $time , weighted_pixel[88], weighted_pixel[89], weighted_pixel[90], weighted_pixel[91], weighted_pixel[92]); 410 | $display("weighted_pixel[93] = %d | weighted_pixel[94] = %d | weighted_pixel[95] = %d | weighted_pixel[96] = %d | weighted_pixel[97] = %d | weighted_pixel[98] = %d ", 411 | weighted_pixel[93], weighted_pixel[94], weighted_pixel[95], weighted_pixel[96], weighted_pixel[97], weighted_pixel[98]); 412 | */ 413 | wt_pix_pos <= wt_pix_pos + 1; 414 | end 415 | wt_pix >=2355 && wt_pix <= 2365 : begin//10 416 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 417 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 418 | /* 419 | $display("time = %t | weighted_pixel[99] = %d | weighted_pixel[100] = %d | weighted_pixel[101] = %d | weighted_pixel[102] = %d | weighted_pixel[103] = %d | ", 420 | $time , weighted_pixel[99], weighted_pixel[100], weighted_pixel[101], weighted_pixel[102], weighted_pixel[103]); 421 | $display("weighted_pixel[104] = %d | weighted_pixel[105] = %d | weighted_pixel[106] = %d | weighted_pixel[107] = %d | weighted_pixel[108] = %d | weighted_pixel[109] = %d ", 422 | weighted_pixel[104], weighted_pixel[105], weighted_pixel[106], weighted_pixel[107], weighted_pixel[108], weighted_pixel[109]); 423 | */ 424 | wt_pix_pos <= wt_pix_pos + 1; 425 | end 426 | wt_pix >=2368 && wt_pix <= 2378 : begin//11 427 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 428 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 429 | /* 430 | $display("time = %t | weighted_pixel[110] = %d | weighted_pixel[111] = %d | weighted_pixel[112] = %d | weighted_pixel[113] = %d | weighted_pixel[114] = %d | ", 431 | $time , weighted_pixel[110], weighted_pixel[111], weighted_pixel[112], weighted_pixel[113], weighted_pixel[114]); 432 | $display("weighted_pixel[115] = %d | weighted_pixel[116] = %d | weighted_pixel[117] = %d | weighted_pixel[118] = %d | weighted_pixel[119] = %d | weighted_pixel[120] = %d ", 433 | weighted_pixel[115], weighted_pixel[116], weighted_pixel[117], weighted_pixel[118], weighted_pixel[119], weighted_pixel[120]); 434 | */ 435 | wt_pix_pos <= wt_pix_pos + 1; 436 | end 437 | wt_pix >=2381 && wt_pix <= 2391 : begin//12 438 | weighted_pixel[wt_pix_pos] <= {lfsr_random[10], shift_reg[1023], shift_reg[895], shift_reg[767], shift_reg[639], 439 | shift_reg[511], shift_reg[383], shift_reg[255], shift_reg[127]}; 440 | /* 441 | $display("time = %t | weighted_pixel[121] = %d | weighted_pixel[122] = %d | weighted_pixel[123] = %d | weighted_pixel[124] = %d | weighted_pixel[125] = %d | ", 442 | $time , weighted_pixel[121], weighted_pixel[122], weighted_pixel[123], weighted_pixel[124], weighted_pixel[125]); 443 | $display("weighted_pixel[126] = %d | weighted_pixel[127] = %d ",weighted_pixel[126], weighted_pixel[127]); 444 | */ 445 | wt_pix_pos <= wt_pix_pos + 1; 446 | end 447 | default : begin 448 | //weighted_pixel[wt_pix_pos] <= 9'bx; 449 | //$display(" "); 450 | //wt_pix_pos <= 9'bx; 451 | end 452 | endcase 453 | 454 | end 455 | 456 | end 457 | 458 | 459 | 460 | // **---------------------------------------------------------------------------------------------------** 461 | // ** PARALLEL ADDER ** 462 | // **---------------------------------------------------------------------------------------------------** 463 | 464 | always @(posedge clk2 or negedge reset_an2) 465 | begin 466 | if (!reset_an2 == 1) 467 | begin 468 | sum00 <= 0; 469 | sum01 <= 0; 470 | sum02 <= 0; 471 | sum03 <= 0; 472 | end 473 | else 474 | begin 475 | sum00 <= weighted_pixel[0] + weighted_pixel[1]+weighted_pixel[2]; 476 | sum01 <= sum00 + weighted_pixel[3]+weighted_pixel[4]; 477 | sum02 <= sum01+ weighted_pixel[5]+weighted_pixel[6]; 478 | sum03 <= sum02 + weighted_pixel[7]; 479 | 480 | //$display ("%b", sum03); 481 | end 482 | end 483 | 484 | always @(posedge clk2 or negedge reset_an2) 485 | begin 486 | if (!reset_an2 == 1) 487 | begin 488 | sum10 <= 0; 489 | sum11 <= 0; 490 | sum12 <= 0; 491 | sum13 <= 0; 492 | end 493 | else 494 | begin 495 | sum10 <= weighted_pixel[8] + weighted_pixel[9]+weighted_pixel[10]; 496 | sum11 <= sum10 + weighted_pixel[11]+weighted_pixel[12]; 497 | sum12 <= sum11+ weighted_pixel[13]+weighted_pixel[14]; 498 | sum13 <= sum12 + weighted_pixel[15]; 499 | 500 | //$display ("%b", sum13); 501 | end 502 | end 503 | 504 | always @(posedge clk2 or negedge reset_an2) 505 | begin 506 | if (!reset_an2 == 1) 507 | begin 508 | sum20 <= 0; 509 | sum21 <= 0; 510 | sum22 <= 0; 511 | sum23 <= 0; 512 | end 513 | else 514 | begin 515 | sum20 <= weighted_pixel[16] + weighted_pixel[17]+weighted_pixel[18]; 516 | sum21 <= sum20 + weighted_pixel[19]+weighted_pixel[20]; 517 | sum22 <= sum21+ weighted_pixel[21]+weighted_pixel[22]; 518 | sum23 <= sum22 + weighted_pixel[23]; 519 | 520 | //$display ("%b", sum23); 521 | end 522 | end 523 | 524 | always @(posedge clk2 or negedge reset_an2) 525 | begin 526 | if (!reset_an2 == 1) 527 | begin 528 | sum30 <= 0; 529 | sum31 <= 0; 530 | sum32 <= 0; 531 | sum33 <= 0; 532 | end 533 | else 534 | begin 535 | sum30 <= weighted_pixel[24] + weighted_pixel[25]+weighted_pixel[26]; 536 | sum31 <= sum30 + weighted_pixel[27]+weighted_pixel[28]; 537 | sum32 <= sum31+ weighted_pixel[29]+weighted_pixel[30]; 538 | sum33 <= sum32 + weighted_pixel[31]; 539 | 540 | //$display ("%b", sum33); 541 | end 542 | end 543 | 544 | always @(posedge clk2 or negedge reset_an2) 545 | begin 546 | if (!reset_an2 == 1) 547 | begin 548 | sum40 <= 0; 549 | sum41 <= 0; 550 | sum42 <= 0; 551 | sum43 <= 0; 552 | end 553 | else 554 | begin 555 | sum40 <= weighted_pixel[32] + weighted_pixel[33]+weighted_pixel[34]; 556 | sum41 <= sum40 + weighted_pixel[35]+weighted_pixel[36]; 557 | sum42 <= sum41+ weighted_pixel[37]+weighted_pixel[38]; 558 | sum43 <= sum42 + weighted_pixel[39]; 559 | 560 | //$display ("%b", sum43); 561 | end 562 | end 563 | 564 | always @(posedge clk2 or negedge reset_an2) 565 | begin 566 | if (!reset_an2 == 1) 567 | begin 568 | sum50 <= 0; 569 | sum51 <= 0; 570 | sum52 <= 0; 571 | sum53 <= 0; 572 | end 573 | else 574 | begin 575 | sum50 <= weighted_pixel[40] + weighted_pixel[41]+weighted_pixel[42]; 576 | sum51 <= sum50 + weighted_pixel[43]+weighted_pixel[44]; 577 | sum52 <= sum51+ weighted_pixel[45]+weighted_pixel[46]; 578 | sum53 <= sum52 + weighted_pixel[47]; 579 | 580 | //$display ("%b", sum53); 581 | end 582 | end 583 | 584 | always @(posedge clk2 or negedge reset_an2) 585 | begin 586 | if (!reset_an2 == 1) 587 | begin 588 | sum60 <= 0; 589 | sum61 <= 0; 590 | sum62 <= 0; 591 | sum63 <= 0; 592 | end 593 | else 594 | begin 595 | sum60 <= weighted_pixel[48] + weighted_pixel[49]+weighted_pixel[50]; 596 | sum61 <= sum60 + weighted_pixel[51]+weighted_pixel[52]; 597 | sum62 <= sum61+ weighted_pixel[53]+weighted_pixel[54]; 598 | sum63 <= sum62 + weighted_pixel[55]; 599 | 600 | //$display ("%b", sum63); 601 | end 602 | end 603 | 604 | always @(posedge clk2 or negedge reset_an2) 605 | begin 606 | if (!reset_an2 == 1) 607 | begin 608 | sum70 <= 0; 609 | sum71 <= 0; 610 | sum72 <= 0; 611 | sum73 <= 0; 612 | end 613 | else 614 | begin 615 | sum70 <= weighted_pixel[56] + weighted_pixel[57]+weighted_pixel[58]; 616 | sum71 <= sum70 + weighted_pixel[59]+weighted_pixel[60]; 617 | sum72 <= sum71+ weighted_pixel[61]+weighted_pixel[62]; 618 | sum73 <= sum72 + weighted_pixel[63]; 619 | 620 | //$display ("%b", sum73); 621 | end 622 | end 623 | 624 | always @(posedge clk2 or negedge reset_an2) 625 | begin 626 | if (!reset_an2 == 1) 627 | begin 628 | sum80 <= 0; 629 | sum81 <= 0; 630 | sum82 <= 0; 631 | sum83 <= 0; 632 | end 633 | else 634 | begin 635 | sum80 <= weighted_pixel[64] + weighted_pixel[65]+weighted_pixel[66]; 636 | sum81 <= sum80 + weighted_pixel[67]+weighted_pixel[68]; 637 | sum82 <= sum81+ weighted_pixel[69]+weighted_pixel[70]; 638 | sum83 <= sum82 + weighted_pixel[71]; 639 | 640 | //$display ("%b", sum83); 641 | end 642 | end 643 | 644 | always @(posedge clk2 or negedge reset_an2) 645 | begin 646 | if (!reset_an2 == 1) 647 | begin 648 | sum90 <= 0; 649 | sum91 <= 0; 650 | sum92 <= 0; 651 | sum93 <= 0; 652 | end 653 | else 654 | begin 655 | sum90 <= weighted_pixel[72] + weighted_pixel[73]+weighted_pixel[74]; 656 | sum91 <= sum90 + weighted_pixel[75]+weighted_pixel[76]; 657 | sum92 <= sum91+ weighted_pixel[77]+weighted_pixel[78]; 658 | sum93 <= sum92 + weighted_pixel[79]; 659 | 660 | //$display ("%b", sum93); 661 | end 662 | end 663 | 664 | always @(posedge clk2 or negedge reset_an2) 665 | begin 666 | if (!reset_an2 == 1) 667 | begin 668 | sum100 <= 0; 669 | sum101 <= 0; 670 | sum102 <= 0; 671 | sum103 <= 0; 672 | end 673 | else 674 | begin 675 | sum100 <= weighted_pixel[80] + weighted_pixel[81]+weighted_pixel[82]; 676 | sum101 <= sum100 + weighted_pixel[83]+weighted_pixel[84]; 677 | sum102 <= sum101+ weighted_pixel[85]+weighted_pixel[86]; 678 | sum103 <= sum102 + weighted_pixel[87]; 679 | 680 | //$display ("%b", sum103); 681 | end 682 | end 683 | 684 | always @(posedge clk2 or negedge reset_an2) 685 | begin 686 | if (!reset_an2 == 1) 687 | begin 688 | sum110 <= 0; 689 | sum111 <= 0; 690 | sum112 <= 0; 691 | sum113 <= 0; 692 | end 693 | else 694 | begin 695 | sum110 <= weighted_pixel[88] + weighted_pixel[89]+weighted_pixel[90]; 696 | sum111 <= sum110 + weighted_pixel[91]+weighted_pixel[92]; 697 | sum112 <= sum111+ weighted_pixel[93]+weighted_pixel[94]; 698 | sum113 <= sum112 + weighted_pixel[95]; 699 | 700 | //$display ("%b", sum113); 701 | end 702 | end 703 | 704 | always @(posedge clk2 or negedge reset_an2) 705 | begin 706 | if (!reset_an2 == 1) 707 | begin 708 | sum120 <= 0; 709 | sum121 <= 0; 710 | sum122 <= 0; 711 | sum123 <= 0; 712 | end 713 | else 714 | begin 715 | sum120 <= weighted_pixel[96] + weighted_pixel[97]+weighted_pixel[98]; 716 | sum121 <= sum120 + weighted_pixel[99]+weighted_pixel[100]; 717 | sum122 <= sum121+ weighted_pixel[101]+weighted_pixel[102]; 718 | sum123 <= sum122 + weighted_pixel[103]; 719 | 720 | //$display ("%b", sum123); 721 | end 722 | end 723 | 724 | always @(posedge clk2 or negedge reset_an2) 725 | begin 726 | if (!reset_an2 == 1) 727 | begin 728 | sum130 <= 0; 729 | sum131 <= 0; 730 | sum132 <= 0; 731 | sum133 <= 0; 732 | end 733 | else 734 | begin 735 | sum130 <= weighted_pixel[104] + weighted_pixel[105]+weighted_pixel[106]; 736 | sum131 <= sum130 + weighted_pixel[107]+weighted_pixel[108]; 737 | sum132 <= sum131+ weighted_pixel[109]+weighted_pixel[110]; 738 | sum133 <= sum132 + weighted_pixel[111]; 739 | 740 | //$display ("%b", sum133); 741 | end 742 | end 743 | 744 | always @(posedge clk2 or negedge reset_an2) 745 | begin 746 | if (!reset_an2 == 1) 747 | begin 748 | sum140 <= 0; 749 | sum141 <= 0; 750 | sum142 <= 0; 751 | sum143 <= 0; 752 | end 753 | else 754 | begin 755 | sum140 <= weighted_pixel[112] + weighted_pixel[113]+weighted_pixel[114]; 756 | sum141 <= sum140 + weighted_pixel[115]+weighted_pixel[116]; 757 | sum142 <= sum141+ weighted_pixel[117]+weighted_pixel[118]; 758 | sum143 <= sum142 + weighted_pixel[119]; 759 | 760 | //$display ("%b", sum143); 761 | end 762 | end 763 | 764 | always @(posedge clk2 or negedge reset_an2) 765 | begin 766 | if (!reset_an2 == 1) 767 | begin 768 | sum150 <= 0; 769 | sum151 <= 0; 770 | sum152 <= 0; 771 | sum153 <= 0; 772 | end 773 | else 774 | begin 775 | sum150 <= weighted_pixel[120] + weighted_pixel[121]+weighted_pixel[122]; 776 | sum151 <= sum150 + weighted_pixel[123]+weighted_pixel[124]; 777 | sum152 <= sum151+ weighted_pixel[125]+weighted_pixel[126]; 778 | sum153 <= sum152 + weighted_pixel[127]; 779 | 780 | //$display ("%b", sum153); 781 | end 782 | end 783 | 784 | always @(posedge clk2 or negedge reset_an2) 785 | begin 786 | if (!reset_an2 == 1) 787 | begin 788 | sum160 <= 0; 789 | sum161 <= 0; 790 | end 791 | else 792 | begin 793 | 794 | sum160 <= sum03 + sum13+ sum23; 795 | sum161 <= sum160 +sum33; 796 | 797 | end 798 | end 799 | always @(posedge clk2 or negedge reset_an2) 800 | begin 801 | if (!reset_an2 == 1) 802 | begin 803 | sum170 <= 0; 804 | sum171 <= 0; 805 | end 806 | else 807 | begin 808 | 809 | sum170 <= sum43 + sum53+ sum63; 810 | sum171 <= sum170 +sum73; 811 | 812 | end 813 | end 814 | 815 | always @(posedge clk2 or negedge reset_an2) 816 | begin 817 | if (!reset_an2 == 1) 818 | begin 819 | sum180 <= 0; 820 | sum181 <= 0; 821 | end 822 | else 823 | begin 824 | 825 | sum180 <= sum83 + sum93+ sum103; 826 | sum181 <= sum180 +sum113; 827 | 828 | end 829 | end 830 | 831 | always @(posedge clk2 or negedge reset_an2) 832 | begin 833 | if (!reset_an2 == 1) 834 | begin 835 | sum190 <= 0; 836 | sum191 <= 0; 837 | end 838 | else 839 | begin 840 | 841 | sum190 <= sum123 + sum133+ sum143; 842 | sum191 <= sum190 +sum153; 843 | 844 | end 845 | end 846 | 847 | always @(posedge clk2 or negedge reset_an2) 848 | begin 849 | if (!reset_an2 == 1) 850 | begin 851 | sum200 <= 0; 852 | out_stimulus <= 0; 853 | end 854 | else 855 | begin 856 | 857 | sum200 <= sum161 + sum171+ sum181; 858 | out_stimulus <= sum200 +sum191; 859 | //$display("%b", out_stimulus); 860 | end 861 | end 862 | 863 | endmodule -------------------------------------------------------------------------------- /verilog_codes/wptr_full.v: -------------------------------------------------------------------------------- 1 | module wptr_full (wfull, waddr, wptr, wq2_rptr, winc, wclk, wrst_n); 2 | 3 | parameter ADDRSIZE = 9; 4 | 5 | output reg wfull; 6 | output [ADDRSIZE-1:0] waddr; 7 | output reg [ADDRSIZE :0] wptr; 8 | input [ADDRSIZE :0] wq2_rptr; 9 | input winc, wclk, wrst_n; 10 | 11 | reg [ADDRSIZE:0] wbin; 12 | wire [ADDRSIZE:0] wgraynext, wbinnext; 13 | 14 | // GRAYSTYLE2 pointer 15 | 16 | always @(posedge wclk or negedge wrst_n) 17 | 18 | begin 19 | if (!wrst_n) {wbin, wptr} <= 0; 20 | else {wbin, wptr} <= {wbinnext, wgraynext}; 21 | end 22 | 23 | // Memory write-address pointer (okay to use binary to address memory) 24 | assign waddr = wbin[ADDRSIZE-1:0]; 25 | assign wbinnext = wbin + (winc & ~wfull); 26 | assign wgraynext = (wbinnext>>1) ^ wbinnext; 27 | 28 | //------------------------------------------------------------------ 29 | // Simplified version of the three necessary full-tests: 30 | // assign wfull_val=((wgnext[ADDRSIZE] !=wq2_rptr[ADDRSIZE] ) && 31 | // (wgnext[ADDRSIZE-1] !=wq2_rptr[ADDRSIZE-1]) && 32 | // (wgnext[ADDRSIZE-2:0]==wq2_rptr[ADDRSIZE-2:0])); 33 | //------------------------------------------------------------------ 34 | 35 | assign wfull_val = (wgraynext=={~wq2_rptr[ADDRSIZE:ADDRSIZE-1], wq2_rptr[ADDRSIZE-2:0]}); 36 | always @(posedge wclk or negedge wrst_n) 37 | 38 | begin 39 | if (!wrst_n) wfull <= 1'b0; 40 | else wfull <= wfull_val; 41 | end 42 | 43 | endmodule --------------------------------------------------------------------------------