Beginning FPGA Programming - Partie52
Beginning FPGA Programming - Partie52
component light_sensor_adc_sequencer
port
(
clk : in std_logic;
avm_m0_address : out std_logic_vector(9 downto 0);
avm_m0_chipselect : out std_logic;
avm_m0_read : out std_logic;
avm_m0_readdata : in std_logic_vector(31 downto 0);
avm_m0_write : out std_logic;
avm_m0_writedata : out std_logic_vector(31 downto 0)
);
end component;
component light_sensor_counter_led
generic (LOW_BOUNDARY : integer;
HIGH_BOUNDARY : integer;
NUM_LEDS : integer
);
port(clk : in std_logic;
avl_str_sink_valid : in std_logic;
avl_str_sink_channel : in std_logic_vector(4 downto 0);
avl_str_sink_data : in std_logic_vector(11 downto 0);
avl_str_sink_startofpacket : in std_logic;
avl_str_sink_endofpacket : in std_logic;
pb4 : in std_logic;
led : out std_logic_vector(NUM_LEDS-1 downto 0)
);
end component;
251
Chapter 12 ■ Light Sensors: Turning a Laser Pointer into a Hi-Tech Tripwire
begin
-- The ADC in 10M08DAF484 needs to be fed by the c0 output of PLL_1 in the device.
-- The input clock source SYS_CLK on the BeMicro Max10 board is unfortunately placed on
the dedicated input to PLL_2 and can not feed PLL_1
-- Therefore we need to cascade the clock source via PLL_2, which is called "cascade_pll"
in this case.
cascade_pll_inst : cascade_pll
port map (
areset => '0',
inclk0 => SYS_CLK,
c0 => pll_cascade_c0_wire,
locked => pll_cascade_locked_reset_wire
);
252
Chapter 12 ■ Light Sensors: Turning a Laser Pointer into a Hi-Tech Tripwire
-- This module writes a "run" command into the ADC's CSR register
-- Default address in Qsys was placed on 0x0000_0000. Make sure it corresponds!
sequencer_inst : light_sensor_adc_sequencer
port map (
clk => pll_adc_clk_50m_wire,
avm_m0_address => wire_avm_m0_address,
avm_m0_chipselect => wire_avm_m0_chipselect,
avm_m0_read => wire_avm_m0_read,
avm_m0_readdata => wire_avm_m0_readdata,
avm_m0_write => wire_avm_m0_write,
avm_m0_writedata => wire_avm_m0_writedata
);
-- This module take the ADC data and detect the lost of light from laser beam
-- Counter number of lost and output the count value to LEDs
counter_led_inst : light_sensor_counter_led
generic map(
LOW_BOUNDARY => LOW_BOUNDARY,
HIGH_BOUNDARY => HIGH_BOUNDARY,
NUM_LEDS => NUM_LEDS
)
port map(
clk => pll_adc_clk_50m_wire,
avl_str_sink_valid => wire_avl_str_adc_counter_valid,
avl_str_sink_channel => wire_avl_str_adc_counter_channel,
avl_str_sink_data => wire_avl_str_adc_counter_data,
avl_str_sink_startofpacket => wire_avl_str_adc_counter_startofpacket,
avl_str_sink_endofpacket => wire_avl_str_adc_counter_endofpacket,
pb4 => PB(4),
led => USER_LED
);
end arch;
12.6.4 Add All Files to the Project and Create the Tripwire Device
You need to add two Altera IPs to the project. Please take the following steps:
Step 1: Right-click the File icon (Figure 12-35) and click Add/Remove Files in Project… or, from the
Project menu, select Add/Remove Files in Project.
253
Chapter 12 ■ Light Sensors: Turning a Laser Pointer into a Hi-Tech Tripwire
254
Chapter 12 ■ Light Sensors: Turning a Laser Pointer into a Hi-Tech Tripwire
Step 3: After you have added the adc_pll.qip and cascade_pll.qip files, Figure 12-37 shows all the
files in the correct order. You can use the Up or Down button to move the file order up or down. Please follow
this file order, as it is very important for simulation. The top-level design file (light_sensor_top.vhd) must
be the last one.
Step 4: When all the files are ready, select the light_sensor_top.vhd file as the top-level entity. Right-
click the light_sensor_top.vhd file and select Set as Top-Level Entity.
Step 5: Click the or select Start Compilation from the Processing menu. You should see
Figure 12-38 as your result. In the Task window (lower left), it should have all green checks, a 100% progress
bar, and no red errors in the Message window. At this point, you are ready to upload the design to the MAX10
FPGA.
255