The PWM output controls an LED light and adjusts the duty ratio of the output signal to change the brightness of the LED light.
Because the block module is parallel, it is very convenient to produce a clock module, which no longer needs to be interrupted by a timer like a single chip microcomputer.
The code is very simple and can be understood at a glance.
The program changes the output PWM---by adjusting the combined state of the SW0~SW4 LEDG
Module Pwm_module (Input CLK, input rst_n, input [4:0] option_key, output LED); Parameter SEGMENT = 8 ' d195;
3.9us reg [7:0] C1;
Always @ (Posedge CLK or Negedge rst_n) if (!rst_n) C1 <= 7 ' D0;
else if (c1 = = SEGMENT) C1 <= 7 ' D0;
else C1 <= C1 + 1 ' B1;
reg [7:0] system_seg;
Always @ (Posedge CLK or Negedge rst_n) if (!rst_n) system_seg <= 8 ' D0;
else if (system_seg = = 8 ' d255) system_seg <= 8 ' D0;
else if (c1 = = SEGMENT) system_seg <= system_seg + 1 ' B1;
reg [7:0] option_seg;
Always @ (Posedge CLK or Negedge rst_n) if (!rst_n) option_seg <= 8 ' D0; else if (option_key[4])//segment + if (Option_seg < 8 ' d245) option_seg <= option
_seg + 8 ' D10;
else option_seg <= 8 ' d255; else if (option_key[3])//segment-10 if (option_seg > 8 ' D10) option_seg <= op
Tion_seg-8 ' D10;
else option_seg <= 8 ' D0; else if (option_key[2])//segment + 1 if (Option_seg < 8 ' d255) option_seg <= option_s
eg + 8 ' d1;
else option_seg <= 8 ' d255; else if (option_key[1])//segment-1 if (option_seg > 8 ' d0) option_seg <= option_seg
-8 ' D1;
else option_seg <= 8 ' D0;
else if (option_key[0])//segment = half option_seg <= 8 ' d127; Assign led = (System_seg < option_seg)?
1 ' b1:1 ' B0; Endmodule
My pin assignment diagram