+ Post New Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 27 of 27
  1. #21
    Member level 5
    Points: 614, Level: 5

    Join Date
    Feb 2016
    Posts
    83
    Helped
    0 / 0
    Points
    614
    Level
    5

    Re: Cordic Algorithm Question

    ads-ee:

    design.sv is actually terminology used by edaplayground. It is actually referring to cordic_pipelined.v which is the top design module.

    I am getting the following verbose output for using negedge clk to trigger the $display().
    The generate for loop is actually pipeline design where each stage is the same logic.

    I need to solve this $display() issue because my verilator simulation failed at one test case and I need to see what happen at every stage at every clock cycle.

    Code:
    [2017-05-23 22:51:55 EDT] iverilog '-Wall' 'cordic_stage.v' design.sv testbench.sv  && unbuffer vvp a.out  
    VCD info: dumpfile cordic_pipelined.vcd opened for output.
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 7, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000111
    i= 6, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000001110
    i= 5, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000011100
    i= 4, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000111001
    i= 3, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00001110010
    i= 2, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00011100000
    i= 1, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00110101001
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 0, arctan[i]=01011010000
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 0, arctan[i]=00110101001
    i= 2, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00011100000
    i= 3, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00001110010
    i= 4, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000111001
    i= 5, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000011100
    i= 6, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000001110
    i= 7, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000111
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 7, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000111
    i= 6, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000001110
    i= 5, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000011100
    i= 4, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000111001
    i= 3, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00001110010
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 1, arctan[i]=00011100000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 1, arctan[i]=00001110010
    i= 4, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000111001
    i= 5, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000011100
    i= 6, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000001110
    i= 7, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000111
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 7, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000111
    i= 6, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000001110
    i= 5, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000011100
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 1, arctan[i]=00000111001
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 1, arctan[i]=00000011100
    i= 6, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000001110
    i= 7, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000111
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 7, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000111
    i= 6, x_i=10110100110111100, y_i=10110101000111000, z_i=11111111110, x_next=10110111101100100, y_next=10110010010010010, z_next=00000001100, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 1, arctan[i]=00000001110
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=10110100110111100, y_o=10110101000111000, z_o=11111111110, d= 1, arctan[i]=00000011100
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=10110100110111100, y_o=10110101000111000, z_o=11111111110, d= 1, arctan[i]=00000011100
    i= 6, x_i=10110100110111100, y_i=10110101000111000, z_i=11111111110, x_next=10110111101100100, y_next=10110010010010010, z_next=00000001100, x_o=10110111101100100, y_o=10110010010010010, z_o=00000001100, d= 1, arctan[i]=00000001110
    i= 7, x_i=10110111101100100, y_i=10110010010010010, z_i=00000001100, x_next=10110110010011011, y_next=10110011101110000, z_next=00000000101, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 0, arctan[i]=00000000111
    i= 8, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000011
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 9, x_i=xxxxxxxxxxxxxxxxx, y_i=xxxxxxxxxxxxxxxxx, z_i=xxxxxxxxxxx, x_next=xxxxxxxxxxxxxxxxx, y_next=xxxxxxxxxxxxxxxxx, z_next=xxxxxxxxxxx, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= x, arctan[i]=00000000001
    i= 8, x_i=10110110010011011, y_i=10110011101110000, z_i=00000000101, x_next=10110101100110100, y_next=10110100011011100, z_next=00000000010, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 0, arctan[i]=00000000011
    i= 7, x_i=10110111101100100, y_i=10110010010010010, z_i=00000001100, x_next=10110110010011011, y_next=10110011101110000, z_next=00000000101, x_o=10110110010011011, y_o=10110011101110000, z_o=00000000101, d= 0, arctan[i]=00000000111
    i= 6, x_i=10110100110111100, y_i=10110101000111000, z_i=11111111110, x_next=10110111101100100, y_next=10110010010010010, z_next=00000001100, x_o=10110111101100100, y_o=10110010010010010, z_o=00000001100, d= 1, arctan[i]=00000001110
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=10110100110111100, y_o=10110101000111000, z_o=11111111110, d= 1, arctan[i]=00000011100
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=10110100110111100, y_o=10110101000111000, z_o=11111111110, d= 1, arctan[i]=00000011100
    i= 6, x_i=10110100110111100, y_i=10110101000111000, z_i=11111111110, x_next=10110111101100100, y_next=10110010010010010, z_next=00000001100, x_o=10110111101100100, y_o=10110010010010010, z_o=00000001100, d= 1, arctan[i]=00000001110
    i= 7, x_i=10110111101100100, y_i=10110010010010010, z_i=00000001100, x_next=10110110010011011, y_next=10110011101110000, z_next=00000000101, x_o=10110110010011011, y_o=10110011101110000, z_o=00000000101, d= 0, arctan[i]=00000000111
    i= 8, x_i=10110110010011011, y_i=10110011101110000, z_i=00000000101, x_next=10110101100110100, y_next=10110100011011100, z_next=00000000010, x_o=10110101100110100, y_o=10110100011011100, z_o=00000000010, d= 0, arctan[i]=00000000011
    i= 9, x_i=10110101100110100, y_i=10110100011011100, z_i=00000000010, x_next=10110101010000000, y_next=10110100110010001, z_next=00000000001, x_o=xxxxxxxxxxxxxxxxx, y_o=xxxxxxxxxxxxxxxxx, z_o=xxxxxxxxxxx, d= 0, arctan[i]=00000000001
    i= 9, x_i=10110101100110100, y_i=10110100011011100, z_i=00000000010, x_next=10110101010000000, y_next=10110100110010001, z_next=00000000001, x_o=10110101010000000, y_o=10110100110010001, z_o=00000000001, d= 0, arctan[i]=00000000001
    i= 8, x_i=10110110010011011, y_i=10110011101110000, z_i=00000000101, x_next=10110101100110100, y_next=10110100011011100, z_next=00000000010, x_o=10110101100110100, y_o=10110100011011100, z_o=00000000010, d= 0, arctan[i]=00000000011
    i= 7, x_i=10110111101100100, y_i=10110010010010010, z_i=00000001100, x_next=10110110010011011, y_next=10110011101110000, z_next=00000000101, x_o=10110110010011011, y_o=10110011101110000, z_o=00000000101, d= 0, arctan[i]=00000000111
    i= 6, x_i=10110100110111100, y_i=10110101000111000, z_i=11111111110, x_next=10110111101100100, y_next=10110010010010010, z_next=00000001100, x_o=10110111101100100, y_o=10110010010010010, z_o=00000001100, d= 1, arctan[i]=00000001110
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=10110100110111100, y_o=10110101000111000, z_o=11111111110, d= 1, arctan[i]=00000011100
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 0, x_i=10011011011101001, y_i=00000000000000000, z_i=01011010000, x_next=10011011011101001, y_next=10011011011101001, z_next=00000000000, x_o=10011011011101001, y_o=10011011011101001, z_o=00000000000, d= 0, arctan[i]=01011010000
    i= 1, x_i=10011011011101001, y_i=10011011011101001, z_i=00000000000, x_next=01001101101110101, y_next=11101001001011101, z_next=11001010111, x_o=01001101101110101, y_o=11101001001011101, z_o=11001010111, d= 0, arctan[i]=00110101001
    i= 2, x_i=01001101101110101, y_i=11101001001011101, z_i=11001010111, x_next=10001000000001100, y_next=11010101110000000, z_next=11100110111, x_o=10001000000001100, y_o=11010101110000000, z_o=11100110111, d= 1, arctan[i]=00011100000
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100, y_next=11000100101111111, z_next=11110101001, x_o=10100010101111100, y_o=11000100101111111, z_o=11110101001, d= 1, arctan[i]=00001110010
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=10110100110111100, y_o=10110101000111000, z_o=11111111110, d= 1, arctan[i]=00000011100
    i= 6, x_i=10110100110111100, y_i=10110101000111000, z_i=11111111110, x_next=10110111101100100, y_next=10110010010010010, z_next=00000001100, x_o=10110111101100100, y_o=10110010010010010, z_o=00000001100, d= 1, arctan[i]=00000001110
    i= 7, x_i=10110111101100100, y_i=10110010010010010, z_i=00000001100, x_next=10110110010011011, y_next=10110011101110000, z_next=00000000101, x_o=10110110010011011, y_o=10110011101110000, z_o=00000000101, d= 0, arctan[i]=00000000111
    i= 8, x_i=10110110010011011, y_i=10110011101110000, z_i=00000000101, x_next=10110101100110100, y_next=10110100011011100, z_next=00000000010, x_o=10110101100110100, y_o=10110100011011100, z_o=00000000010, d= 0, arctan[i]=00000000011
    i= 9, x_i=10110101100110100, y_i=10110100011011100, z_i=00000000010, x_next=10110101010000000, y_next=10110100110010001, z_next=00000000001, x_o=10110101010000000, y_o=10110100110010001, z_o=00000000001, d= 0, arctan[i]=00000000001
    i= 9, x_i=10110101100110100, y_i=10110100011011100, z_i=00000000010, x_next=10110101010000000, y_next=10110100110010001, z_next=00000000001, x_o=10110101010000000, y_o=10110100110010001, z_o=00000000001, d= 0, arctan[i]=00000000001
    i= 8, x_i=10110110010011011, y_i=10110011101110000, z_i=00000000101, x_next=10110101100110100, y_next=10110100011011100, z_next=00000000010, x_o=10110101100110100, y_o=10110100011011100, z_o=00000000010, d= 0, arctan[i]=00000000011
    i= 7, x_i=10110111101100100, y_i=10110010010010010, z_i=00000001100, x_next=10110110010011011, y_next=10110011101110000, z_next=00000000101, x_o=10110110010011011, y_o=10110011101110000, z_o=00000000101, d= 0, arctan[i]=00000000111
    i= 6, x_i=10110100110111100, y_i=10110101000111000, z_i=11111111110, x_next=10110111101100100, y_next=10110010010010010, z_next=00000001100, x_o=10110111101100100, y_o=10110010010010010, z_o=00000001100, d= 1, arctan[i]=00000001110
    i= 5, x_i=10101111000010011, y_i=10111010100101000, z_i=11111100010, x_next=10110100110111100, y_next=10110101000111000, z_next=11111111110, x_o=10110100110111100, y_o=10110101000111000, z_o=11111111110, d= 1, arctan[i]=00000011100
    i= 4, x_i=10100010101111100, y_i=11000100101111111, z_i=11110101001, x_next=10101111000010011, y_next=10111010100101000, z_next=11111100010, x_o=10101111000010011, y_o=10111010100101000, z_o=11111100010, d= 1, arctan[i]=00000111001
    i= 3, x_i=10001000000001100, y_i=11010101110000000, z_i=11100110111, x_next=10100010101111100,Finding VCD file...
    ./cordic_pipelined.vcd
    [2017-05-23 22:51:55 EDT] Opening EPWave...
    Done
    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
    
    `timescale 1ns/100ps
     
    module cordic_pipelined_tb;
     
      reg clk;
      reg [10:0] z0;
      wire [16:0] xn, yn;
     
      cordic_pipelined C1
      (
        .clk(clk), .z0(z0), .xn(xn), .yn(yn)
      );
     
      initial begin
        $dumpfile("cordic_pipelined.vcd");
        $dumpvars(0, cordic_pipelined_tb);
        
        clk = 0;
        z0 = 11'b010_1101_0000; 
        
        #120 $finish;
      end
      
      always #5 clk = !clk;
      
      genvar j;
      generate
        for(j=0; j<C1.N; j=j+1)
          begin
            always @(negedge clk)
              begin
                $display("i=%2d, x_i=%b, y_i=%b, z_i=%b, x_next=%b, y_next=%b, z_next=%b, x_o=%b, y_o=%b, z_o=%b, d=%2d, arctan[i]=%b", C1.stage_generate[j].i, C1.stage_generate[j].stage_i.x_i, C1.stage_generate[j].stage_i.y_i, C1.stage_generate[j].stage_i.z_i, C1.stage_generate[j].stage_i.x_next, C1.stage_generate[j].stage_i.y_next, C1.stage_generate[j].stage_i.z_next, C1.stage_generate[j].stage_i.x_o, C1.stage_generate[j].stage_i.y_o, C1.stage_generate[j].stage_i.z_o, C1.stage_generate[j].stage_i.d, C1.stage_generate[j].stage_i.arctan);
              end
          end
      endgenerate
     
    endmodule



    •   Alt24th May 2017, 04:00

      advertising

        
       

  2. #22
    Super Moderator
    Points: 26,786, Level: 39
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    6,090
    Helped
    1493 / 1493
    Points
    26,786
    Level
    39

    Re: Cordic Algorithm Question

    Dont use a for loop for the display if you want the state of the pipeline at each clock cycle. It only makes the displayed report confusing. For loops replicate what is inside them hence you replicates a bunch of copies of the display task. I suggest again use a single display or better yet a monitor task (in an initial block) so you wont get tempted to use you software centric paradigm. Just include every signal in the pipeline in the task and put it in a forever loop along with @(negedge clk);



  3. #23
    Member level 5
    Points: 614, Level: 5

    Join Date
    Feb 2016
    Posts
    83
    Helped
    0 / 0
    Points
    614
    Level
    5

    Re: Cordic Algorithm Question

    ads-ee:

    Since $monitor displays every time one of its display parameters changes and only one $monitor per simulation is to be used, does this mean I need to include every single signals in all pipeline stages in the monitor task without the help of generate for loop ?

    Besides, why are you suggesting putting the monitor task in a forever loop along with @(negedge clk); ? What about the initial block that you mentioned ?



    •   Alt24th May 2017, 13:20

      advertising

        
       

  4. #24
    Super Moderator
    Points: 26,786, Level: 39
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    6,090
    Helped
    1493 / 1493
    Points
    26,786
    Level
    39

    Re: Cordic Algorithm Question

    Sorry was mixing the $display task method with the $monitor task. Just don't use a for loop with a $display task unless you like getting confusing output. Sometimes it makes sense if you are doing something like dumping the contents of a memory array, but it certainly doesn't make sense for trying to generate output for each clock cycle of a pipeline.

    Personally I hardly ever use the $monitor task, as I normally make self checking testbenches that spit out status of the simulation as it runs using the $display task. I normally just look at the waveforms than go through a huge output listing of the signal changes.

    Regardless you want all the signals in each stage of the pipeline on each clock. The best way to do that is to include all the signals in a single $display task, which will result in one line for each clock cycle. Not multiple lines as you have now (which is what I think is confusing things for you).

    BTW, tt will help with legibility of the file if you use %h instead of %b as you have been doing.



  5. #25
    Member level 5
    Points: 614, Level: 5

    Join Date
    Feb 2016
    Posts
    83
    Helped
    0 / 0
    Points
    614
    Level
    5

    Re: Cordic Algorithm Question

    ads-ee:

    I have done a self-check testbench with verilator and I have cos(x) and sin(x) , where 0<= x <= 89 cordic output passed my tolerance of 0.01

    I am stuck at 90 degrees. I am still working on how to solve this verilog bug with verilator debug cout.
    cordic outputs cos(90) as 0.997269 while it should be close to zero.

    Please let me know if you have any insights.
    I have also attached the files for verilator below if you are interested.

    cordic_pipelined.v
    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
    
    `timescale 1ns/100ps
     
    module cordic_pipelined(clk, z0, xn, yn);
      
      input clk;
      input signed [11:0] z0;
      output signed [17:0] xn, yn;
     
      parameter N = 10; // number of iterations
      
      reg [(N-1):0] d;
      wire signed [17:0] x [N:0];
      wire signed [17:0] y [N:0];
      wire signed [11:0] z [N:0];
     
      assign x[0] = 'b01_0011_0110_1110_1001;  // 0.60725 in binary
      assign y[0] = 0;
      assign z[0] = z0;
      
      wire signed [11:0] arctan [(N-1):0];
        
      assign arctan[0] = 'b0010_1101_0000; // 45.000;
      assign arctan[1] = 'b0001_1010_1001; // 26.565;
      assign arctan[2] = 'b0000_1110_0000; // 14.036;
      assign arctan[3] = 'b0000_0111_0010; // 7.1250;
      assign arctan[4] = 'b0000_0011_1001; // 3.5763;
      assign arctan[5] = 'b0000_0001_1100; // 1.7899;
      assign arctan[6] = 'b0000_0000_1110; // 0.8952;
      assign arctan[7] = 'b0000_0000_0111; // 0.4476;
      assign arctan[8] = 'b0000_0000_0011; // 0.2238;
      assign arctan[9] = 'b0000_0000_0001; // 0.1119;
     
      genvar i;
      generate
        for(i=0; i<N; i=i+1)
          begin: stage_generate
            cordic_stage #(.i(i)) stage_i
            (
              .clk(clk), 
              .x_i(x[i]), .x_o(x[i+1]), 
              .y_i(y[i]), .y_o(y[i+1]), 
              .z_i(z[i]), .z_o(z[i+1]),
              .arctan(arctan[i])
            );
     
          end
      endgenerate
     
       assign xn = x[N]; // xn = cos(z0)
       assign yn = y[N]; // yn = sin(z0)
         
    endmodule

    cordic_stage.v
    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
    
    `timescale 1ns/100ps
     
    module cordic_stage(clk, x_i, y_i, z_i, x_o, y_o, z_o, arctan);
      
      input signed [11:0] arctan;
      parameter i=0;
      
      input clk;
      input signed [17:0] x_i, y_i;
      input signed [11:0] z_i;
      output [17:0] x_o, y_o;
      output [11:0] z_o;
      
      reg d;
      reg signed [17:0] x_o, x_next;
      reg signed [17:0] y_o, y_next;
      reg signed [11:0] z_o, z_next;
      
      always @ (posedge clk)
        begin
          x_o <= x_next;
          y_o <= y_next;
          z_o <= z_next; 
        end
     
      always @(*)
        begin    
     
          d = (z_i[11] == 0) ? 0 : 1;
     
          if(d == 0) begin
            x_next = x_i - (y_i >>> i);
            y_next = y_i + (x_i >>> i);
            z_next = z_i - arctan;
          end
     
          else begin
            x_next = x_i + (y_i >>> i);
            y_next = y_i - (x_i >>> i);
            z_next = z_i + arctan;
          end
          
      end
     
    endmodule

    cordic_pipelined.cpp
    Code C++ - [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
    
    #include <verilated.h>          // Defines common routines
    #include "Vcordic_pipelined.h"
    #include "verilated_vcd_c.h"
     
    #include <assert.h>
    #include <math.h>  
    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <cstdio>
    #include <bitset>
    #include <limits>
    #include <iomanip>
    #include <typeinfo>
    #define PI 3.14159265
    #define TOLERANCE 0.01
    #define X(i) std::bitset<17>(uut->cordic_pipelined__DOT__stage_generate__BRA__##i##__KET____DOT____Vcellinp__stage_i__x_i)
    #define XOUT(i) cout << "x[" << i << "] = " << X(i) << endl 
     
    Vcordic_pipelined *uut;                     // Instantiation of module
    vluint64_t main_time = 0;       // Current simulation time
     
    double sc_time_stamp () {       // Called by $time in Verilog
        return main_time;           // converts to double, to match
        // what SystemC does
    }
     
    double cal_sin(unsigned int angle){     // Returns the sine of an angle of x radians.
        printf("angle = %d\n", angle);
        return sin(angle*PI/180);
    }
     
    double cal_cos(unsigned int angle){     // Returns the cosine of an angle of x radians.
        return cos(angle*PI/180);
    }
     
    void cout_debug_msg(void){
        static int i;
        
        XOUT(0); XOUT(1); XOUT(2); XOUT(3); XOUT(4); XOUT(5); XOUT(6); XOUT(7); XOUT(8); XOUT(9); 
      
    }
     
    // Reference: [url]http://www.cplusplus.com/forum/general/216385/[/url]
    template < std::size_t N = 17 > // input: bits of the N-bit significand
    double bits_to_double( const std::string& bits )
    {
        static_assert( N < std::numeric_limits<unsigned long long>::digits, "overflow" ) ;
     
        static constexpr auto denom = 1ULL << N ;
     
        std::string mantissa ; // remove non-digit characters
        for( char c : bits ) 
        if( c == '1' || c == '0' ) 
        {
           mantissa += c ; 
         //std::cout << "Loop  , mantissa = " << mantissa << '\n'; 
        }
        
        //std::cout << "before, mantissa = " << mantissa << '\n';
        mantissa.resize( N, '0' ) ; // truncate / append zeroes to make N bits
        //std::cout << "after , mantissa = " << mantissa << '\n';
        
        return double( std::bitset<N>(mantissa).to_ullong() ) / denom ;
    }
     
    int main(int argc, char** argv)
    {
        // turn on trace or not?
        bool vcdTrace = true;
        VerilatedVcdC* tfp = NULL;
     
        Verilated::commandArgs(argc, argv);   // Remember args
        uut = new Vcordic_pipelined;   // Create instance
     
        double cos_result, sin_result;
     
        uut->eval();
        uut->eval();
     
        if (vcdTrace)
        {
            Verilated::traceEverOn(true);
     
            tfp = new VerilatedVcdC;
            uut->trace(tfp, 99);
     
            std::string vcdname = argv[0];
            vcdname += ".vcd";
            std::cout << vcdname << std::endl;
            tfp->open(vcdname.c_str());
        }
        uut->z0 = 0x0; // 0000_0000.0000; // 0 degree
        uut->clk = 0;
        uut->eval();
     
        while (!Verilated::gotFinish())   
        {
        if ((main_time > 0) && (main_time % 5 == 0)){
                uut->clk = uut->clk ? 0 : 1;       // Toggle clock
            //printf("Toggling clock at time = %d\n", main_time);
        }
     
        if ((main_time > 0) && (main_time % 10 == 0)){
                uut->z0 += 0x010;    // add 000_0001.0000  which is 1 degree
            //printf("Incrementing input test angle");
        }
     
        uut->eval();            // Evaluate model
     
        if ((main_time >= 95) && (main_time % 10 == 5)){   // main_time = 85, 95, 105, ...
            printf("uut->z0 = %x, (uut->z0)-0x090 = %x\n", uut->z0, (uut->z0)-0x090 );
            cos_result = cal_cos((uut->z0 - 0x090) / 16);
            sin_result = cal_sin((uut->z0 - 0x090) / 16);
            std::cout<<"uut->z0 is of type: "<<typeid(uut->z0).name()<<std::endl;
            cout << "std::bitset<17>(uut->xn) = " << std::bitset<17>(uut->xn) << endl;   
            cout << "std::bitset<17>(uut->yn) = " << std::bitset<17>(uut->yn) << endl;
     
            cout << "to_string(uut->xn) = " << std::bitset<17>(uut->xn).to_string() << endl;   
            cout << "to_string(uut->yn) = " << std::bitset<17>(uut->yn).to_string() << endl;
     
            double dxn = bits_to_double<17>( std::bitset<17>(uut->xn).to_string() );
            double dyn = bits_to_double<17>( std::bitset<17>(uut->yn).to_string() );
     
            cout << "dxn = " << dxn << endl;   
            cout << "dyn = " << dyn << endl;
     
            cout << "cos_result = " << cos_result << endl;   
            cout << "sin_result = " << sin_result << endl;
            cout_debug_msg();
            assert( abs(dxn - cos_result) < TOLERANCE );
            assert( abs(dyn - sin_result) < TOLERANCE );
        }
     
            if (tfp != NULL)
            {
                tfp->dump (main_time);
            }
     
            main_time++;            // Time passes...
        }
     
        uut->final();               // Done simulating
     
        if (tfp != NULL)
        {
            tfp->close();
            delete tfp;
        }
     
        delete uut;
     
        return 0;
    }


    Makefile
    Code Bash - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
    TARGET=cordic_pipelined
    .PHONY: $(TARGET)
    RTLSRC=../rtl
    all: $(TARGET)
     
    LDFLAGS=
    CFLAGS=-g -O3
     
    $(TARGET):
        verilator -Wno-fatal -I$(RTLSRC) --cc $(@).v cordic_stage.v --trace --exe ../$(@).cpp  -Mdir $(@) -CFLAGS "$(CFLAGS)"
        make -C $(@) -f V$(@).mk
    clean:: 
        rm -rf *.o $(TARGET)
    distclean:: clean
        rm -rf *~ *.txt *.vcd *.mif *.orig



    •   Alt25th May 2017, 18:06

      advertising

        
       

  6. #26
    Super Moderator
    Points: 26,786, Level: 39
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    6,090
    Helped
    1493 / 1493
    Points
    26,786
    Level
    39

    Re: Cordic Algorithm Question

    Quote Originally Posted by promach View Post
    I am stuck at 90 degrees. I am still working on how to solve this verilog bug with verilator debug cout.
    cordic outputs cos(90) as 0.997269 while it should be close to zero.

    Please let me know if you have any insights.
    I have also attached the files for verilator below if you are interested.
    Sorry, I don't have verilator installed, only Vivado, Modelsim, and a very old un-updated version of icarus. To find this issue I'd have to do what you are doing, debug it, which I don't have the time to do.



  7. #27
    Member level 5
    Points: 614, Level: 5

    Join Date
    Feb 2016
    Posts
    83
    Helped
    0 / 0
    Points
    614
    Level
    5

    Re: Cordic Algorithm Question

    ads-ee:

    I am still working on "pipelined testbench" (feed unit under test with a new sample every clock)

    Just to share.
    A pipelined cordic algoithm for computing cos(angle) and sin(angle) with "non-pipelined testbench" (feed unit under test with a new sample every N pipeline stages)
    This had been tested against input angles ranging from -180 degree to +180 degree with output tolerance of 0.01



    cordic_pipelined.v
    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
    
    `timescale 1ns/100ps
     
    module cordic_pipelined(clk, z0, xn, yn);
      
      parameter z_width = 12; 
      parameter iter_width = 17;  // iteration width
     
      input clk;
      input signed [z_width:0] z0;
      output reg signed [iter_width:0] xn, yn;
     
      parameter N = 10; // number of iterations
      
      reg [(N-1):0] d;
      wire signed [iter_width:0] x [N:0];
      wire signed [iter_width:0] y [N:0];
      wire signed [z_width:0] z [N:0];
     
      assign x[0] = 'b01_0011_0110_1110_1001;  // 0.60725 in binary
      assign y[0] = 0;
     
      always @ (z0, x[N], y[N]) begin
        
        // cordic only works in first and fourth quadrant
     
        if (((z0[z_width]==1) && (z0 < 'h1A60)) || 
        ((z0[z_width]==0) && (z0 > 'h05A0))) begin      // if z0 < -90 || z0 > +90
        //$display("at 1, z0 = %h", z0);
        if (z0[z_width] == 1) begin             // if z0 < 0
            z[0] = z0 + 'hB40;    // third quadrant, so add 180 degrees
            //$display("at 2");
        end
        else begin
            z[0] = z0 - 'hB40;    // second quadrant, so subtract 180 degrees
            //$display("at 3");
        end
        // flip the sign for second or third quadrant using two-complement rule
        xn = ~( x[N]-1 ); // xn = cos(z0)
        yn = ~( y[N]-1 ); // yn = sin(z0)  
        end
     
        else begin
        z[0] = z0; 
        xn = x[N];  // xn = cos(z0)  
        yn = y[N];  // yn = sin(z0)  
        end
        //$display("z[0] = ", z[0]);
      end
      
      wire signed [z_width:0] arctan [(N-1):0];
        
      assign arctan[0] = 'b0_0010_1101_0000; // 45.000;
      assign arctan[1] = 'b0_0001_1010_1001; // 26.565;
      assign arctan[2] = 'b0_0000_1110_0000; // 14.036;
      assign arctan[3] = 'b0_0000_0111_0010; // 7.1250;
      assign arctan[4] = 'b0_0000_0011_1001; // 3.5763;
      assign arctan[5] = 'b0_0000_0001_1100; // 1.7899;
      assign arctan[6] = 'b0_0000_0000_1110; // 0.8952;
      assign arctan[7] = 'b0_0000_0000_0111; // 0.4476;
      assign arctan[8] = 'b0_0000_0000_0011; // 0.2238;
      assign arctan[9] = 'b0_0000_0000_0001; // 0.1119;
     
      genvar i;
      generate
        for(i=0; i<N; i=i+1)
          begin: stage_generate
            cordic_stage #(.i(i)) stage_i
            (
              .clk(clk), 
              .x_i(x[i]), .x_o(x[i+1]), 
              .y_i(y[i]), .y_o(y[i+1]), 
              .z_i(z[i]), .z_o(z[i+1]),
              .arctan(arctan[i])
            );
     
          end
      endgenerate
         
    endmodule


    cordic_stage.v
    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
    
    `timescale 1ns/100ps
     
    module cordic_stage(clk, x_i, y_i, z_i, x_o, y_o, z_o, arctan);
      
      parameter z_width = 12; 
      parameter iter_width = 17;    // iteration width
      parameter i=0;        // power of two shift amount
     
      input signed [z_width:0] arctan;
      
      input clk;
      input signed [iter_width:0] x_i, y_i;
      input signed [z_width:0] z_i;
      output [iter_width:0] x_o, y_o;
      output [z_width:0] z_o;
      
      reg d;
      reg signed [iter_width:0] x_o, x_next;
      reg signed [iter_width:0] y_o, y_next;
      reg signed [z_width:0] z_o, z_next;
      
      always @ (posedge clk)
        begin
          x_o <= x_next;
          y_o <= y_next;
          z_o <= z_next; 
        end
     
      always @(*)
        begin    
     
          d = (z_i[11] == 0) ? 0 : 1;
     
          if(d == 0) begin
            x_next = x_i - (y_i >>> i);
            y_next = y_i + (x_i >>> i);
            z_next = z_i - arctan;
          end
     
          else begin
            x_next = x_i + (y_i >>> i);
            y_next = y_i - (x_i >>> i);
            z_next = z_i + arctan;
          end
          
      end
     
    endmodule


    cordic_pipelined.cpp
    Code C++ - [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
    
    #include <verilated.h>          // Defines common routines
    #include "Vcordic_pipelined.h"
    #include "verilated_vcd_c.h"
     
    #include <assert.h>
    #include <math.h>  
    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <cstdio>
    #include <bitset>
    #include <limits>
    #include <iomanip>
    #include <typeinfo>
    #define PI 3.14159265
    #define TOLERANCE 0.01
     
    #define X(i) uut-> cordic_pipelined__DOT__stage_generate__BRA__##i##__KET____DOT____Vcellout__stage_i__x_o
    #define XOUT(i) cout << "x[" << i << "] = " << Dict::bits_to_double<18>(std::bitset<18>(X(i)).to_string()) << endl 
     
    #define Y(i) uut-> cordic_pipelined__DOT__stage_generate__BRA__##i##__KET____DOT____Vcellout__stage_i__y_o
    #define YOUT(i) cout << "y[" << i << "] = " << Dict::bits_to_double<18>(std::bitset<18>(Y(i)).to_string()) << endl 
     
    #define Z(i) uut-> cordic_pipelined__DOT__stage_generate__BRA__##i##__KET____DOT____Vcellout__stage_i__z_o
    #define ZOUT(i) cout << "z[" << i << "] = " << Dict::bits_to_double<12>(std::bitset<12>(Z(i)).to_string(), true) << endl 
     
    #define Zin(i) uut-> cordic_pipelined__DOT__stage_generate__BRA__##i##__KET____DOT____Vcellinp__stage_i__z_i
     
    Vcordic_pipelined *uut;                     // Instantiation of module
    vluint64_t main_time = 0;       // Current simulation time
     
    class Dict{
        public:
        double sc_time_stamp () {       // Called by $time in Verilog
            return main_time;           // converts to double, to match
            // what SystemC does
        }
     
        double cal_sin(int angle){  // Returns the sine of an angle of x radians.
            printf("angle = %d\n", angle);
            return sin(angle*PI/180);
        }
     
        double cal_cos(int angle){  // Returns the cosine of an angle of x radians.
            return cos(angle*PI/180);
        }
     
        bool check_result(void){
     
            int angle = static_cast<int>
                (bits_to_double<13>( std::bitset<13>( uut->z0 ).to_string(), true));    
    // since angle starts from 0.0 degree instead of 1.0 degree and we are only getting the final result after 10 positive edges (iterations). z0 is the input angle used to generate this final result. Divide by 16 becuase we have 4 decimal place
     
            //cout << "uut->z0 / 16 = " << uut->z0 / 16 << endl; 
            double cos_result = cal_cos(angle);
            double sin_result = cal_sin(angle);
     
            double dxn = bits_to_double<18>( std::bitset<18>(uut->xn).to_string() );
            double dyn = bits_to_double<18>( std::bitset<18>(uut->yn).to_string() );        
     
            //std::cout<<"uut->z0 is of type: "<<typeid(uut->z0).name()<<std::endl;
            //cout << "std::bitset<18>(uut->xn) = " << std::bitset<18>(uut->xn) << endl;   
            //cout << "std::bitset<18>(uut->yn) = " << std::bitset<18>(uut->yn) << endl;
     
            //cout << "to_string(uut->xn) = " << std::bitset<18>(uut->xn).to_string() << endl;   
            //cout << "to_string(uut->yn) = " << std::bitset<18>(uut->yn).to_string() << endl;
            
            cout << "dxn = " << dxn << endl;   
            cout << "dyn = " << dyn << endl;
     
            cout << "cos_result = " << cos_result << endl;   
            cout << "sin_result = " << sin_result << endl;
     
            assert( abs(dxn - cos_result) < TOLERANCE );
            assert( abs(dyn - sin_result) < TOLERANCE );
     
            if (angle == 180) exit(0);   // to stop at +180 degrees
     
            return true;
        }
     
        void cout_debug_msg(unsigned int iteration){
            cout << "--------------start of debug_message--------------" << endl;
            cout << "iteration = " << iteration << endl;      
            
            cout_XOUT(iteration); 
            cout_YOUT(iteration);
            cout_ZOUT(iteration);
     
            cout << "--------------end of debug_message--------------" << endl;     
        }
     
        void cout_XOUT(unsigned int iteration){
            if (iteration == 0) XOUT(0); 
            if (iteration == 1) XOUT(1); 
            if (iteration == 2) XOUT(2); 
            if (iteration == 3) XOUT(3); 
            if (iteration == 4) XOUT(4); 
            if (iteration == 5) XOUT(5); 
            if (iteration == 6) XOUT(6); 
            if (iteration == 7) XOUT(7); 
            if (iteration == 8) XOUT(8); 
            if (iteration == 9) XOUT(9);        
        }
     
        void cout_YOUT(unsigned int iteration){
            if (iteration == 0) YOUT(0); 
            if (iteration == 1) YOUT(1); 
            if (iteration == 2) YOUT(2); 
            if (iteration == 3) YOUT(3); 
            if (iteration == 4) YOUT(4); 
            if (iteration == 5) YOUT(5); 
            if (iteration == 6) YOUT(6); 
            if (iteration == 7) YOUT(7); 
            if (iteration == 8) YOUT(8); 
            if (iteration == 9) YOUT(9);        
        }
     
        void cout_ZOUT(unsigned int iteration){
            if (iteration == 0) ZOUT(0); 
            if (iteration == 1) ZOUT(1); 
            if (iteration == 2) ZOUT(2); 
            if (iteration == 3) ZOUT(3); 
            if (iteration == 4) ZOUT(4); 
            if (iteration == 5) ZOUT(5); 
            if (iteration == 6) ZOUT(6); 
            if (iteration == 7) ZOUT(7); 
            if (iteration == 8) ZOUT(8); 
            if (iteration == 9) ZOUT(9);        
        }
     
        // Reference: [url]http://www.cplusplus.com/forum/general/216385/[/url]
        template < std::size_t N = 18 > // input: bits of the N-bit significand
        double bits_to_double( const std::string& bits , bool print_z=false)
        {
            //std::cout << "bits = " << bits << '\n'; 
            //std::cout << "N = " << N << '\n'; 
            static_assert( N < std::numeric_limits<signed long long>::digits, "overflow" ) ;
     
            static auto denom = 1ULL << (N-1) ;
     
            if (print_z == false)
            denom = 1ULL << (N-1) ;
            else 
            denom = 1ULL << 4 ;
     
            std::string mantissa ; // remove non-digit characters
            for( char c : bits ) 
            if( c == '1' || c == '0' ) 
            {
               mantissa += c ; 
               //std::cout << "Loop  , mantissa = " << mantissa << '\n'; 
            }
            
            //std::cout << "before, mantissa = " << mantissa << '\n';
            mantissa.resize( N, '0' ) ; // truncate / append zeroes to make N bits
            //std::cout << "after , mantissa = " << mantissa << '\n';
            
            int sign = ( mantissa[0] == '0' ? 1 : -1 );                            
            //std::cout << "sign = " << sign << endl;
     
            if (sign == -1){        // two-complement       
            mantissa = std::to_string( std::stol(mantissa) - 1 ) ;
            //std::cout << "sign  , mantissa = " << mantissa << '\n';
                for( char& c : mantissa ) c = ( c == '0' ? '1' : '0' ) ;
            }     
            mantissa[0] == '0';                                           
            //std::cout << "final , mantissa = " << mantissa << '\n';
            return sign * double( std::bitset<N>(mantissa).to_ullong() ) / denom ; 
        }
    };
     
    int main(int argc, char** argv)
    {
        // turn on trace or not?
        bool vcdTrace = true;
        VerilatedVcdC* tfp = NULL;
     
        Verilated::commandArgs(argc, argv);   // Remember args
        uut = new Vcordic_pipelined;   // Create instance
     
        uut->eval();
     
        if (vcdTrace)
        {
            Verilated::traceEverOn(true);
     
            tfp = new VerilatedVcdC;
            uut->trace(tfp, 99);
     
            std::string vcdname = argv[0];
            vcdname += ".vcd";
            std::cout << vcdname << std::endl;
            tfp->open(vcdname.c_str());
        }
        uut->z0 = 0x14c0; // 1_0100_1100.0000; // start from -180.0 degree to +180.0 degree
        uut->clk = 0;
        uut->eval();
     
        unsigned int iteration_stage = 0;
     
        while (!Verilated::gotFinish())   
        {
        Dict d;
     
        if ((main_time > 0) && (main_time % 5 == 0)){
                uut->clk = uut->clk ? 0 : 1;        // Toggle clock with period of 10 main_time units
                                // first positive clock edge at main_time = 5
            //printf("Toggling clock at time = %d\n", main_time);
            uut->eval();            // Evaluate combinatorial logic before and after clock edge transitions
        }
     
    //  if ((main_time >= 11) && (main_time % 10 == 1)){    // main_time = 11, 21, 31, 41, 51, ...
    //            uut->z0 += 0x010;     // add 000_0001.0000  which is 1.0 degree when clk = 0
                        // first negative clock edge at main_time = 10
            //printf("Incrementing input test angle");
    //  }
     
        if ((main_time >= 5) && (main_time % 10 == 5)){   // main_time = 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, ...
            
            std::string stage = std::to_string(main_time);
     
            iteration_stage = (main_time == 5) ? 
            0  :  static_cast<uint>( std::stoi(stage.substr(stage.length()-2, 1)) ) ;
     
            //cout << "main_time = " << main_time << endl;   
            //cout << "iteration_stage = " << iteration_stage << endl;
     
            d.cout_debug_msg(iteration_stage);  // print debug message
        }
     
        if ((main_time >= 95) && (main_time % 10 == 5)){   // main_time = 95, 105, 115, 125, ...
            
            bool result_passed = false;  
        
            // check if the result from final iterations matches closely with exact values of cos(angle) and sin(angle)
            if (iteration_stage == 9) result_passed = d.check_result();  
            
            
            
            if (result_passed == true) {
            if (uut->z0 != 0x1FF0)      // not equal to -1.0 degree
                uut->z0 += 0x010;       
            else 
                uut->z0 = 0;    // 0.0 degree
            }
        }
     
            if (tfp != NULL)
            {
                tfp->dump (main_time);
            }
     
            main_time++;            // Time passes...
        }
     
        uut->final();               // Done simulating
     
        if (tfp != NULL)
        {
            tfp->close();
            delete tfp;
        }
     
        delete uut;
     
        return 0;
    }


    Makefile
    Code Bash - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
    TARGET=cordic_pipelined
    .PHONY: $(TARGET)
    RTLSRC=../rtl
    all: $(TARGET)
     
    LDFLAGS=
    CFLAGS=-g -O3
     
    $(TARGET):
        verilator -Wno-fatal -I$(RTLSRC) --cc $(@).v cordic_stage.v --trace --exe ../$(@).cpp  -Mdir $(@) -CFLAGS "$(CFLAGS)"
        make -C $(@) -f V$(@).mk
    clean:: 
        rm -rf *.o $(TARGET)
    distclean:: clean
        rm -rf *~ *.txt *.vcd *.mif *.orig



--[[ ]]--