PWM GENERATOR
Pulse Width Modulation (PWM) is a way to control analog devices with a digital output. Another way to put it is that you can output a modulating signal from a digital device such as an MCU to drive an analog device. It’s one of the primary means by which MCUs drive analog devices like variable-speed motors, dimmable lights, actuators, and speakers. PWM is not true analog output, however. PWM “fakes” an analog-like result by applying power in pulses, or short bursts of regulated voltage.
Supplies
We recommend to code with ISE Design Suite 14.7 as it can also be used to test the code in VHDL. However, to upload the code into BASYS 3, you will need to install Vivado (ver. 2015.4 or 2016.4) and write the constraint file with .xdc extension.
Signal Input and Output
INPUT
1. Nilai_Kecepatan_kiri : in STD_LOGIC_VECTOR (7 downto 0);
2. Nilai_Kecepatan_kanan : in STD_LOGIC_VECTOR (7 downto 0);
3. CLK : in STD_LOGIC; RST : in STD_LOGIC;
4. LEFT_DIR_INPUT : in STD_LOGIC;
5. RIGHT_DIR_INPUT : in STD_LOGIC;
INTERNAL SIGNAL
1. COUNTER_PWM_KIRI: STD_LOGIC_VECTOR(7 downto 0):=(others => '0'); (counter for PWM signal on left motor)
2. COUNTER_PWM_KANAN: STD_LOGIC_VECTOR(7 downto 0):=(others => '0'); (counter for PWM signal on right motor)
OUTPUT
1. LEFT_MOTOR_DIRECTION: out STD_LOGIC;
2. RIGHT_MOTOR_DIRECTION: out STD_LOGIC;
3. PWM_OUT_LEFT_MOTOR: out STD_LOGIC;
4. PWM_OUT_RIGHT_MOTOR: out STD_LOGIC;
How It Works
A Pulse Width Modulation (PWM) signal generator works by varying the duty cycle of a square wave while keeping the period fixed. so in a PWM generator, there is only a high input or a low input and we can control the duty cycle by controlling how long the signal is on for one period. in our PWM generator, we make an 8-bit PWM generator so one period equals the count of 255. The input signal that we receive is an 8-bit stream that is then sent to a counter that we have set to the value, so that the signal that is generated is high until the inputted value over 255 and that is one duty cycle. So hereby changing the duty cycle of the waveform we are actually changing the average value of the output waveform, and by doing so we are actually changing the average voltage that is applied to the load. so by changing the duty cycle we can control the device.
Click HERE for the code sample