RGB Generator Using VHDL
RGB Generator Using VHDL
Faculty of Engineering
Department of Electronic and Communications Engineering
30 / 11 / 2023
Content
-Introduction
-Procedures
-Implementation and Results
- Applications
-Appendix
Introduction
RGB components are widely used in today’s devices, one reason is
that they are attractive because of their beautiful colors, control of
such components requires a Microcontroller in most cases, which
in turn uses PWM signal in order to produce analog output from
digital input (Variations in Duty Cycle). This approach could be
expensive for controlling small components.
Procedures
The Most basic RGB component is the RGB LED shown in figure
(1), RGB LED stands for Red, Green, Blue Light Emitting Diode.
It's a type of LED that can emit light in multiple colors, making
RGB LEDs popular in various applications like lighting, displays,
and electronic devices. It consists of 3 anodes and a cathode
(common cathode type) the operation is simple, each of the 3
anodes will be connected to digital high (usually 5V or 3.3V )
while cathode is connected the ground.
Figure.(1) RGB LED.
For anodes, each pin will be at maximum intensity when digital
high is supplied this means we cannot get some colors that require
variations in intensities, only colors that require a combination of
maximum intensities is available, since we have 3 anodes then: 2^3
= 8 Possible colors as shown in Table.(1).
R G B LED
0 0 0 (Off)
0 0 1 Blue
0 1 0 Green
0 1 1 Cyan
1 0 0 Red
1 0 1 Magenta
1 1 0 Yellow
1 1 1 White
Table.(1). Possible colors
Our procedure is to cycle through these possible colors, starting
from cold colors (Blue, Cyan …) toward the hot colors (Red,
Yellow…) With an interval of 1 Second for each color:
To test the results, we tried to simulate the code with the counter
but since the simulation waveform editor in Quartus can only show
output for 100 μs maximum and that is too far from 1 second, so
we cannot simulate the code with this interval, the simulation will
be done using a counter of 0.1 μs instead as an input to the FSM
(same code but different time count, see Figure.(5)) and we can
subdivide the code to two codes (the complete code with the
counter of 1 second) and (the code with the counter of 0.1 μs, see
Appendix).
Figure.(4) Simulation waveform editor (University Program VWF with
button instead of counter).
Appendix
Complete Code for RGB Generator (1 Second Interval):
-- RGB_Generator entity--
library ieee;
use ieee.std_logic_1164.all;
entity RGB_Gen is
Port ( clk : in std_logic;
rst : in std_logic;
rgb : out std_logic_vector(2 downto 0));
end RGB_Gen;
component counter IS
PORT ( clk : IN STD_LOGIC; -- clk should be 100 Mhz
rst : IN STD_LOGIC;
one_second : OUT STD_LOGIC);
END component;
type state_type is (off, Blue, Green, Cyan, Red, Magneta, Yellow, White);
signal state, next_state: state_type;
signal one_second : std_logic;
begin
count : counter
port map (clk => clk, rst=>rst, one_second => one_second);
end case;
end process fsm_process;
end first;
-------Counter Entity-----------
library ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;
ENTITY counter IS
PORT ( clk : IN STD_LOGIC; -- clk should be 100 Mhz
rst : IN STD_LOGIC;
one_second : OUT STD_LOGIC);
END counter;
library ieee;
use ieee.std_logic_1164.all;
entity RGB_Gen is
Port ( clk : in std_logic;
rst : in std_logic;
rgb : out std_logic_vector(2 downto 0));
end RGB_Gen;
component counter IS
PORT ( clk : IN STD_LOGIC; -- clk should be 100 Mhz
rst : IN STD_LOGIC;
one_second : OUT STD_LOGIC);
END component;
type state_type is (off, Blue, Green, Cyan, Red, Magneta, Yellow, White);
signal state, next_state: state_type;
signal one_second : std_logic;
begin
count : counter
port map (clk => clk, rst=>rst, one_second => one_second);
state_assignment: process (clk) is
begin
if rising_edge(clk) then
if (rst = '1') then
state <= off;
else
state <= next_state;
end if;
end if;
end process state_assignment;
end case;
end process fsm_process;
end first;
-------Counter Entity-----------
library ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;
ENTITY counter IS
PORT ( clk : IN STD_LOGIC; -- clk should be 100 Mhz
rst : IN STD_LOGIC;
one_second : OUT STD_LOGIC);
END counter;
BEGIN