njithjw的个人空间 https://blog.eetop.cn/505866 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

alt_gxb时钟控制模块

已有 762 次阅读| 2012-1-3 21:21 |个人分类:FPGA_Verilog

`timescale 1ns/1ns
module alt_gxb_clk_ctrl
    (
    input               rst,
    input               clk,

    input               rx_pll_locked,
    input               rx_freq_locked,

    output      reg     lock_to_data,
    output      reg     lock_to_refclk
    );

parameter   START      = 3'b001;
parameter   MANUAL_SEL = 3'b010;
parameter   AUTO_SEL   = 3'b100;


reg     [2:0]   cur_stat;
reg     [2:0]   next_stat;
reg             cnt_reset;
reg     [7:0]   cnt_dly;
reg             time_dly_flag0;
reg             time_dly_flag1;

always @ (posedge clk or posedge rst)
begin
    if (rst == 1'b1)
        cur_stat <= START;
    else
        cur_stat <= next_stat;
end

always @ (*)
begin
    case (cur_stat)
        START :
        begin
            if ((rx_pll_locked == 1'b1) && (time_dly_flag0 == 1'b1))
                next_stat = MANUAL_SEL;
            else
                next_stat = START;
        end

        MANUAL_SEL :
        begin
            if ((rx_freq_locked == 1'b1) && (time_dly_flag1 == 1'b1))
                next_stat = AUTO_SEL;
            else
                next_stat = START;
        end

        AUTO_SEL :
        begin
            if (rx_freq_locked == 1'b1)
                next_stat = AUTO_SEL;
            else
                next_stat = START;
        end

        default : next_stat = START;
    endcase
end

always @ (posedge clk or posedge rst)
begin
    if (rst == 1'b1)
        cnt_reset <= 1'b1;
    else
    begin
        case (cur_stat)
            START :
            begin
                if (time_dly_flag0 == 1'b1)
                    cnt_reset <= 1'b1;
                else
                    cnt_reset <= 1'b0;
            end
            MANUAL_SEL :
            begin
                if (time_dly_flag1 == 1'b1)
                    cnt_reset <= 1'b1;
                else
                    cnt_reset <= 1'b0;
            end
            AUTO_SEL : cnt_reset <= 1'b1;

            default : cnt_reset <= 1'b1;
        endcase
    end

end

always @ (posedge clk or posedge rst)
begin
    if (rst == 1'b1)
        cnt_dly <= 8'd0;
    else if (cnt_reset == 1'b1)
        cnt_dly <= 8'd0;
    else if (cur_stat == START)
    begin
        if (cnt_dly <= 8'd31)
            cnt_dly <= cnt_dly + 8'd1;
        else ;
    end
    else if (cur_stat == MANUAL_SEL)
    begin
        if (cnt_dly <= 8'hff)
            cnt_dly <= cnt_dly + 8'd1;
        else ;
    end
    else
        cnt_dly <= 8'd0;
end

always @ (posedge clk or posedge rst)
begin
    if (rst == 1'b1)
        time_dly_flag0 <= 1'b0;
    else if ((cur_stat == START) && (cnt_dly == 8'd31))
        time_dly_flag0 <= 1'b1;
    else
        time_dly_flag0 <= 1'b0;
end

always @ (posedge clk or posedge rst)
begin
    if (rst == 1'b1)
        time_dly_flag1 <= 1'b0;
    else if ((cur_stat == MANUAL_SEL) && (cnt_dly == 8'hff))
        time_dly_flag1 <= 1'b1;
    else
        time_dly_flag1 <= 1'b0;
end


always @ (posedge clk or posedge rst)
begin
    if (rst == 1'b1)
    begin
        lock_to_data <= 1'b0;
        lock_to_refclk <= 1'b0;
    end
    else
    begin
        case (cur_stat)
            START :
            begin
                lock_to_data <= 1'b0;
                lock_to_refclk <= 1'b1;
            end

            MANUAL_SEL :
            begin
                lock_to_data <= 1'b1;
                lock_to_refclk <= 1'b0;
            end

            AUTO_SEL :
            begin
                lock_to_data <= 1'b0;
                lock_to_refclk <= 1'b0;
            end

            default :
            begin
                lock_to_data <= 1'b0;
                lock_to_refclk <= 1'b0;
            end
        endcase
    end
end

endmodule


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 0

    好友
  • 0

    获赞
  • 17

    评论
  • 3512

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-3 08:40 , Processed in 0.016827 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部