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 20 of 56
Figure 6.3. PIC32 PWM generation.
The RGBLED library from the Basys MX3 library pack contains a commented example of PWM implementation with
the following features:
LED8_R, LED8_G, and LED8_B are mapped to OC3, OC5, and OC4.
OC3, OC5, and OC4 are properly configured, together with assigned Timer 2.
When a new color is set, its components (R, G, and B) are assigned to OC3RS, OC5RS, and OC4RS.
6.2.2 RGB LED Implemented Using PDM
PDM method adjusts both the frequency and length of the “High” pulses in the modulated signal.
A PDM is implemented using a register and an accumulator adder with carry output. The n-bit register can store
any binary value from 0 to 2
𝑛
1. In each clock period, the register content is added to the accumulator. The carry
bit (overflow of the n-bit accumulator) is the output. It is “High” as often as the accumulator overflows, so that
when large values are added, carry will occur often. The “High” pulse is only 1 clock period long, but more “High”
pulses can succeed when the register content is close to maximum.
The RGBLED library from the Basys MX3 library pack contains an example of PDM implementation, with the
following features:
LED8_R, LED8_G, and LED8_B are configured as simple digital outputs.
Timer 5 is configured to generate an interrupt every approx. x us.
Three 16-bit accumulators are used, one for each color.
In the interrupt service routine, for each color, the 8-bit color value is added to the corresponding 16-bit
accumulator.
For each color, the 9
th
bit of the accumulator is considered the carry bit. The resulted carry bits are
assigned to LED8_R, LED8_G, and LED8_B.
For each color, the accumulator is masked so that it only contains an 8-bit value (carry is cleared).
7 Seven-segment Display
The Basys MX3 board contains a four-digit common anode seven-segment LED display. Each of the four digits is
composed of seven segments displaying a “figure 8” pattern and a decimal point with an LED embedded in each
segment. Segment LEDs can be individually illuminated. Of the number of possible patterns, the ten corresponding
to the decimal digits are the most useful.