Electronic – Why does this Verilog code produce no output on the FPGA

fpgaintel-fpgaverilog

I am trying to learn Verilog on my own using the DE1-Soc and the Altera university program labs. I am on the very first lab and trying to make a 4 bit-wide two input multiplexer. I wrote this verilog code to make switches 3-0 and 7-4 the two 4bit inputs and switch 9 the select as well as LEDs 3-0 the display.

I wanted to use encapsulation so i made the inputs of the top level module the switches and the outputs the LEDs and then i used wires to route the signals.

For some reason it synthesizes just fine but the LEDs on the FPGA are all off no matter what i do.

Here is the Verilog Code:

module part2(SW, LEDR);

    //input and output declarations
    input [9:0] SW; // all 10 switches on DE1-SoC board
    output [9:0] LEDR; //all 10 LEDs on DE1-SoC board

    //input and output wires
    wire [3:0]X; //routes first four bit input
    wire [3:0]Y; //routes second four bit input
    wire s; // routes select
    wire [3:0]M; //routes output to LEDS

    //wire assignments
    assign X = SW[3:0];
    assign Y = SW[7:4];
    assign s = SW[9];
    assign M = LEDR[3:0];

    //mux declarations
    Mux2_1(s, X[0], Y[0], M[0]);
    Mux2_1(s, X[1], Y[1], M[1]);
    Mux2_1(s, X[2], Y[2], M[2]);
    Mux2_1(s, X[3], Y[3], M[3]);
endmodule

module Mux2_1(s, x, y, m); //2:1 mux

    //input and output declarations
    input s;
    input x;
    input y;

    output m;

    //assignment
    assign m = (~s & x) | (s & y);
endmodule

I have checked the assignments and they should be completely correct, but just in case you want to check here is my assignments for the DE1-SoC board:

# -------------------------------------------------------------------------- #
#
# Copyright (C) 1991-2014 Altera Corporation. All rights reserved.
# Your use of Altera Corporation's design tools, logic functions 
# and other software and tools, and its AMPP partner logic 
# functions, and any output files from any of the foregoing 
# (including device programming or simulation files), and any 
# associated documentation or information are expressly subject 
# to the terms and conditions of the Altera Program License 
# Subscription Agreement, the Altera Quartus II License Agreement,
# the Altera MegaCore Function License Agreement, or other 
# applicable license agreement, including, without limitation, 
# that your use is for the sole purpose of programming logic 
# devices manufactured by Altera and sold by Altera or its 
# authorized distributors.  Please refer to the applicable 
# agreement for further details.
#
# -------------------------------------------------------------------------- #
#
# Quartus II 64-Bit
# Version 14.1.0 Build 186 12/03/2014 SJ Web Edition
# Date created = 11:52:22  March 25, 2015
#
# -------------------------------------------------------------------------- #
#
# Notes:
#
# 1) The default values for assignments are stored in the file:
#       part2_assignment_defaults.qdf
#    If this file doesn't exist, see file:
#       assignment_defaults.qdf
#
# 2) Altera recommends that you do not modify this file. This
#    file is updated automatically by the Quartus II software
#    and any changes you make may be lost or overwritten.
#
# -------------------------------------------------------------------------- #


set_global_assignment -name FAMILY "Cyclone V"
set_global_assignment -name DEVICE 5CSEMA5F31C6
set_global_assignment -name TOP_LEVEL_ENTITY part2
set_global_assignment -name ORIGINAL_QUARTUS_VERSION 14.1.0
set_global_assignment -name PROJECT_CREATION_TIME_DATE "11:52:22  MARCH 25, 2015"
set_global_assignment -name LAST_QUARTUS_VERSION 14.1.0
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR 256
set_global_assignment -name EDA_SIMULATION_TOOL "ModelSim-Altera (Verilog)"
set_global_assignment -name EDA_OUTPUT_DATA_FORMAT "VERILOG HDL" -section_id eda_simulation
set_global_assignment -name VERILOG_FILE part2.v
set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top
set_location_assignment PIN_V16 -to LEDR[0]
set_location_assignment PIN_W16 -to LEDR[1]
set_location_assignment PIN_V17 -to LEDR[2]
set_location_assignment PIN_V18 -to LEDR[3]
set_location_assignment PIN_W17 -to LEDR[4]
set_location_assignment PIN_W19 -to LEDR[5]
set_location_assignment PIN_Y19 -to LEDR[6]
set_location_assignment PIN_W20 -to LEDR[7]
set_location_assignment PIN_W21 -to LEDR[8]
set_location_assignment PIN_Y21 -to LEDR[9]
set_location_assignment PIN_AB12 -to SW[0]
set_location_assignment PIN_AC12 -to SW[1]
set_location_assignment PIN_AF9 -to SW[2]
set_location_assignment PIN_AF10 -to SW[3]
set_location_assignment PIN_AD11 -to SW[4]
set_location_assignment PIN_AD12 -to SW[5]
set_location_assignment PIN_AE11 -to SW[6]
set_location_assignment PIN_AC9 -to SW[7]
set_location_assignment PIN_AD10 -to SW[8]
set_location_assignment PIN_AE12 -to SW[9]
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top

Best Answer

You do not drive LEDR output at all. You need an assignment like:

assign LEDR = M;

You probably wanted to achieve that by assigning LEDR[3:0] to M (i.e. assign M = LEDR[3:0]), but this two assignments are not equivalent in Verilog.