Block diagram of the datagen circuit is given below The down
Solution
find your entire code as below:
a)
first that is file you can say down_counter.v
as below:
module down_counter (clk ,reset,out_c,MACXOUNT,CLK1HZEN);
 output [7:0] out_c; // Output of the counter
input [7:0] MACXOUNT; // Data to load
 input CLK1HZEN; // down control for counter
 input clk, reset;
reg [7:0] out_c;
always @(posedge clk)
 if (reset == 1\'b0) begin
 out_c <= MACXOUNT ;
 end else if (CLK1HZEN == 1\'b1) begin
 out_c <= out_c - 1;
 end
 
 endmodule
b)
second is the file you can say bin_to_bcd.v
as below:
module bin_bcd( bin_input, bcd_output);
input [7:0] bin_input; // 8 bit binary input
 
 output [11:0] bcd_output; // 12 bit bcd output
reg [11 : 0] bcd_output;
   
 reg [3:0] i;   
 
 always @(bin_input)
 begin
 bcd_output = 0; //initialize bcd output to zero.
 for (i = 0; i < 8; i = i+1)
 begin
 bcd_output = {bcd_output[10:0],bin_input[7-i]};
   
 //if a hex digit of bcd output is more than 4, add 3 to it.
 if(i < 7 && bcd_output[3:0] > 4)
 bcd_output[3:0] = bcd_output[3:0] + 3;
 if(i < 7 && bcd_output[7:4] > 4)
 bcd_output[7:4] = bcd_output[7:4] + 3;
 if(i < 7 && bcd_output[11:8] > 4)
 bcd_output[11:8] = bcd_output[11:8] + 3;
 end
 end   
   
 endmodule
c)
third is the file you can say data_gen.v
module data_gen(clk,reset_n,CLK1HZEN,MAXCOUNT,BCD_OUT);
 input clk,reset_n,CLK1HZEN;
 input [7:0]MAXCOUNT;
 output [11:0]BCD_OUT;
   
 wire [11:0]BCD_OUT;
 wire [7:0]bin_count;
   
   
 down_counter down (
 .clk (clk),
 .reset(reset_n),
 .out_c(bin_count),
 .MACXOUNT(MAXCOUNT),
 .CLK1HZEN(CLK1HZEN));
   
   
 bin_bcd binbcd(
 .bin_input(bin_count),
 .bcd_output(BCD_OUT));
 
 endmodule
code is completely working i have verified it if you want to show the wave form please let me know.
and also reset_n is necessary to apply first while simulation.


