{"id":105,"date":"2024-05-30T17:06:09","date_gmt":"2024-05-30T09:06:09","guid":{"rendered":"http:\/\/blog.huanmie.fun\/?p=105"},"modified":"2024-06-04T10:48:36","modified_gmt":"2024-06-04T02:48:36","slug":"%e5%9f%ba%e4%ba%8everilog%e7%9a%84tcs-230%e9%a2%9c%e8%89%b2%e4%bc%a0%e6%84%9f%e5%99%a8%e9%a9%b1%e5%8a%a8%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/blog.huanmie.fun\/index.php\/2024\/05\/30\/%e5%9f%ba%e4%ba%8everilog%e7%9a%84tcs-230%e9%a2%9c%e8%89%b2%e4%bc%a0%e6%84%9f%e5%99%a8%e9%a9%b1%e5%8a%a8%e6%a8%a1%e5%9d%97\/","title":{"rendered":"\u57fa\u4e8eVerilog\u7684TCS-230\u989c\u8272\u4f20\u611f\u5668\u9a71\u52a8\u6a21\u5757"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u6a21\u5757\u7b80\u4ecb\uff1a<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong>TCS230\u662fTAOS\u516c\u53f8\u63a8\u51fa\u7684\u53ef\u7f16\u7a0b\u5f69\u8272\u5149\u5230\u9891\u7387\u7684\u8f6c\u6362\u5668\u3002\u5b83\u628a\u53ef\u914d\u7f6e\u7684\u7845\u5149\u7535\u4e8c\u6781\u7ba1\u4e0e\u7535\u6d41\u9891\u7387\u8f6c\u6362\u5668\u96c6\u6210\u5728\u4e00\u4e2a\u5355\u4e00\u7684CMOS\u7535\u8def\u4e0a\uff0c\u540c\u65f6\u5728\u5355\u4e00\u82af\u7247\u4e0a\u96c6\u6210\u4e86\u7ea2\u7eff\u84dd(RGB)\u4e09\u79cd\u6ee4\u5149\u5668\uff0c\u662f\u4e1a\u754c\u7b2c\u4e00\u4e2a\u6709\u6570\u5b57\u517c\u5bb9\u63a5\u53e3\u7684RGB\u5f69\u8272\u4f20\u611f\u5668\u3002<\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-4fc3f8e1 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:49%\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"271\" height=\"163\" src=\"http:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/f843a39012974c58a474b412dae4c0b7-1.png\" alt=\"\" class=\"wp-image-109\" style=\"width:409px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"765\" height=\"199\" src=\"http:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/c8e20ebcc42b4136819460eb56c05376.png\" alt=\"\" class=\"wp-image-107\" style=\"width:411px;height:auto\" srcset=\"https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/c8e20ebcc42b4136819460eb56c05376.png 765w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/c8e20ebcc42b4136819460eb56c05376-300x78.png 300w\" sizes=\"auto, (max-width: 765px) 100vw, 765px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:51%\">\n<p class=\"wp-block-paragraph\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong>\u5f53\u5165\u5c04\u5149\u6295\u5c04\u5230TCS230\u4e0a\u65f6\uff0c\u901a\u8fc7\u5149\u7535\u4e8c\u6781\u7ba1\u63a7\u5236\u5f15\u811aS2\u3001S3\u7684\u4e0d\u540c\u7ec4\u5408\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0d\u540c\u7684\u6ee4\u6ce2\u5668\uff1b\u7ecf\u8fc7\u7535\u6d41\u5230\u9891\u7387\u8f6c\u6362\u5668\u540e\u8f93\u51fa\u4e0d\u540c\u9891\u7387\u7684\u65b9\u6ce2(\u5360\u7a7a\u6bd4\u662f50%)\uff0c\u4e0d\u540c\u7684\u989c\u8272\u548c\u5149\u5f3a\u5bf9\u5e94\u4e0d\u540c\u9891\u7387\u7684\u65b9\u6ce2\uff1b\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8f93\u51fa\u5b9a\u6807\u63a7\u5236\u5f15\u811aS0\u3001S1\uff0c\u9009\u62e9\u4e0d\u540c\u7684\u8f93\u51fa\u6bd4\u4f8b\u56e0\u5b50\uff0c\u5bf9\u8f93\u51fa\u9891\u7387\u8303\u56f4\u8fdb\u884c\u8c03\u6574\uff0c\u4ee5\u9002\u5e94\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong>S0\u3001S1\u7528\u4e8e\u9009\u62e9\u8f93\u51fa\u6bd4\u4f8b\u56e0\u5b50\u6216\u7535\u6e90\u5173\u65ad\u6a21\u5f0f\uff1bS2\u3001S3\u7528\u4e8e\u9009\u62e9\u6ee4\u6ce2\u5668\u7684\u7c7b\u578b\uff1bOE\u662f\u9891\u7387\u8f93\u51fa\u4f7f\u80fd\u5f15\u811a\uff0c\u53ef\u4ee5\u63a7\u5236\u8f93\u51fa\u7684\u72b6\u6001\uff0c\u5f53\u6709\u591a\u4e2a\u82af\u7247\u5f15\u811a\u5171\u7528\u5fae\u5904\u7406\u5668\u7684\u8f93\u5165\u5f15\u811a\u65f6\uff0c\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u7247\u9009\u4fe1\u53f7\uff1bOUT\u662f\u9891\u7387\u8f93\u51fa\u5f15\u811a\uff0cGND\u662f\u82af\u7247\u7684\u63a5\u5730\u5f15\u811a\uff0cVCC\u4e3a\u82af\u7247\u63d0\u4f9b\u5de5\u4f5c\u7535\u538b\u3002\u88681\u662fS0\u3001S1\u53caS2\u3001S3\u7684\u53ef\u7528\u7ec4\u5408\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5de5\u4f5c\u539f\u7406\uff1a<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u767d\u5e73\u8861\u6821\u51c6\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong>\u7406\u60f3\u72b6\u6001\u4e0b\u767d\u8272\u7531\uff1a\u7ea2\u8272(R)=255\uff0c\u7eff\u8272(G)=255\uff0c\u84dd\u8272(B)=255\u6df7\u5408\u800c\u6210\uff0c\u4f46\u662f\u5728\u5b9e\u9645\u73af\u5883\u4e2d\uff0c\u7531\u4e8e\u73af\u5883\u5149\u4e0d\u540c\uff0c\u5e76\u4e14\u5bf9\u4e8eTCS230\u7684\u5149\u4f20\u611f\u5668\u6765\u8bf4\uff0c\u5b83\u5bf9\u8fd9\u4e09\u79cd\u57fa\u672c\u8272\u7684\u654f\u611f\u6027\u662f\u4e0d\u76f8\u540c\u7684\uff0c\u5bfc\u81f4TCS230\u7684RGB\u8f93\u51fa\u5e76\u4e0d\u76f8\u7b49\uff0c\u767d\u8272\u6240\u5bf9\u5e94\u4e09\u539f\u8272\u7684\u53c2\u6570\u4e5f\u4e0d\u540c\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u8fdb\u884c\u767d\u5e73\u8861\u6821\u51c6\u544a\u8bc9\u7cfb\u7edf\u4ec0\u4e48\u662f\u767d\u8272\u3002\u4f7f\u5f97TCS230\u5bf9\u6240\u68c0\u6d4b\u7684\u201c\u767d\u8272\u201d\u4e2d\u7684\u4e09\u539f\u8272\u662f\u76f8\u7b49\u7684\u3002\u8fdb\u884c\u767d\u5e73\u8861\u8c03\u6574\u662f\u4e3a\u540e\u7eed\u7684\u989c\u8272\u8bc6\u522b\u4f5c\u51c6\u5907\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong>\u767d\u5e73\u8861\u8c03\u6574\u7684\u5177\u4f53\u6b65\u9aa4\u548c\u65b9\u6cd5\u5982\u4e0b\uff1a\u5c06\u767d\u8272\u7eb8\u677f\u653e\u5728\u4f20\u611f\u5668\u524d\u65b9\uff0c\u4f7f\u5165\u5c04\u5149\u80fd\u591f\u7167\u5c04\u5230TCS230\u4e0a\uff1b\u6839\u636e\u524d\u9762\u6240\u4ecb\u7ecd\u7684\u65b9\u6cd5\uff0c\u4f9d\u6b21\u9009\u901a\u7ea2\u8272\u3001\u7eff\u8272\u548c\u84dd\u8272\u6ee4\u6ce2\u5668\uff0c\u5206\u522b\u6d4b\u5f97\u7ea2\u8272\u3001\u7eff\u8272\u548c\u84dd\u8272\u6240\u4ea7\u751f\u5230\u7b2c255\u4e2a\u8109\u51b2\u65f6\u7684\u65f6\u95f4\uff0c\u8fd9\u4e9b\u65f6\u95f4\u5bf9\u5e94\u4e8e\u5b9e\u9645\u6d4b\u8bd5\u65f6TCS230\u6bcf\u79cd\u6ee4\u6ce2\u5668\u6240\u91c7\u7528\u7684\u65f6\u95f4\u57fa\u51c6\uff0c\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\u6240\u6d4b\u5f97\u7684\u8109\u51b2\u6570\u5c31\u662f\u6240\u5bf9\u5e94\u7684R\u3001G\u548cB\u7684\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u989c\u8272\u8bc6\u522b\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong>\u5f53\u7528TCS230\u8bc6\u522b\u989c\u8272\u65f6\uff0c\u5c31\u7528\u4e0a\u8ff03\u4e2a\u65f6\u95f4\u57fa\u51c6\u5206\u522b\u6d4b\u5f97\u5728\u65f6\u95f4\u5185TCS-230\u6240\u8f93\u51fa\u7684\u8109\u51b2\u4e2a\u6570\uff0c\u8be5\u8109\u51b2\u4e2a\u6570\u5373\u4e3a\u6d4b\u5f97\u4e09\u4e2a\u989c\u8272\u901a\u9053\u7684\u989c\u8272\u53c2\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6838\u5fc3\u4ee3\u7801\u5b9e\u73b0\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u4f53RTL\u89c6\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"502\" src=\"http:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-15-1024x502.png\" alt=\"\" class=\"wp-image-110\" srcset=\"https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-15-1024x502.png 1024w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-15-300x147.png 300w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-15-768x376.png 768w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-15-1536x753.png 1536w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-15.png 1577w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff081\uff09\u9876\u5c42\u6a21\u5757\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u57fa\u4e8eVerilog\u7684TCS230\u989c\u8272\u4f20\u611f\u5668\u9a71\u52a8\u7a0b\u5e8f\n\/*\n\u5f15\u811a\u5b9a\u4e49\uff1a\nGND\uff08\u5730\u7ebf\uff09\uff1a\u7535\u6e90\u5730\u7ebf\u3002\nOE\uff08\u8f93\u51fa\u4f7f\u80fd\uff09\uff1a\u542f\u7528\u8f93\u51fa\u9891\u7387\uff08\u4f4e\u7535\u5e73\u6709\u6548\uff09\u3002\nOUT\uff1a\u8f93\u51fa\u9891\u7387\u3002\nS0\u3001S1\uff08\u7f29\u653e\u9009\u62e9\u8f93\u5165\uff09\uff1a\u7528\u4e8e\u7f29\u653e\u8f93\u51fa\u9891\u7387\uff08Arduino \u901a\u5e38\u4f7f\u7528 20% \u7f29\u653e\uff09\u3002\nS2\u3001S3\uff08\u5149\u7535\u4e8c\u6781\u7ba1\u7c7b\u578b\u9009\u62e9\u8f93\u5165\uff09\uff1a\u9009\u62e9\u8981\u8bfb\u53d6\u7684\u989c\u8272\u3002\nVDD\uff08\u7535\u538b\u4f9b\u5e94\uff09\uff1a\u63d0\u4f9b\u7535\u538b\u3002\n\u6ee4\u5149\u7247\u9009\u62e9\uff1a\u786e\u5b9a\u5149\u7535\u4e8c\u6781\u7ba1\u7684\u989c\u8272\uff08\u4f8b\u5982\u7ea2\u8272\u3001\u84dd\u8272\u3001\u7eff\u8272\u6216\u65e0\u6ee4\u5149\u7247\uff09\n*\/\nmodule  TCS230_Demo (\n    input clk_50Mhz,\n    input rst,\n    input TCS_Out,\n    input EN,\n    input test,\n    output wire OE,S0,S1,S2,S3,\n    output wire &#91;23:0] Color_Out_D,\n    output wire DONE,\n    output uart_tx\n);\nwire delay,timer_out,pulse_en,timer_en,pulse_clr,pulse_done;\/\/\u5b9a\u65f6\u5668\u4f7f\u80fd\u548c\u8109\u51b2\u4f7f\u80fd\nwire &#91;7:0] Color_Cnt_RGB,Color_Cnt_D;\/\/\u989c\u8272\u8ba1\u6570\u5668\nwire &#91;13:0] SR_Cnt;\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\nwire &#91;13:0] CR_Cnt;\nwire &#91;41:0]SR_RGB;\n\/\/\u4f8b\u5316DataPath\u6a21\u5757\nDataPath DP(\n    .rst(rst),\n    .clk(clk_50Mhz),\n    .TCS_Out(TCS_Out),\n    .test_EN(test_en),\n    .CR_RGB_en(CR_RGB_en),\n    .delay_en(delay_en),\n    .test_down(test_down),\n    .delay(delay),\n   \/\/ .SR_RGB(SR_RGB),\n    .SR_Cnt(SR_Cnt),\n    .Color_Cnt_D(Color_Cnt_D),\n    .CR_down(CR_down),\n    .CR_Cnt(CR_Cnt)\n    \n);\nwire &#91;4:0]present_state;\n \n\/\/\u4f8b\u5316TCS_230_SYS\u6a21\u5757\nTCS_230_SYS TCS230_SYS(\n    .clk(clk_50Mhz),\n    .RSTN(rst),\n    .EN(EN),\n    .test(test),\n    .delay(delay),\n    .test_down(test_down),\n    .CR_down(CR_down),\n    .SR_Cnt(SR_Cnt),\n    .delay_en(delay_en),\n    .test_en(test_en),\n    .CR_RGB_en(CR_RGB_en),\n    .SR_RGB(SR_RGB),\n    .oe(OE),.S0(S0),.S1(S1),.S2(S2),.S3(S3),\n    .present_state(present_state),\n    .CR_Cnt(CR_Cnt),\n    .Color_Out_D(Color_Out_D),\n    .R_TCS_done(DONE),\n    .Color_Cnt_D(Color_Cnt_D)\n);\n \n\/\/\u4f8b\u5316uart_tx\u6a21\u5757\nUart_tx UT(\n    .uart_tx(uart_tx),\n    .clk_100m(clk_50Mhz),\n    .rst(rst),\n    .data1({6'd0,Color_Out_D&#91;23:16]}),\n    .data2({6'd0,Color_Out_D&#91;15:8]}),\n    .data3({6'd0,Color_Out_D&#91;7:0]}),\n    .data4(SR_RGB&#91;41:28]),\n    .data5(SR_RGB&#91;27:14]),\n    .data6(SR_RGB&#91;13:0]),\n    .data7({9'd0,present_state})\n);\n \n \nendmodule\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff082\uff09\u6570\u636e\u901a\u9053\u6a21\u5757\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"588\" src=\"http:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-16-1024x588.png\" alt=\"\" class=\"wp-image-111\" srcset=\"https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-16-1024x588.png 1024w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-16-300x172.png 300w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-16-768x441.png 768w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-16-1536x882.png 1536w, https:\/\/blog.huanmie.fun\/wp-content\/uploads\/2024\/05\/image-16.png 1609w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u6570\u636e\u901a\u9053\u6a21\u5757\nmodule DataPath(\n        input rst,clk,\/\/\u590d\u4f4d\u548c\u65f6\u949f\n        input TCS_Out,\/\/TCS230\u8f93\u51fa\n        input test_EN,\/\/\u6d4b\u8bd5\u4f7f\u80fd\n        input delay_en,\/\/\u5ef6\u65f6\u4f7f\u80fd\n        input CR_RGB_en,\/\/\u989c\u8272\u8bfb\u53d6\u4f7f\u80fd\n        input &#91;13:0] CR_Cnt,\/\/\u989c\u8272\u8ba1\u6570\u5668\n        \/\/input &#91;41:0]SR_RGB,\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\n        output test_down,\/\/\u6d4b\u8bd5\u5b8c\u6210\n        output CR_down,\/\/\u989c\u8272\u8bc6\u522b\u5b8c\u6210\n        output delay,\/\/\u5ef6\u65f6\n        output &#91;13:0]SR_Cnt,\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\n        output &#91;7:0] Color_Cnt_D\/\/\u989c\u8272\u8ba1\u6570\u5668\n);\n \nwire &#91;7:0] Color_Cnt_RGB;\/\/\u989c\u8272\u8ba1\u6570\u5668\n \n\/\/\u4f8b\u5316timer\u6a21\u5757\ntimer TIMER0(\n    .timeout(timer_out),\n    .clk(clk),\n    .rst(!rst),\n    .en(timer_en)\n);\nwire timer_en1,timer_en2,pulse_en1,pulse_en2,pulse_clr1,pulse_clr2;\nassign timer_en = timer_en1 || timer_en2;\n\/\/\u4f8b\u5316timer\u6a21\u5757\ntimer delay1(\n    .timeout(delay),\n    .clk(clk),\n    .rst(!rst),\n    .en(delay_en)\n);\n \nassign pulse_en = pulse_en1 || pulse_en2;\nassign pulse_clr = pulse_en?1'b0:1'b1;\n\/\/\u4f8b\u5316\u8109\u51b2\u8ba1\u6570\u6a21\u5757\npulse_count PCNT(\n    .count(Color_Cnt_RGB),\n    .pulse_in(TCS_Out),\n    .clk(clk),\n    .rst(!rst),\n    .pulse_en(pulse_en),\n    .pulse_clr(pulse_clr)\n    );\n\/\/\u4f8b\u5316color_test\u6a21\u5757\nColor_test CT(\n    .clk(clk),\n    .RSTN(rst),\n    .test_EN(test_EN),\n    .timeout(timer_out),\n    .Color_Cnt_RGB(Color_Cnt_RGB),\n    .pulse_en(pulse_en1),\n    .pulse_clr(pulse_clr1),\n    .timer_en(timer_en1),\n    .SR_Cnt(SR_Cnt),\n    .test_down(test_down)\n);\n \n\/\/\u4f8b\u5316color_CR\u6a21\u5757\nColor_CR CR(\n    .clk(clk),\n    .RSTN(rst),\n    .CR_RGB_en(CR_RGB_en),\n    .CR_Cnt(CR_Cnt),\n    .timeout(timer_out),\n    .Color_Cnt_RGB(Color_Cnt_RGB),\n    .Color_Cnt_D(Color_Cnt_D),\n    .pulse_en(pulse_en2),\n    .pulse_clr(pulse_clr2),\n    .timer_en(timer_en2),\n    .CR_down(CR_down)\n);\n \nendmodule\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff083\uff09\u72b6\u6001\u673a\u6a21\u5757\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u72b6\u6001\u673a\u6a21\u5757\nmodule TCS_230_SYS(\n        input clk,\/\/\u65f6\u949f\n        input RSTN,\/\/\u590d\u4f4d\n\t\tinput EN,test,\n        input delay,\/\/\u5ef6\u65f6\n        input test_down,\/\/\u6d4b\u8bd5\u5b8c\u6210\n        input CR_down,\/\/\u989c\u8272\u8bc6\u522b\u5b8c\u6210\n        input &#91;13:0]SR_Cnt,\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\n        input &#91;7:0] Color_Cnt_D,\/\/\u989c\u8272\u8ba1\u6570\u5668\n        output reg delay_en,\/\/\u5ef6\u65f6\u4f7f\u80fd\n        output reg test_en,\/\/\u6d4b\u8bd5\u4f7f\u80fd\n        output reg CR_RGB_en,\/\/\u989c\u8272\u8bfb\u53d6\u4f7f\u80fd\n        output reg &#91;41:0]SR_RGB,\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\n        output reg oe,S0,S1,S2,S3,\/\/TCS230\u8f93\u5165\u4fe1\u53f7\n        output reg &#91;4:0]present_state,\n        output reg &#91;13:0] CR_Cnt,\/\/\u989c\u8272\u8ba1\u6570\u5668\n        output reg &#91;23:0] Color_Out_D,\/\/\u989c\u8272\u8f93\u51fa\n        output reg R_TCS_done\/\/TCS230\u5b8c\u6210\n        );\n\/\/reg &#91;4:0]present_state;\n \nreg &#91;4:0]next_state;\/\/\u5f53\u524d\u72b6\u6001\u548c\u4e0b\u4e00\u72b6\u6001\nparameter   Init    =   5'b00000,\/\/\u521d\u59cb\u72b6\u6001\n            Wait    =   5'b00001,\/\/\u7b49\u5f85\u72b6\u6001\n            C_R_W   =   5'b00010,\/\/R_W\n            C_R     =   5'b00011,\/\/G\n            C_G_W   =   5'b00111,\/\/B\n            C_G     =   5'b00101,\/\/R\n            C_B_W   =   5'b00100,\/\/G\n            C_B     =   5'b01100,\/\/B\n            done_out=   5'b01101,\/\/\u8f93\u51fa\n            t_R_W   =   5'b01111,\/\/T_R_W\n            t_R     =   5'b01110,\/\/T_R\n            t_G_W   =   5'b11110,\/\/T_G_W\n            t_G     =   5'b11111,\/\/T_G\n            t_B_W   =   5'b11101,\/\/T_B_W\n            t_B     =   5'b11001;\/\/T_B\n \nalways @ (posedge clk or negedge RSTN)\n    if(!RSTN)begin\/\/\u590d\u4f4d\n        present_state&lt;=Init;  \n    end\n    else\n        present_state&lt;=next_state;\n\/\/\u72b6\u6001\u673a\n\/*\n    TCS230\u8f93\u5165\u4fe1\u53f7\n    {oe,S0,S1,S2,S3}=5'b01110;\/\/\u521d\u59cb\u5316\n    {oe,S0,S1,S2,S3}=5'b11100;\/\/100%\u7f29\u653e,\u9009\u62e9\u7ea2\u8272\n    {oe,S0,S1,S2,S3}=5'b11111;\/\/100%\u7f29\u653e,\u9009\u62e9\u7eff\u8272\n    {oe,S0,S1,S2,S3}=5'b11101;\/\/100%\u7f29\u653e,\u9009\u62e9\u84dd\u8272\n    \u8109\u51b2\u8ba1\u6570\u5668\u8f93\u5165\u4fe1\u53f7\n    {pulse_en,pulse_clr} = 3'b01;\/\/\u521d\u59cb\u5316\n    {pulse_en,pulse_clr} = 3'b10;\/\/\u542f\u7528\u8ba1\u6570\u5668\n    {pulse_en,pulse_clr} = 3'b01;\/\/\u6e05\u96f6\u8ba1\u6570\u5668\n    \u8ba1\u65f6\u5668\u8f93\u5165\u4fe1\u53f7 \n    timer_en = 1'b0;\/\/\u521d\u59cb\u5316\n    timer_en = 1'b1;\/\/\u542f\u7528\u8ba1\u65f6\u5668\n*\/\nalways @ (*) begin\n    case (present_state)\n        Init:begin\n            SR_RGB = {14'd1500,14'd1500,14'd1500};\/\/\u521d\u59cb\u5316\n            {oe,S0,S1,S2,S3}=5'b01110;\/\/\u521d\u59cb\u5316\n            {delay_en,test_en,CR_RGB_en}=3'b000;\/\/\u521d\u59cb\u5316\n            R_TCS_done = 0;\n            next_state=Wait;\n        end\n        Wait:begin\n            {oe,S0,S1,S2,S3}=5'b01110;\/\/\u521d\u59cb\u5316\n            {delay_en,test_en,CR_RGB_en}=3'b000;\/\/\u521d\u59cb\u5316\n            R_TCS_done = 0;\n            next_state=Wait;\n            if(!test)begin\n                next_state=t_R_W;\n                \/\/SR_RGB = SR_RGB;\n            end\n            else begin\n                if(!EN)begin\n                    next_state=C_G_W;\n                    \/\/SR_RGB = SR_RGB;\n                end\n                else begin\n                    next_state=Wait;\n                    \/\/SR_RGB = SR_RGB;\n                end\n            end\n        end\n        t_R_W:begin\n            {oe,S0,S1,S2,S3}=5'b11100;\/\/100%\u7f29\u653e,\u9009\u62e9\u7ea2\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b100;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(delay)begin\n                next_state=t_R;\n            end\n            else begin\n                next_state=t_R_W;\n            end\n        end\n        t_R:begin\n            {oe,S0,S1,S2,S3}=5'b11100;\/\/100%\u7f29\u653e,\u9009\u62e9\u7ea2\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b010;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(test_down)begin\n                next_state=t_G_W;\n                SR_RGB&#91;41:28] = SR_Cnt;\n            end\n            else begin\n                SR_RGB&#91;41:28] = SR_RGB&#91;41:28];\n                next_state=t_R;\n            end\n        end\n        t_G_W:begin\n            {oe,S0,S1,S2,S3}=5'b11111;\/\/100%\u7f29\u653e,\u9009\u62e9\u7eff\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b100;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(delay)begin\n                next_state=t_G;\n                \/\/SR_RGB = SR_RGB;\n            end\n            else begin\n                next_state=t_G_W;\n                \/\/SR_RGB = SR_RGB;\n            end\n        end\n        t_G:begin\n            {oe,S0,S1,S2,S3}=5'b11111;\/\/100%\u7f29\u653e,\u9009\u62e9\u7eff\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b010;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(test_down)begin\n                next_state=t_B_W;\n                SR_RGB&#91;27:14] = SR_Cnt;\n            end\n            else begin\n                SR_RGB&#91;27:14] = SR_RGB&#91;27:14];\n                next_state=t_G;\n            end\n        end\n        t_B_W:begin\n            {oe,S0,S1,S2,S3}=5'b11101;\/\/100%\u7f29\u653e,\u9009\u62e9\u84dd\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b100;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(delay)begin\n                next_state=t_B;\n                \/\/SR_RGB = SR_RGB;\n            end\n            else begin\n                next_state=t_B_W;\n                \/\/SR_RGB = SR_RGB;\n            end\n        end\n        t_B:begin\n            {oe,S0,S1,S2,S3}=5'b11101;\/\/100%\u7f29\u653e,\u9009\u62e9\u84dd\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b010;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(test_down)begin\n                next_state=Wait;\n                SR_RGB&#91;13:0] = SR_Cnt;\n            end\n            else begin\n                SR_RGB&#91;13:0] = SR_RGB&#91;13:0];\n                next_state=t_B;\n            end\n        end\n \n        C_R_W:begin\n            {oe,S0,S1,S2,S3}=5'b11100;\/\/100%\u7f29\u653e,\u9009\u62e9\u7ea2\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b100;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(delay)begin\n                next_state=C_R;\n                SR_RGB = SR_RGB;\n               \n            end\n            else begin\n                next_state=C_R_W;\n                SR_RGB = SR_RGB;\n               \n            end\n        end\n        C_R:begin\n            {oe,S0,S1,S2,S3}=5'b11100;\/\/100%\u7f29\u653e,\u9009\u62e9\u7ea2\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b001;\/\/\u542f\u7528\u8bfb\u53d6\u989c\u8272CR_Cnt\n            CR_Cnt = SR_RGB&#91;41:28];\n            if(CR_down)begin\n                next_state=done_out;\n                Color_Out_D&#91;23:16] = Color_Cnt_D;\n            end\n            else begin\n               \/\/ \/\/SR_RGB = SR_RGB;\n                \n                next_state=C_R;\n            end\n        end\n \n        C_G_W:begin\n            {oe,S0,S1,S2,S3}=5'b11111;\/\/100%\u7f29\u653e,\u9009\u62e9\u7eff\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b100;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(delay)begin\n                next_state=C_G;\n                \/\/SR_RGB = SR_RGB;\n                \n            end\n            else begin\n                next_state=C_G_W;\n                \/\/SR_RGB = SR_RGB;\n               \n            end\n        end\n \n        C_G:begin\n            {oe,S0,S1,S2,S3}=5'b11111;\/\/100%\u7f29\u653e,\u9009\u62e9\u7eff\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b001;\/\/\u542f\u7528\u8bfb\u53d6\u989c\u8272CR_Cnt\n            CR_Cnt = SR_RGB&#91;27:14];\n            if(CR_down)begin\n                next_state=C_B_W;\n                Color_Out_D&#91;15:8] = Color_Cnt_D;\n            end\n            else begin\n                \/\/SR_RGB = SR_RGB;\n                \n                next_state=C_G;\n            end\n        end\n \n        C_B_W:begin\n            {oe,S0,S1,S2,S3}=5'b11101;\/\/100%\u7f29\u653e,\u9009\u62e9\u84dd\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b100;\/\/\u542f\u7528\u5ef6\u8fdf\n            if(delay)begin\n                next_state=C_B;\n                \/\/SR_RGB = SR_RGB;\n               \n            end\n            else begin\n                next_state=C_B_W;\n                \/\/SR_RGB = SR_RGB;\n              \n            end\n        end\n \n        C_B:begin\n            {oe,S0,S1,S2,S3}=5'b11101;\/\/100%\u7f29\u653e,\u9009\u62e9\u84dd\u8272\n            {delay_en,test_en,CR_RGB_en}=3'b001;\/\/\u542f\u7528\u8bfb\u53d6\u989c\u8272CR_Cnt\n            CR_Cnt = SR_RGB&#91;13:0];\n            if(CR_down)begin\n                next_state=C_R_W;\n                Color_Out_D&#91;7:0] = Color_Cnt_D;\n            end\n            else begin\n                \/\/SR_RGB = SR_RGB;\n                \n                next_state=C_B;\n            end\n        end\n \n        done_out:begin\n            {oe,S0,S1,S2,S3}=5'b01110;\/\/\u521d\u59cb\u5316\n            R_TCS_done = 1;\n            {delay_en,test_en,CR_RGB_en}=3'b000;\/\/\u521d\u59cb\u5316\n            next_state=Wait;\n        end\n\t\t  \n        default: \n            next_state=Init;\n\t\t  \n    endcase\nend\nendmodule<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff084\uff09\u767d\u5e73\u8861\u6821\u51c6\u6a21\u5757\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u767d\u5e73\u8861\u6821\u51c6\u6a21\u5757\nmodule Color_test(\n    input clk,\/\/\u65f6\u949f\n    input RSTN,\/\/\u590d\u4f4d\n    input test_EN,\/\/\u4f7f\u80fd\n    input timeout,\/\/\u5b9a\u65f6\u5668\n    input &#91;7:0] Color_Cnt_RGB,\/\/\u989c\u8272\u8ba1\u6570\u5668\n    output reg pulse_en,pulse_clr,\/\/\u8109\u51b2\u4f7f\u80fd\u548c\u5b9a\u65f6\u5668\u4f7f\u80fd\n    output reg timer_en,\/\/\u5ef6\u65f6\u4f7f\u80fd\u548c\u5b9a\u65f6\u5668\u4f7f\u80fd\n    output reg &#91;13:0]SR_Cnt,\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\n    output reg test_down\/\/\u767d\u5e73\u8861\u5b8c\u6210\n);\n \nalways @ (posedge clk or negedge RSTN)\n    if(!RSTN)begin\/\/\u590d\u4f4d\n        {pulse_en,pulse_clr}&lt;=2'b01;\n        timer_en&lt;=0;\n        SR_Cnt&lt;=0;\n        test_down &lt;= 0;\n    end\n    else begin\n        if(test_EN)begin\n            {pulse_en,pulse_clr}&lt;=2'b10;\n            timer_en&lt;=1;\n            if(timeout)begin\n                SR_Cnt&lt;=SR_Cnt+1;\n                if(Color_Cnt_RGB&gt;=14'd255)begin\n                    test_down &lt;= 1;\n                end\n                else begin\n                    test_down &lt;= 0;\n                end\n            end\n            else begin\n                test_down &lt;= 0;\n                SR_Cnt&lt;=SR_Cnt;\n            end\n            \n        end\n        else begin\n            {pulse_en,pulse_clr}&lt;=2'b01;\n            timer_en&lt;=0;\n            test_down &lt;= 0;\n            SR_Cnt&lt;=0;\n        end\n    end\nendmodule<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff085\uff09\u989c\u8272\u8bc6\u522b\u6a21\u5757<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u989c\u8272\u8bc6\u522b\u6a21\u5757\nmodule Color_CR(\n    input clk,\/\/\u65f6\u949f\n    input RSTN,\/\/\u590d\u4f4d\n    input CR_RGB_en,\/\/\u989c\u8272\u8bc6\u522b\u4f7f\u80fd\n    \/\/input &#91;41:0]SR_RGB,\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\n    input wire &#91;13:0]CR_Cnt,\/\/\u5b9a\u65f6\u5668\u8ba1\u6570\u5668\n    input timeout,\/\/\u5b9a\u65f6\u5668\n    input &#91;7:0] Color_Cnt_RGB,\/\/\u989c\u8272\u8ba1\u6570\u5668\n    output reg &#91;7:0] Color_Cnt_D,\/\/\u989c\u8272\u8ba1\u6570\u5668\n    output reg pulse_en,pulse_clr,\/\/\u8109\u51b2\u4f7f\u80fd\u548c\u5b9a\u65f6\u5668\u4f7f\u80fd\n    output reg timer_en,\/\/\u5ef6\u65f6\u4f7f\u80fd\u548c\u5b9a\u65f6\u5668\u4f7f\u80fd\n    output reg CR_down\/\/\u989c\u8272\u8bc6\u522b\u5b8c\u6210\n);\nreg &#91;13:0] tmp_cnt;\nalways @ (posedge clk or negedge RSTN)\n    if(!RSTN)begin\/\/\u590d\u4f4d\n        {pulse_en,pulse_clr}&lt;=2'b01;\n        timer_en&lt;=0;\n        tmp_cnt&lt;=0;\n        CR_down &lt;= 0;\n    end\n    else begin\n        if(CR_RGB_en)begin\n            {pulse_en,pulse_clr}&lt;=2'b10;\n            timer_en&lt;=1;\n            if(timeout)begin\n                \n                if(tmp_cnt&gt;=CR_Cnt)begin\n                    CR_down &lt;= 1;\n                    Color_Cnt_D&lt;=Color_Cnt_RGB;\n                    tmp_cnt &lt;= 0;\n                end\n                else begin\n                    tmp_cnt &lt;=tmp_cnt+1;\n                    CR_down &lt;= 0;\n                end\n            end\n            else begin\n                CR_down &lt;= 0;\n                tmp_cnt&lt;=tmp_cnt;\n \n            end      \n        end\n        else begin\n            {pulse_en,pulse_clr}&lt;=2'b01;\n            timer_en&lt;=0;\n            CR_down &lt;= 0;\n            tmp_cnt &lt;= 0;\n        end\n    end\nendmodule<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff086\uff09\u8ba1\u65f6\u5668\u6a21\u5757<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u8ba1\u65f6\u5668\u6a21\u5757\nmodule timer (\n    output reg timeout,\n    input clk,\n    input rst,\n    input en\n);\n    parameter div_value = 50;\n    reg&#91;5:0] cnt_value;\n    \n    always@(posedge clk or posedge rst)\n    begin\n        if(rst)\n            timeout &lt;= 0;\n        else if(en)\n                if(cnt_value == div_value - 1)\n                    timeout &lt;= 1;\n                else\n                    timeout &lt;= 0;\n            else\n                timeout &lt;= 0;\n    end\n    \n    always@(posedge clk or posedge rst)\n    begin\n        if(rst )\n            cnt_value &lt;= 0;\n        else\n\t\t\tif(en)\n                if((cnt_value == div_value - 1))\n\t\t\t\t    cnt_value &lt;= 0;\n\t\t\t\telse\n                    cnt_value &lt;= cnt_value + 1;\n            else\n                cnt_value &lt;= 0;\n    end\n    \nendmodule<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff087\uff09\u8109\u51b2\u8ba1\u6570\u5668\u6a21\u5757<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>module pulse_count(\n    output reg&#91;7:0] count,\n    input pulse_in,\n    input clk,\n    input rst,\n    input pulse_en,\n    input pulse_clr\n    );\n    \n    wire pulse_filt;\n    parameter filter_level = 2;\n \n    pulse_conver PC0(\n        .pulse_out(pulse_filt),\n        .pulse_in(pulse_in),\n        .clk(clk),\n        .rst(rst)\n        );\n    \n    integer j;\n    always@(posedge clk or posedge rst)\n    begin\n        if(rst)\n            count &lt;= 0;\n        else begin\n            if(pulse_clr)begin\n                count &lt;= 0;\n            end else begin\n                if(pulse_en)begin\n                    for(j = 0;j &lt; 2;j = j + 1) begin\n                        count &lt;= count + pulse_filt;\n                    end\n                end\n                else\n                    count &lt;= count;\n            end\n        end\n    end\n    \nendmodule<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6a21\u5757\u7b80\u4ecb\uff1a \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TCS230\u662fTAOS\u516c\u53f8\u63a8\u51fa\u7684\u53ef\u7f16\u7a0b\u5f69\u8272\u5149\u5230\u9891\u7387\u7684\u8f6c\u6362\u5668\u3002\u5b83\u628a\u53ef\u914d\u7f6e\u7684\u7845\u5149\u7535\u4e8c\u6781\u7ba1\u4e0e\u7535\u6d41\u9891\u7387\u8f6c\u6362\u5668\u96c6 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":111,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-105","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fpga"],"_links":{"self":[{"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":4,"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":116,"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/posts\/105\/revisions\/116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/media\/111"}],"wp:attachment":[{"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.huanmie.fun\/index.php\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}