bit file onto the FPGA for verification first and then onto the ROM so that FPGA works as a PWM module whenever powered on. Input PWM_ontime // 8-bit PWM inputĪfter including the necessary files onto the project, select the option to generate a programming file, which creates. Module PWM_generator (PWM_ontime, PWM_out , Verilog main code used (PWM_main.v) for PWM generation is given below. Thus, PWM can be achieved by varying the input provided to PWM module. Comparator finds that, current counter value is greater than the value provided to PWM module, therefore output must be pulled low.Ĭhanging input to PWM module will consequently change the threshold value, where transition from high to low state occurs. In the next clock cycle, after the counter has reached 128, counter increments its value to 129(10000001) b. This same paradigm keeps output of the generator pulled high until value of the counter reaches 128 (10000000) b. This prompts the module to pull output of PWM generator high. The module finds that, value of counter is less than the value provided. During the first clock cycle, value of counter and input value to PWM module are compared. Counter is initialised using Reset button, so that output is 0(00000000 b). Suppose, input to PWM module is 128 (10000000 b). Let us take a test case to understand the operation. However, if current value of the counter is less than the value given as input to the module, output of PWM generator is pulled high.
If current value of the counter is greater than the value given to the module as input, PWM output is pulled low. Input given to PWM module is compared to the current value of the counter using the comparator. Comparator used in the PWM generator is also 8-bit. It increments its value on the positive edge of the clock (positive edge triggered).
The microcontroller unit provides 8-bit input into PWM module. Working principle of the generator is simple. PWM generationīlock diagram of the PWM generator is shown in Fig. It is simulated using ModelSim, a multi-language (hardware description language) simulation environment from Mentor Graphics and tested on Basys 2 FPGA development board from Digilent. This project demonstrates how a simple and fast pulse width modulator (PWM) generator can be implemented using Verilog programming.