1.2. PWM Using MAX II Devices
The detailed description of the implementation is based on the MAX II devices. This application can also be implemented in MAX V and MAX 10 devices.
The up and down input signals are used to vary the duty cycle of the output signal. The first module is used to generate two clocks of different frequencies with the available internal user flash memory oscillator in MAX II devices. The 4-bit output signal from the DUTY_CYCLE module has positive or negative incrementation, depending on whether up or down is asserted. The second 4-bit output signal COUNT (reference counter) is incremented continuously at the higher clock frequency generated in the first module. This signal is compared to DUTY_CYCLE at the same frequency in the second module. The result of the comparison, which is a single bit, is assigned to the final output signal PWM.
The inputs to the PWM are comprised of up and down signals used to vary the duty cycle of the output signal. The device uses two basic modules to realize the working of the PWM. All input and output signals are of a single bit.
The 4-bit variable signal DUTY_CYCLE allows 16 different variations in the duty cycle of the output signal. In this design implementation, input up has a higher priority over down. If both are high at the same time, the output signal sees an increase in its duty cycle.
You can implement this design example with an EPM240, or any other MAX II devices, and observe results by controlling the intensity of mono-color (red) LEDs and varying color shades of bi-color (red/green) LEDs on the MDN-B2 demo board. Implement this design with the design example source code and allocate the appropriate control and output lines to the GPIO lines of the MAX II device that are connected to LEDs. The red LEDs are driven by the PWM output, which causes their intensities to vary. The bi-color LEDs are driven by two mutually complementary signals: PWM and PWM_INV. The frequency of operation causes the phenomenon of persistence of human vision. This creates a small spectrum of colors involving the two individual colors of the bi-color LEDs, while their individual intensities are varied corresponding to the PWM signal. You can operate two push-button switches on the demo board to gradually create the small spectrum of colors. This also illustrates the change in the duty cycle of the output signal because of the varied intensity of the single-color LED.
Signal | Pin |
---|---|
pwm | Pin 87 |
pwm1 | Pin 71 |
pwm3 | Pin 73 |
up | Pin 82 |
pwn_inv | Pin 88 |
pwm2 | Pin 72 |
pwm4 | Pin 74 |
dn | Pin 81 |