|
1 | | -# Example Chapter09_08a |
| 1 | +# Example Chapter09_08b (variation 32-bit microcontroller) |
2 | 2 | ## Controlling an RGB LED of type ws2812 |
3 | 3 |
|
4 | | -Example chapter09_08a utilizes object oriented programming techniques |
5 | | -to control an industry-standard RGB LED of type ws2812 |
6 | | - |
7 | | -This example controls an RGB LED using programming techniques similar to those used in the previous example. |
8 | | -There are, however, several differences such as the refactored, modernized LED-class hierarchy. |
9 | | -The main difference, however, is that a _digitally_-controlled industry-standard |
10 | | -RGB LED of type ws2812 is used. In addition, the color transitions at (and around) $255~\text{bits}$-RGB |
11 | | -are slowed down providing emphasized, longer-lasting RGB hues near these points. |
12 | | - |
13 | | -## Controlling the ws2812 |
14 | | - |
15 | | -The ws2812 RGB LED is controlled by a very specifically timed, |
16 | | -novel digital signal. In this signal, each of the $24$ RGB |
17 | | -color bits is set to the value $1$ or $0$ depending on the |
18 | | -half-width of a low/high signal pair. |
19 | | - |
20 | | -In this example (as in most other examples), both a hardware |
21 | | -version for the target system as well as a simlulated PC |
22 | | -version are available. For this exercise, it was |
23 | | -decided to implement a rather detailed PC simulation |
24 | | -using old-school traditional Win32-API programming. |
25 | | - |
26 | | -## Application Description |
27 | | - |
28 | | -Strikingly bright, vibrant hues of RGB blend in a smooth fashion around the entire |
29 | | -spectrum to produce the appearance of evenly varying colors. |
30 | | - |
31 | | -The user LED is simultaneously toggled at the usual $\frac{1}{2}~\text{Hz}$. |
32 | | - |
33 | | -The `led_rgb_ws2812` template class can be found in its entirety in the file |
34 | | -[`mcal_led_rgb_ws2812.h`](./src/mcal/avr/mcal_led_rgb_ws2812.h). |
35 | | - |
36 | | -The template signature of the `led_rgb_ws2812` template class is shown |
37 | | -in the declaration below. |
38 | | - |
39 | | -```cpp |
40 | | - namespace mcal { namespace led { |
41 | | - |
42 | | - template<const std::uint8_t PortAddr, |
43 | | - const std::uint8_t PortBpos, |
44 | | - const unsigned LedCount = static_cast<unsigned>(UINT8_C(1))> |
45 | | - class led_rgb_ws2812; |
46 | | -} } // namespace mcal::led |
47 | | -``` |
48 | | -
|
49 | | -The first two template parameters `PortAddr` and `PortBpos` |
50 | | -are used to set the port address and bit position of the digital I/O port. |
51 | | -These very specific mcal/microcontroller-dependent parameters |
52 | | -are used to generate the real-time ws2812 control signal. |
53 | | -
|
54 | | -The third template parameter `LedCount` provides the ability |
55 | | -to link multiple ws2812 devices seqentially and control them |
56 | | -in an LED chain, as is common for this particular device. |
57 | | -
|
58 | | -In example chapter09_08a, a ws2812 LED device is used. |
59 | | -
|
60 | | -### Enhanced RGB-Color-Light-Show |
61 | | -
|
62 | | -The RGB-color-light-show in example chapter09_08a (this example) |
63 | | -differs slightly from the one in example chapter09_08 (the previous example). |
64 | | -
|
65 | | -In this example the color transitions are a bit lenghtier in time |
66 | | -(instead of the normal $20~\text{ms}$). Also the color transitions |
67 | | -at and around the points $255~\text{bits}$-RGB |
68 | | -have been lengthened in time. This results in color emphasis |
69 | | -near these points. |
70 | | -
|
71 | | -This enhanced RGB-color-light-show can be found in the file |
72 | | -[`app_led.cpp`](./src/app/led/app_led.cpp). |
73 | | -
|
74 | | -### Windows Simulation |
75 | | -
|
76 | | -The chapter09_08a Win32-API simulation in its Windows-based |
77 | | -application is shown in action in the image below. |
78 | | -
|
79 | | - |
| 4 | +Example chapter09_08b utilizes essentially the same techniques |
| 5 | +to control its ws2812 RGB LED as were used in Example Chapter09_08a. |
| 6 | +In variation 09_08b, however, a 32-bit, single-core ARM(R) Cortex(R)-M3 |
| 7 | +microcontroller is used. |
80 | 8 |
|
81 | 9 | ## Hardware Setup |
82 | 10 |
|
83 | | -In this particular example, we have simply used a commercially-available |
84 | | -ARDUINO(R) placed on a breadboard with soldered-on pins. |
85 | | -The wiring is straightforward. The ws2812 port control uses port pin `portd.3`. |
86 | | -
|
87 | | -The hardware setup with the RGB LED in action is pictured |
88 | | -in the images below. The pictures show colorful RGB hues eminating |
89 | | -from the bright RGB LED of type ws2812. |
90 | | -
|
91 | | - |
92 | | - |
93 | | - |
94 | | -
|
95 | | -### Bit Timing: ws2812 |
96 | | -
|
97 | | -The approximate bit timing needed by the ws2812 is shown in the following table. |
98 | | -
|
99 | | -| Bit Value | $T_{hi}~\left[{ns}\right]$ | $T_{lo}~\left[{ns}\right]$ | |
100 | | -| --------- | --------------- | --------------- | |
101 | | -| $0$ | $350$ | $800$ | |
102 | | -| $1$ | $700$ | $600$ | |
103 | | -
|
104 | | -A sample partial-trace of the control signal on `portd.3` is shown |
105 | | -below in a representation of an image from a digital oscilloscpoe. |
| 11 | +In this particular example, we have simply used |
| 12 | +the commercially-available, open-platform |
| 13 | +[STM32F100 Value Line Discovery Kit](https://www.st.com/en/evaluation-tools/stm32vldiscovery.html) |
| 14 | +with soldered-on pins fitted on a breadboard. |
106 | 15 |
|
107 | | - |
| 16 | +The wiring is straightforward. The blinking LED uses the blue colored |
| 17 | +user LED controlled by pin `portc.8`. The LED digital control signal |
| 18 | +is on `portb.9`. The microcontroller is clocked at $24~\text{MHz}$. |
0 commit comments