User manual
Basys MX3™ Board Reference Manual
Copyright Digilent, Inc. All rights reserved.
Other product and company names mentioned may be trademarks of their respective owners.
Page 19 of 56
There is one digital signal to control each color component. Using either 0 or 1 values for these signals will only
give the user a limited number of colors (two colors for each component), so most of the time this is not enough in
applications using the RGB feature. The solution is to send a sequence of 1 and 0 values on these digital lines,
switched rapidly with a frequency higher than human perception. The “duty factor” will finally determine the
color, as the human eye will “integrate” the discrete illumination values into the final color sensation.
The most used approach in solving this problem is the use of pulse-width modulation (PWM) signals. Another
approach is the use of pulse-density modulation (PDM). These methods are explained in the RGB LED Implemented
Using PWM and RGB LED Implemented Using PDM sections.
6.1 Connectivity
Label
Schematic
Name
PIC32 Pin
Description
R
LED8_R
AN25/RPD2/RD2
Signal corresponding to the R component of
the RGB
G
LED8_G
RPD12/PMD12/RD12
Signal corresponding to the G component of
the RGB
B
LED8_B
AN26/RPD3/RD3
Signal corresponding to the R component of
the RGB
Table 6.1. RGB LED connectivity.
6.2 Functionality
6.2.1 RGB LED Implemented Using PWM
The percentage of each period that the pulse is high determines the signals “duty cycle”. Figure 6.2 shows how
different duty cycles are implemented using PWM.
Figure 6.2. PWM duty cycle.
Using this method, the intensity of each component of the RGB LED is determined by the duty cycle being applied.
PWM is most often implemented in the microcontroller using the output compare (OC) peripheral modules along
with a timer.
One timer (Timer y) is assigned to the OC module. Setting the PRy register of the timer will set the PWM period.
Setting the OCxRS register of the OC module will set the actual duty cycle.
The PIC32 datasheet displayed in Fig. 6.3 below explains how one period of the PWM is generated.