Asraf Mohamed
Newbie level 3
- Joined
- May 1, 2014
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 63
hai there,
im doing project on converting analog signal to digital signal with Spartan 3e board.unfortunately, i have 2 issue here, first, i don't know whether the coding working properly..second..i need to save the converted analog signal into text file inside my computer. i attached with this threads my coding as well..please advise me..thank you..
im doing project on converting analog signal to digital signal with Spartan 3e board.unfortunately, i have 2 issue here, first, i don't know whether the coding working properly..second..i need to save the converted analog signal into text file inside my computer. i attached with this threads my coding as well..please advise me..thank you..
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// module test(clk,reset,spi_sck,amp_cs,spi_mosi,spi_miso,ad_conv,spi_ss_b,amp_cs,dac_cs,sf_ce0,fpga_init_b,amp_shdn,dac_clr,led); input clk,reset; input spi_miso; output reg [7:0] led; output reg spi_sck; output reg amp_cs; output reg spi_mosi; output reg ad_conv; output reg amp_shdn; output reg dac_clr; output reg spi_ss_b; output reg dac_cs; output reg sf_ce0; output reg fpga_init_b; reg [6:0] counter;////count spi_sck for period 100 cycles reg [4:0] counter2;////count spi_sck for period 20 cycles reg [5:0] counter3;////count spi_sck for period 34 cycles reg [4:0] state; reg [1:0] state2; reg [7:0] data; reg [13:0] data_adc0;//assume from data to spi_miso first to test reg [13:0] data_adc1; reg [3:0] kire; reg [3:0] kire_14bit; reg [2:0] kire_adc; reg [27:0] counter_led; reg sclk; reg [7:0] mem1 [0:255];// 8 bits memory with 16 location reg [7:0] mem2 [0:255];// 8 bits memory with 16 location reg [7:0] mem3 [0:255];// 8 bits memory with 16 location reg [7:0] mem4 [0:255];// 8 bits memory with 16 location reg [7:0] mem5 [0:255];// 8 bits memory with 16 location reg [7:0] mem6 [0:255];// 8 bits memory with 16 location reg [15:0] i1,i2,i3,i4,i5,i6; integer m1,m2,m3,m4,m5,m6; initial begin amp_cs<=1; spi_sck=0; counter<=0; counter2<=0; counter3<=0; data=8'b00010001; data_adc0=14'b0; data_adc1=14'b0; kire<=4'd7; kire_adc<=4'd0; kire_14bit<=4'd13; ad_conv<=0; led<=0; end always@(posedge clk or posedge reset) begin spi_ss_b<=1; dac_cs<=1; sf_ce0<=1; fpga_init_b<=1; amp_shdn<=0; dac_clr<=0; end /////////////////////////counter////////////////////////////////// always@(posedge clk or posedge reset) begin if(reset) begin counter<=0; end else begin if(counter==7'd100) begin counter<=0; end else begin counter<=counter+1'b1; end end end /////////////////////////counter2////////////////////////////////// always@(posedge clk or posedge reset) begin if(reset) begin counter2<=0; end else begin if(counter2==5'd20) begin counter2<=0; end else begin counter2<=counter2+1'b1; end end end ////////////////////////////for slow clock///////////////////// always@(posedge clk or posedge reset) begin if(reset) counter_led<=0; else begin if(counter_led==28'd5000000) counter_led<=0; else counter_led<=counter_led+1; end end always@(posedge clk or posedge reset) begin if(reset) sclk=0; else if(counter_led==28'd5000000) sclk=0; else if(counter_led==28'd0) sclk=1; end always@(posedge clk or posedge reset ) begin if(reset) begin state<=0; end else begin case(state) 0: begin amp_cs<=1; ad_conv<=0; kire<=4'd7; kire_adc<=4'd0; counter3<=6'd0; if(counter==7'd20) state<=1; else state<=0; end 1: begin amp_cs<=0; spi_sck=0; if(counter==7'd50) state<=2; else state<=1; end 2: begin spi_sck=1; spi_mosi<=data[kire];//data for amplifier if(counter==7'd100) state<=3; else state<=2; end 3: begin spi_sck=0; kire<=kire-1'b1; if(kire==4'd0) state<=4; else state<=1; end 4: begin amp_cs<=1;//disable first...amplifier ad_conv<=1; kire_adc<=kire_adc+1'b1; if(kire_adc==4'd3) state<=5; else state<=4; end 5: begin ad_conv<=0; spi_sck=0; kire_adc<=kire_adc+1'b1; if(kire_adc==4'd7) state<=6; else state<=5; end 6: begin kire_adc<=0; counter3<=counter3+1'b1; if(counter3==6'd2) state<=9; else state<=7; end 7: begin spi_sck=1; if(counter2==5'd10) state<=8; else state<=7; end 8: begin spi_sck=0; if(counter2==5'd20) state<=6; else state<=8; end 9: begin spi_sck=1; data_adc0[kire_14bit]<=spi_miso; //spi_miso<=data_adc0[kire_14bit]; if(counter2==5'd10) state<=10; else state<=9; end 10: begin spi_sck=0; if(counter2==5'd20) state<=11; else state<=10; end 11: begin kire_14bit<=kire_14bit-1'b1; counter3<=counter3+1'b1; if(kire_14bit==0) state<=12; else state<=9; end 12: begin kire_14bit<=4'd13; spi_sck=1; if(counter2==5'd10) state<=13; else state<=12; end 13: begin spi_sck=0; if(counter2==5'd20) state<=14; else state<=13; end 14: begin counter3<=counter3+1'b1; if(counter3==6'd18) state<=15; else state<=12; end 15: begin spi_sck=1; data_adc1[kire_14bit]<=spi_miso; if(counter2==5'd10) state<=16; else state<=15; end 16: begin spi_sck=0; if(counter2==5'd20) state<=17; else state<=16; end 17: begin kire_14bit<=kire_14bit-1'b1; counter3<=counter3+1'b1; if(kire_14bit==0) state<=18; else state<=15; end 18: begin kire_14bit<=4'd13; spi_sck=1; if(counter2==5'd10) state<=19; else state<=18; end 19: begin spi_sck=0; if(counter2==5'd20) state<=20; else state<=19; end 20: begin counter3<=counter3+1'b1; if(counter3==6'd34) state<=21;//state<=0; else state<=18; end 21: begin ad_conv<=0; kire_adc<=kire_adc+1'b1; if(kire_adc==4'd3) state<=22; else state<=21; end 22: begin ad_conv<=1; spi_sck=0; kire_adc<=kire_adc+1'b1; if(kire_adc==4'd7) state<=23; else state<=22; end 23: begin kire_adc<=0; ad_conv<=0; state<=0; end endcase end end //////////////////program untuk led run dgn slow clock///////////////////////////// always@(posedge sclk or posedge reset) begin if(reset) led<=0; else led<=data_adc0[13:6]; end endmodule
Last edited by a moderator: