问答
直播中

何立立

9年用户 86经验值
擅长:可编程逻辑 嵌入式技术
私信 关注

【Z-turn Board试用体验】+蜂鸣器 产生SOS信号

本帖最后由 何立立 于 2015-7-5 20:06 编辑

本实验RTL原理图如下:
sos_sig_ger.png       sos_module.v 如字面上的意思,是产生“SOS信号”的“功能模块”。但是看简单一点,就是有次序的控制输出莫斯密码的“点”,“画”和“间隔”。而 control_module.v 是一个简单的定时触发器,每一段时间都会使能sos_module.v。

在这里稍微认识一下“摩斯密码"的基本三个元素:
莫尔斯密码.png

  英文字母“S”是 “. . .”,亦即三个短音节之中夹杂间隔。而英文字母“O”是“_ _ _”,亦即三个长音节之中夹杂间隔。所以SOS形成了“ . . . _ _ _ . . . ”
下面给出实验代码:
工程结构.png
顶层模块sos_generator_module:
  1. module sos_generator_module
  2. (
  3.     CLK,Pin_Out
  4. );
  5.     input CLK;

  6.     output Pin_Out;
  7.     /****************************/
  8.          wire SOS_En_Sig;
  9.     control_module U1
  10.     (
  11.              .CLK( CLK ),
  12.                   .SOS_En_Sig( SOS_En_Sig )
  13.          );   
  14.          wire Pin_Out_Wire;
  15.          sos_module U2
  16.          (
  17.              .CLK( CLK ),
  18.                
  19.         .SOS_En_Sig( SOS_En_Sig ),
  20.              .Pin_Out( Pin_Out_Wire )         
  21.          );
  22.          /******************************/
  23.          assign Pin_Out = !Pin_Out_Wire;
  24.          /******************************/
  25. endmodule
control_module:
  1. module control_module
  2. (
  3.     CLK,SOS_En_Sig
  4. );
  5.     input CLK;
  6.          output SOS_En_Sig;
  7.          /********************************/
  8.          parameter T3S = 26'd35_997_000;
  9.          /********************************/
  10.          reg isEn=1'b0;
  11.          reg [25:0]Count1=26'd0;
  12.          
  13.          always @ ( posedge CLK  )
  14.             begin
  15.                   if( Count1 == T3S )
  16.                       begin
  17.                           isEn <= 1'b1;
  18.                                     Count1 <= 26'd0;
  19.                            end
  20.                   else
  21.                       begin
  22.                           isEn <= 1'b0;
  23.                                     Count1 <= Count1 + 1'b1;
  24.                            end
  25.                 end
  26.         /*****************************************/
  27.         assign SOS_En_Sig = isEn;
  28.         /*****************************************/
  29. endmodule
sos_module:
  1. module sos_module
  2. (
  3.      CLK, Pin_Out, SOS_En_Sig
  4. );
  5.     input CLK;
  6.          input SOS_En_Sig;
  7.          output Pin_Out;
  8.          /****************************************/
  9.          parameter T1MS = 16'd11_999;//1ms
  10.          /***************************************/
  11.          reg [15:0]Count1=16'd0;;
  12.          always @ ( posedge CLK )
  13.              begin
  14.                         if( isCount && Count1 == T1MS )
  15.                       Count1 <= 16'd0;
  16.                         else if( isCount )
  17.                       Count1 <= Count1 + 1'b1;
  18.                         else if( !isCount )
  19.                       Count1 <= 16'd0;
  20.                         end
  21.     /****************************************/                        
  22.     reg [9:0]Count_MS= 10'd0;
  23.          always @ ( posedge CLK )
  24.         begin
  25.                                 if( isCount && Count1 == T1MS )
  26.                                         Count_MS <= Count_MS + 1'b1;
  27.                                 else if( !isCount )
  28.                                         Count_MS <= 10'd0;
  29.                   end
  30.         /******************************************/
  31.         reg isCount= 1'b0;
  32.         reg rPin_Out= 1'b0;;
  33.         reg [4:0]i=5'd0;
  34.         always @ ( posedge CLK  )
  35.             begin
  36.                 case( i )
  37.                               5'd0 :
  38.                                         if( SOS_En_Sig ) i <= 5'd1;
  39.                                         5'd1, 5'd3, 5'd5,5'd13, 5'd15, 5'd17 :  
  40.                                         if( Count_MS == 10'd100 ) begin isCount <= 1'b0; rPin_Out <= 1'b0; i <= i + 1'b1; end // short
  41.                                         else begin isCount <= 1'b1; rPin_Out <= 1'b1; end
  42.                                         5'd7, 5'd9, 5'd11 :
  43.                                         if( Count_MS == 10'd300 ) begin isCount <= 1'b0; rPin_Out <= 1'b0; i <= i + 1'b1; end // long
  44.                                         else begin isCount <= 1'b1; rPin_Out <= 1'b1; end
  45.                                         5'd2, 5'd4, 5'd6, 5'd8, 5'd10, 5'd12, 5'd14, 5'd16, 5'd18 :
  46.                                         if( Count_MS == 10'd50 ) begin isCount <= 1'b0; i <= i + 1'b1; end// interval
  47.                                         else isCount <= 1'b1;
  48.                                         5'd19 :
  49.                                         begin rPin_Out <= 1'b0; i <= 5'd0; end  // end
  50.                           endcase
  51.                  end
  52.     /***************************************************/
  53.          assign Pin_Out = rPin_Out;
  54.          /***************************************************/
  55. endmodule
拐角约束文件:
  1. NET "CLK" LOC = U14;
  2. NET "Pin_Out" LOC = P18;

下载到z-turn  board 后你会听到:‘’嘀嘀嘀 哒哒哒 嘀嘀嘀‘’的声音。



回帖(2)

blackroot

2015-7-5 09:59:33
已经学习了。。。。。
举报

何立立

2015-7-5 14:05:26
引用: blackroot 发表于 2015-7-5 09:59
已经学习了。。。。。

                                             
举报

更多回帖

发帖
×
20
完善资料,
赚取积分