huiyanhuishi 发表于 2011-9-15 10:00:47

新手有问题的小程序,望各位指教

`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date:    09:02:41 09/15/2011
// Design Name:
// Module Name:    triwave
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module triwave(clk,wave);

input clk;
output wave;
reg wave;
reg rfd;
wire dividend;
wire divisor;
wire quotient;
wire fractional;

wire a;
wire b;
wire s;

reg counter;

always @(posedge clk) begin
        if((counter>=0)&&(counter<10000)) begin
                counter<=counter+1;
        end
        else if(counter==10000) begin
                counter<=0;
        end
end

divip wavediv (
        .clk(clk),
        .rfd(rfd),
        .dividend(dividend), // Bus
        .divisor(divisor), // Bus
        .quotient(quotient), // Bus
        .fractional(fractional)); // Bus
subip wavesub (
        .a(a), // Bus
        .b(b), // Bus
        .clk(clk),
        .s(s)); // Bus

always begin
        if((counter>=0)&&(counter<5000)) begin
                dividend<=counter;
                divisor<=50;
        end
        else if((counter>=5000)&&(counter<10000))
                a<=10000;
                b<=counter;
                dividend<=s;
                divisor<=50;
        end
end

assign wave=quotient<<14+fractional;

endmodule
页: [1]
查看完整版本: 新手有问题的小程序,望各位指教