Part 4: the Absence of Light

by richardmedyanto in Circuits > Robots

132 Views, 1 Favorites, 0 Comments

Part 4: the Absence of Light

NLC.png

This instructable is one part of a larger build. Please ensure you start at HDL Motor Speed Control, so you understand where the following fits in within the larger project.

This part will give a detailed information about the module “nolightcounter.vhd”, which activates when no light source is detected by the robot.

Function of this module

The purpose of this module is to dictate what to do when there is little to no light source detected by the robot. This module is triggered by CAHAYA (the size of the light source), and the validity of the inputs (from READY) and will output whether to rotate or stay in place.

When the light-seeking robot detects little to no light, the robot will rotate around in place to look for a source of light in other directions. If the robot has finished rotating for a certain number of seconds, the robot will be instructed to stop moving for another certain number of seconds. After that, the robot will rotate again, stop moving, and so on.

You can look at the code here.

Signals

NLC.png

This module consists of several port signals and internal signals:

Port Signals:

Input:

  1. RST (Asynchronous reset)
  2. CLK (or VSYNC from camera, 62.5 Hz)
  3. CAHAYA (the size of the light source, 10 bits)
  4. NLC_EN (READY from Thresholding)

Output:

  1. ROTATE (to tell the robot when to rotate and when to stop moving.)

Internal Signals:

  1. ticks (for counting the time duration of each state, 10 bits)
  2. count_en (to know when to count)

Size Comparator and AND Gate

NLC_PT1.png

When CAHAYA is less than 100 pixels, the comparator will output 1. Other than that, the comparator will output 0.

NLC_EN is a signal that shows the validity of the inputs, also known as READY. When it is 0, it means the values of SIZE and POSITION are invalid, since the camera could still be in the initializing process.

Together, these 2 inputs will be entered into an AND gate. The output will decide whether to start counting or not.

The Counter and Comparator

NLC_PT2.png

When the AND gate decides to start counting (COUNT_EN = 1), the counter will start counting.

The counter will start counting from 0, and will increment by 1 every rising edge of the clock (which comes from VSYNC). When ticks (the signal used for counting) is less than 313, the comparator will output 1. When ticks is 313 or above, the comparator will output 0.

The range from ticks = 0 to 312 is 313 ticks, and since VSYNC is a 62.5 Hz clock, the duration calculates to about 5 seconds (313 ticks / 62.5 Hz = 5 seconds). After that, the counter will continue counting from 313 to 1023, which range is 710 ticks, so the duration is 11,36 seconds. Note: 1023 + 1 in 10 bits binary calculation is 0, so the counter will keep looping until stopped.

The value of ticks can be reset to 0:

  • asynchronously by the input RST, or
  • synchronously by changing COUNT_EN to 0

The OR Gate

NLC_PT3.png

When COUNT_EN is 0, the inverse is 1, so the OR gate will output 1.

When ticks is less than 313, the output of the comparator will be 1, so the OR gate will also output 1.

If COUNT_EN is 1 (which means the counter is counting), the inverse is 0, and if the value of ticks is equal to or more than 313, the output of the comparator will be 0, and the OR gate will output 0.

The Code

NLC_TB.png

If you want to learn more about how we translate this module into the VHDL code, you can take a look at the code here. We have also included the explanation on the code using comments.

The picture above shows the desired output of ROTATE. ROTATE will output 1 for 5 seconds, and will output 0 for around 11.36 seconds, and will loop if light is still not detected.

If you want to test the code, you can use the testbench file we provided below, using ISE Design Suite 14.7 app under "simulation". Remember to change the file extension to .vhd.

Downloads