I want to create a design that takes a number of steps in a calculation. For that reason I want to use variables instead of signals. I defined the items that should be variables inside the @always_comb, but also outside them, but that does not solve my problem. Assigning values to variables is not the problem, but re-using them give problems.
The conversion to VHDL gives an error on the line “v_val = registers.testValue”. When I only leave the 2 lines above this line (making the rest comment), then v_val becomes a boolean. Probably for that reason it cannot assign a large value from registers.testValue to v_val. (testValue = Signal(intbv(0, min = -215, max = 215))). When I change the line “v_val = registers.testValue” to “v_val= 65536” there is no problem. v-val becomes an natural variable. The lines “v_val = v_lat” and the line “v_val=v_frn” still gives problems. This give the error message " Local variable may be referenced before assignment"
Can someone help me with this code?
@block
def model(ip_rst, ip_clk, number, number_valid, zero_regs, fnl_zero, fnl_calc, registers):
*** v_lat = intbv(val=0, min = - (216+1), max = (216+1))***
*** v_frn = intbv(val=0, min = - (216+1), max = (216+1)) ***
*** v_val = intbv(val=0, min = - (216+1), max = (216+1))***
#-------------------------------------------------------------
*** @always_comb ***
*** def measurement_valid():***
*** # v_lat = intbv(val=0, min = - (216+1), max = (216+1))***
*** # v_frn = intbv(val=0, min = - (216+1), max = (216+1))***
*** # v_val = intbv(val=0, min = - (216+1), max = (216+1))***
*** if number_valid:***
*** if fnl_calc:***
*** v_lat = number[18:2] + number[1]***
*** else:***
*** v_frn = number[18:2] + number[1]***
*** elif zero_regs:***
*** if fnl_zero:***
*** v_lat = 0***
*** else:***
*** v_frn = 0 ***
*** if registers.outputSwitch == 0:***
*** v_val = 0***
*** elif registers.outputSwitch == 1: ***
*** v_val = 65536 #registers.testValue***
*** elif registers.outputSwitch == 2:***
*** if fnl_zero: ***
*** v_val = v_lat***
*** else:***
*** v_val = v_frn***
*** else:***
*** v_drz = 0 ***
*** return measurement_valid***