EECS151 / fpga_labs_fa20 / lab4 / src / z1top.v
z1top.v
Raw
`timescale 1ns/1ns

`define CLOCK_FREQ 125_000_000

module z1top (
    input CLK_125MHZ_FPGA,
    input [3:0] BUTTONS,
    input [1:0] SWITCHES,
    output [5:0] LEDS,
    output aud_pwm,
    output aud_sd
);
    //assign LEDS[5:4] = 2'b11;
   
    reg reset      = 0;
    reg play_pause = 0;
    reg reverse    = 0;

    wire [23:0] tone_to_play;
    wire [2:0]  leds;
    wire        tempo_up, tempo_down;

    assign aud_sd     = SWITCHES[0];
    assign tempo_up   = SWITCHES[1] & buttons_pressed[1];
    assign tempo_down = !SWITCHES[1] & buttons_pressed[1];

    tone_generator tg (.clk(CLK_125MHZ_FPGA),
                       .rst(buttons_pressed[0]),
                       .output_enable(aud_sd),
                       .tone_switch_period(tone_to_play),
                       .volume(0'd0),
                       .square_wave_out(aud_pwm)
                      );

    music_streamer streamer (.clk(CLK_125MHZ_FPGA),
                             .rst(buttons_pressed[0]),
                             .tempo_up(tempo_up),
                             .tempo_down(tempo_down),
                             .play_pause(play_pause),
                             .reverse(reverse),
                             .leds(leds),
                             .tone(tone_to_play)
                            ); 


    //// Button parser test circuit
    /* verilator lint_off REALCVT */
    // Sample the button signal every 500us
    localparam integer B_SAMPLE_COUNT_MAX = 0.0005 * `CLOCK_FREQ;
    // The button is considered 'pressed' after 100ms of continuous pressing
    localparam integer B_PULSE_COUNT_MAX = 0.100 / 0.0005;
    /* lint_on */

    wire [3:0] buttons_pressed;
    button_parser #(
        .width(4),
        .sample_count_max(B_SAMPLE_COUNT_MAX),
        .pulse_count_max(B_PULSE_COUNT_MAX)
    ) bp (
        .clk(CLK_125MHZ_FPGA),
        .in(BUTTONS),
        .out(buttons_pressed)
    );

endmodule