Aditya Gedela Posted April 5, 2017 Share Posted April 5, 2017 In my code, always @(posedge clk) begin //I wrote some algorithm and I am assigning a new value to a register random done with a delay of 5 seconds. end integer k; //and next to convert it into integer i am writing always @(random done) begin k=random done; .if(k==1) ...... led[0]=1; if (k==2) ........ led[1]=1; end so when I am writing a separate always block for converting into integer all LEDs are glowing at once immediately after programming.... Is there any way I can directly assign to the integer k in the first always block itself?.... Can you please help me out... Thanks in Advance Link to comment Share on other sites More sharing options...
artvvb Posted April 5, 2017 Share Posted April 5, 2017 @Aditya Gedela At this point, k is just a copy of your random_done. always@(random_done) triggers an event whenever random_done changes, so k will be copied and then each led will be updated. The bigger problem is that you do not appear to have a way to set your leds to 0 coded into your always block. How you fix this depends on how many leds you have access to, and how many bits are in the random_done register. To provide a better suggestion, we would need to see more code, but as it stands, if you only have 16 leds (declared as "output reg [15:0] led") and a 32 bit random done register, you could do something like this: always@(random_done) led[15:0] = random_done[31:16]; This should fix the issue of the leds being always on, something a little closer to the style you are already writing in would be this: always@(random_done) begin if (random_done == 0) led = 16'b0; else if (random_done == 1) led = 16'b1; else if (random_done == 2) led = 16'b10; else if (random_done == 3) led = 16'b100; ... end This code will turn on only the led with bit position equal to the value of random_done. Key again is that you need to set the led bits that you don't want on to be 0s. Hope this helps, Arthur Link to comment Share on other sites More sharing options...
Aditya Gedela Posted April 6, 2017 Author Share Posted April 6, 2017 Thanks for your reply @artvvb why I actually assigned to integer k is to perform % operation....(k=k%10 which I forgot to mention in the code and random_done is a 13 bit register) How can I do it with registers... Can you please help me out..... Thanks in advance... Link to comment Share on other sites More sharing options...
D@n Posted April 6, 2017 Share Posted April 6, 2017 @Aditya Gedela, You can find an example divide here. The modulo value is calculated internally as r_dividend, although never output from the core. There's also a testbench for the module in the sim/verilator directory here, which can be used to generate a .vcd file for use with gtkwave, so you can see what it does. Dan Link to comment Share on other sites More sharing options...
Question
Aditya Gedela
In my code,
always @(posedge clk) begin
//I wrote some algorithm and I am assigning a new value to a register random done with a delay of 5 seconds.
end
integer k;
//and next to convert it into integer i am writing
always @(random done) begin
k=random done;
.if(k==1)
......
led[0]=1;
if (k==2)
........
led[1]=1;
end
so when I am writing a separate always block for converting into integer all LEDs are glowing at once immediately after programming....
Is there any way I can directly assign to the integer k in the first always block itself?....
Can you please help me out...
Thanks in Advance
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.