Published using Google Docs
Time Based Clap Pattern Lock (Legacy Documentation)
Updated automatically every 5 minutes

Time Based Clap Pattern Lock

Course Code: CPE016

Program: Computer Engineering

Course Title: Introduction to HDL

Date Performed: 10/11/2020

Section: CPE31S1

Date Submitted: 10/16/2020

Leader:      1. Licas, Janrey T.

Instructor: Engr. Menchie Miranda-Rosales

Members:  2. Imperial, Justine O.

                   3. Jantoc, Janos

                   4. Langaoan, Ronald

  1. Objective(s):

The activity aims to create a Clap Lock that the clap activates (on/reset) the state machine and to demonstrate how to run and simulate the transition from one state to the next at the clap until 7 counts in ModelSim.

  1. Intended Learning Outcomes (ILOs):

The students shall be able to:

  1. Create a clap lock system...
  2. Use port mapping in separating both test bench and module files for efficiency.
  3. Use clocked logic within the program for automation.
  4. Use situational statements properly to run and execute the project successfully.
  1. Discussion:

        This technology has become one of the important and necessary components in our daily life to accomplish our task. People have worked together cooperatively so that they come out with the solutions for certain problems and produce innovations. About this project If a particular pattern of claps is detected, only then the lock will open. For this we are using a sound sensor module. In normal state, the sensor gives HIGH. As soon as a clap is detected, it gives LOW.

  1.  Resources:

Computer System with internet access

Software:

    Model Sim Installer capacity is 345MB while it needs 400MB space memory to your OS drive

    Visual Studio Code
   Video Editor
   Microsoft Word

  1. Procedure:
  1. Open your modelsim. Click Jumpstart > Create a project and name you project as “ClapLockSystem” and hit ok.


Figure 1.1 Creating a Project

  1. After creating the project, you should click “Create New File” on the pop up screen. Type “CL_VHDL_CMPNT” as the Filename for the VHDL File and hit ok. Add a new file again for the test bench and name it as “CL_TESTBENCH”.

For Module File


Figure 1.2 Creating project file for module

For Test Bench File


Figure 1.3 Creating a project file for test bench

  1. Open the created file, and then copy and paste the following codes to your model sim. Be sure to have the right file names in order to compile and run the simulations without errors.

VHDL Code File Name for CL_VHDL_CMPNT - Module File

  1. LIBRARY IEEE;  
  2. USE IEEE.std_logic_1164.ALL;  
  3.  
  4. ENTITY CLAP_LOCK_VHDL IS  
  5.     GENERIC (  
  6.         CLAP_CNT_TO_LCK_PH : INTEGER := 0; -- Clap Count To Locking Phase.  
  7.         CLAP_MIN_LEN_PW : INTEGER := 0; -- Minimum Clap Length Password Pattern  
  8.         CLAP_MAX_LEN_PW : INTEGER := 0; -- Maximum Clap Length Password Pattern  
  9.         CLAP_SLOT_INTERVAL_TO_LOCK : TIME := 1 SEC; -- Clap Slot Interval To Verify.  
  10.         CLAP_WIDTH : INTEGER := 0 -- Clap Length, 1st Index Based! Code will handle it to zero-based.  
  11.         -- Keep in mind that CLAP_MIN_LEN_PW and CLAP_MAX_LEN_PW respects CLAP_WIDTH legnth!  
  12.     );  
  13.  
  14.     PORT (  
  15.         -- Clap Signals Integer State Signals  
  16.         -- More information about these soon because it was looking redundant here.  
  17.         CL_PW_VECTOR_STATE_CODE : OUT INTEGER RANGE 0 TO 2 := 0;  
  18.         CL_PW_CLR_STATE_CODE : OUT INTEGER RANGE 0 TO 5 := 0;  
  19.         CL_PW_STORE_DCT_STATE_CODE : OUT INTEGER RANGE 0 TO 5 := 0;  
  20.         CL_POST_STATE_CODE : OUT INTEGER RANGE 0 TO 1 := 1;  
  21.         CL_TO_UNLCK_LSTN_STATE_CODE : OUT INTEGER RANGE 0 TO 4 := 0;  
  22.         CL_TO_LCK_LSTN_STATE_CODE : OUT INTEGER RANGE 0 TO 3 := 0;  
  23.         BTN_RST_SEQUENCER, BTN_DISCARD_CURR_SEQ : IN STD_LOGIC := '0';  
  24.  
  25.         -- These CL displays were divided due to One Process, One Signal Drive!  
  26.         -- Keep in mind that, the use of Zero-Index is applied here.  
  27.         -- This means that instead providing of 5 DOWNTO 0 for a Size of 5.  
  28.         -- It was done to 4 DOWNTO 0.  
  29.  
  30.         -- Clap Signals Readable State Contexts  
  31.         CL_PW_VECTOR_STATE_DISP : OUT STRING (1 TO 3) := "RDY";  
  32.         CL_PW_CLR_STATE_DISP : OUT STRING (1 TO 3) := "RDY";  
  33.         CL_PW_STORE_DCT_DISP : OUT STRING (1 TO 3) := "RDY";  
  34.         CL_POST_STATE_DISP : OUT STRING (1 TO 3) := "LKD";  
  35.         CL_TO_UNLCK_LSTN_STATE_DISP : OUT STRING (1 TO 3) := "RDY";  
  36.         CL_TO_LCK_LSTN_STATE_DISP : OUT STRING (1 TO 3) := "RDY";  
  37.  
  38.         -- User Input and LED Indicator of Listening Mode.  
  39.         CL_MIC_DTCTR : IN STD_LOGIC := '0'; -- MIC that detects clap.  
  40.         LED_LSTN_MODE : IN STD_LOGIC := '0'; -- Listening Mode Indicator  
  41.         -- Runtime Indicators.  
  42.         -- CL_RT_CLK : IN INTEGER RANGE 0 TO CLAP_WIDTH; -- + 2 because, on + 1, becauase of WHILE Compensation.  
  43.         LED_SEC_BLINK_DISP : IN STD_LOGIC := '0'; -- Time Second Rising Edge Indicator.  
  44.         -- Clap Slots (Specifically for Unlocked to Lock Mechanism)  
  45.         CL_TO_LCK_CLAP_SLTS : OUT STD_LOGIC_VECTOR (CLAP_CNT_TO_LCK_PH DOWNTO 0) := (OTHERS => '0'); -- Clap Slots for Locking Phase.  
  46.         -- Password Storages  
  47.         PW_PTRN_RT : IN STD_LOGIC_VECTOR (CLAP_WIDTH DOWNTO 0) := (OTHERS => '0'); -- Runtime Storage  
  48.         PW_PTRN_ST : OUT STD_LOGIC_VECTOR (CLAP_WIDTH DOWNTO 0) := (OTHERS => '0') -- Last Known Storage  
  49.     );  
  50.  
  51. END CLAP_LOCK_VHDL;  
  52.  
  53. ARCHITECTURE CL_DIGITAL_SIM OF CLAP_LOCK_VHDL IS  
  54. BEGIN  
  55.     -- Internal Component Processor #1 — Password Vector Bit Detection (Initial / Startup) (No Interrupts)  
  56.     -- Password Detection for Malform or Non-Malformed or No Password.  
  57.     -- Description    : Checks if the password container contains data or else restrict the system to do anything  
  58.     --                  unless the user sets a password to allow Locking and Unlocking Capabilities.  
  59.  
  60.     -- Notes:  
  61.     --  1. This process can be executed in the beginning so, there's no wait for other signals that are essential in the whole operation.  
  62.     --  2. This process only alters CL_PW_VECTOR_STATE_CODE and other processors depend on it.  
  63.     --  3. This processor has a WAIT statement for PW_PTRN_RT and PW_PTRN_ST.  
  64.     --  4. This process will only run ONE TIME. It is a startup process that checks for the input.  
  65.     --  5. It has a delay to compensate for the initialization of the device.  
  66.     --  6. Once it resolves things over time, it will wait until PW_PTRN_ST has been changed.  
  67.  
  68.     PROCESS IS  
  69.         VARIABLE HAS_NO_PASSWORD : BOOLEAN := FALSE;  
  70.         VARIABLE PW_CLAP_COUNT_HANDLER : INTEGER := 0;  
  71.         VARIABLE INIT_FLAG : BOOLEAN := TRUE;  
  72.         VARIABLE ON_BIT_COUNT : INTEGER := 0;  
  73.     BEGIN  
  74.         -- Pre-requisites:  
  75.         -- It waits until :  
  76.  
  77.         -- On initialization, we run this process.  
  78.         -- After triggering this process, it has to wait for PW_PTRN_ST to change before running it again.  
  79.  
  80.         -- Pre Initialization, Checking of Constraint of Claps Width.  
  81.         -- Checks if CLAP_MIN_LEN_PW and CLAP_MAX_LEN_PW respects CLAP_WIDTH.  
  82.         -- CLAP_MIN_LEN_PW and CLAP_MAX_LEN_PW can have the same value as long as it was not conflicting.  
  83.         -- The use of negative sign is not allowed here!  
  84.  
  85.         IF INIT_FLAG = TRUE THEN  
  86.             IF CLAP_MIN_LEN_PW < 0 THEN  
  87.                 REPORT "Initialization Processor #1 | Minimum Allowed Claps is out of bounds of acceptable range. (Range should be 0 to Positive Number.)" SEVERITY FAILURE;  
  88.                 WAIT;  
  89.             END IF;  
  90.  
  91.             IF CLAP_MAX_LEN_PW < 0 THEN  
  92.                 REPORT "Initialization Processor #1 | Maximum Allowed Claps is out of bounds! (Range should be 0 to Positive Number.)" SEVERITY FAILURE;  
  93.                 WAIT;  
  94.             END IF;  
  95.  
  96.             IF CLAP_MIN_LEN_PW > CLAP_MAX_LEN_PW THEN  
  97.                 REPORT "Initialization Processor #1 | Minimum Allowed Claps is expected to be lower than CLAP_MAX_LEN_PW! Please check your value assignment before port instantiation!" SEVERITY FAILURE;  
  98.                 WAIT;  
  99.             END IF;  
  100.  
  101.             IF CLAP_MIN_LEN_PW > CLAP_WIDTH THEN  
  102.                 REPORT "Initialization Processor #1 | Minimum Allowed Claps weren't respecting the value of CLAP_WIDTH. Please check your value assignment before port instantiation!" SEVERITY FAILURE;  
  103.                 WAIT;  
  104.             END IF;  
  105.  
  106.             IF CLAP_MAX_LEN_PW > CLAP_WIDTH THEN  
  107.                 REPORT "Initialization Processor #1 | Maximum Allowed Claps weren't respecting the value of CLAP_WIDTH. Please check your value assignment before port instantiation!" SEVERITY FAILURE;  
  108.                 WAIT;  
  109.             END IF;  
  110.  
  111.             WAIT FOR 250 MS;  
  112.             REPORT "Processor #1 | Initialization Started, setting it to False.";  
  113.             INIT_FLAG := FALSE;  
  114.         ELSE  
  115.             REPORT "Processor #1 | After Initialization Phase, On Wait For Next Changes.";  
  116.             WAIT ON PW_PTRN_ST; -- Wait for changes.  
  117.             REPORT "Processor #1 | Changes on Password Pattern Storage Detected!";  
  118.  
  119.         END IF;  
  120.  
  121.         -- There will be two loops for initialization!  
  122.  
  123.         -- Checks the container if is malformed or has no password.  
  124.         -- We don't wanna check by statically declaring a bits of zeros since the width is dynamic.  
  125.         FOR EACH_PW_INDEX IN 0 TO CLAP_WIDTH - 1 LOOP  
  126.             IF PW_PTRN_ST(EACH_PW_INDEX) = '1' THEN  
  127.                 ON_BIT_COUNT := ON_BIT_COUNT + 1;  
  128.             END IF;  
  129.         END LOOP;  
  130.  
  131.         HAS_NO_PASSWORD := TRUE WHEN ON_BIT_COUNT = 0 ELSE  
  132.             FALSE;  
  133.  
  134.         ON_BIT_COUNT := 0;  
  135.  
  136.         IF HAS_NO_PASSWORD THEN  
  137.             CL_PW_VECTOR_STATE_CODE <= 1; --NPW, Sets to No Password State.  
  138.             REPORT "Processor #1 | The system detects no password. Set to NPW state and waiting for resolve.";  
  139.  
  140.             -- We wait until it has been resolved.  
  141.             WAIT UNTIL CL_PW_STORE_DCT_STATE_CODE = 4;  
  142.             CL_PW_VECTOR_STATE_CODE <= 0;  
  143.             HAS_NO_PASSWORD := FALSE;  
  144.             REPORT "Processor #1 | The system has a password because of state CL_PW_VECTOR_STATE_CODE to 4. Issue Resolved. Ready to Unlock.";  
  145.  
  146.         ELSE  
  147.  
  148.             -- If it has a password, then check for the password if malformed.  
  149.             -- If we assumed that the data is retained on initialization then we could check.  
  150.  
  151.             FOR PW_INDEX_ITERATION IN 0 TO CLAP_WIDTH LOOP  
  152.                 IF PW_PTRN_ST(PW_INDEX_ITERATION) = '1' THEN  
  153.                     PW_CLAP_COUNT_HANDLER := PW_CLAP_COUNT_HANDLER + 1;  
  154.                 ELSE  
  155.                     NEXT;  
  156.                 END IF;  
  157.             END LOOP;  
  158.  
  159.             -- After checking if the length respects CLAP_MIN_LEN_PW and CLAP_MAX_LEN_PW.  
  160.             -- It will determines if it was malformed, if it is, then a reset to the password is needed.  
  161.  
  162.             IF PW_CLAP_COUNT_HANDLER >= CLAP_MIN_LEN_PW AND PW_CLAP_COUNT_HANDLER <= CLAP_MAX_LEN_PW THEN  
  163.                 REPORT "Processor #1 | All Clear.";  
  164.                 CL_PW_VECTOR_STATE_CODE <= 0; -- RDY, All Clear.  
  165.             ELSE  
  166.                 REPORT "Processor #1 | The system detects that the Password is Malformed, Resetting Password in 1 Second.";  
  167.                 CL_PW_VECTOR_STATE_CODE <= 2; -- MPW  
  168.  
  169.                 WAIT FOR 250 MS;  
  170.  
  171.                 WAIT ON PW_PTRN_ST; -- Assumes that it will reset!  
  172.  
  173.                 -- In the testbench, you have to clear the password there!  
  174.                 -- A seperate process might be nice. But, let's see if that is gonna work.  
  175.  
  176.                 -- FOR EACH_INDEX IN 0 TO CLAP_WIDTH LOOP  
  177.                 --     PW_PTRN_ST(EACH_INDEX) <= '0';  
  178.                 -- END LOOP;  
  179.  
  180.                 CL_PW_VECTOR_STATE_CODE <= 1;  
  181.                 REPORT "Processor #1 | Password has been reset.";  
  182.  
  183.             END IF;  
  184.             PW_CLAP_COUNT_HANDLER := 0;  
  185.         END IF;  
  186.         WAIT;  
  187.  
  188.     END PROCESS;  
  189.  
  190.     -- Internal Component Processor #2 — Realtime Clock of Runtime Clap Processor (Has Interrupts)  
  191.     -- Input for Unlocking.  
  192.     -- Description    : Runs everytime when a clap was heard for the first time.  
  193.     --                  It does not record the first clap as a zero index of PW_PTRN_RT.  
  194.     --  
  195.     -- Notes:  
  196.     --  1.  This does not run under Unlock To Lock Phase since it has different constraints  
  197.     --      and different parameters to take. I cannot optimize this mechanism into one  
  198.     --      functionality due to nature of VHDL Programming. (This means of not being able to apply DRY Principles.)  
  199.     --  2.  This does not handle the Clap Input (Microphone) but rather iterates through time!  
  200.     --      The testbench should handle the inputs.  
  201.     --  3.  This function only handles interrupts over time that the Testbench cannot handle. (except sending signals ofc.)  
  202.  
  203.     PROCESS IS  
  204.         VARIABLE IS_SEQ_ITER_INTERRUPTED : BOOLEAN := FALSE; -- Boolean for Sequence Iteration Interrupted.  
  205.     BEGIN  
  206.  
  207.         -- Pre-requisites  
  208.         -- It waits until :  
  209.         WAIT UNTIL LED_LSTN_MODE = '1'; -- 1.2. With LED being turned on as well.  
  210.         -- 2. Password State Phase is on State 'Ready'.  
  211.         -- 3. Post State of the System Indicates the Lock was in Locked Mode.  
  212.         -- 4. Listen Phase was Prematurely on Ready State Before Shifting to LTC Mode.  
  213.         -- 5. Unlock To Lock Phase State should still be in RDY State.  
  214.         -- 6. Password Storage Malform Detection should be in OKY State.  
  215.         -- 7. No Password To Password Detection should be in RDY State.  
  216.  
  217.         IF CL_PW_CLR_STATE_CODE = 0 AND CL_POST_STATE_CODE = 1 AND CL_TO_UNLCK_LSTN_STATE_CODE = 0 AND CL_TO_LCK_LSTN_STATE_CODE = 0 AND CL_PW_VECTOR_STATE_CODE = 0 AND CL_PW_STORE_DCT_STATE_CODE = 0 THEN  
  218.             REPORT "Processor #2 | Realtime Clock of Runtime Clap Processor Process Triggered.";  
  219.  
  220.             WHILE (CL_POST_STATE_CODE /= 0) LOOP  
  221.                 -- Set Listen Phase Status to Listen Mode.  
  222.                 CL_TO_UNLCK_LSTN_STATE_CODE <= 1; -- LTC  
  223.                 -- Run the Iteration in Seconds delay.  
  224.                 FOR RUNTIME_CNT_SEC IN 0 TO CLAP_WIDTH LOOP  
  225.                     -- Wait for 1 Second Here To Compensate with 0 Second shifting to 1 Second.  
  226.                     WAIT FOR 1 SEC;  
  227.  
  228.                     -- Checks with Excemption for CL_MIC_DTCTR. Because user could skip certain seconds for pattern.  
  229.                     IF (BTN_DISCARD_CURR_SEQ = '0' AND LED_LSTN_MODE = '1') THEN  
  230.                         IS_SEQ_ITER_INTERRUPTED := FALSE;  
  231.  
  232.                     ELSE  
  233.                         -- Reset the Whole System State to Locked Mode.  
  234.                         -- Set Sequence Iteration Interrupted and Iterate Runtimes to Zero.  
  235.                         IS_SEQ_ITER_INTERRUPTED := TRUE;  
  236.                         EXIT;  
  237.  
  238.                     END IF;  
  239.                 END LOOP;  
  240.  
  241.                 IF IS_SEQ_ITER_INTERRUPTED THEN  
  242.                     REPORT "Processor #2 | Process Interrupted due to Button Push.";  
  243.                     CL_TO_UNLCK_LSTN_STATE_CODE <= 3; -- IPR  
  244.                 ELSE  
  245.                     REPORT "Processor #2 | Process On Password Validation.";  
  246.                     CL_TO_UNLCK_LSTN_STATE_CODE <= 2; -- PWV  
  247.                 END IF;  
  248.  
  249.                 WAIT FOR 500 MS;  
  250.  
  251.                 IF CL_POST_STATE_CODE = 0 THEN  
  252.                     CL_TO_UNLCK_LSTN_STATE_CODE <= 0;  
  253.                     EXIT;  
  254.                 ELSE  
  255.                     NEXT;  
  256.                 END IF;  
  257.  
  258.                 IS_SEQ_ITER_INTERRUPTED := FALSE; -- Check if it resets.  
  259.                 REPORT "Processor #2 | Realtime Clock of Runtime Clap Processor Process is Finished.";  
  260.             END LOOP;  
  261.         END IF;  
  262.     END PROCESS;  
  263.  
  264.     -- Internal Component Processor #3 — Password Validation to Unlock or Retained State Phase Mechanism (No Interrupts) (Multi-Usage)  
  265.     -- Password Verifier to Unlock.  
  266.     -- Description    : Checks for Password Everytime CL_TO_UNLCK_LSTN_STATE_DISP has a value of 2 which is Password Checking Mode.  
  267.     --  
  268.     -- Notes:  
  269.     --  1.  This process assumes that the PW_PTRN_ST contains Vectored Password Pattern!  
  270.     --      It does not check it because we have a signal that displays if the state of the lock has a password.  
  271.     --  2. This is where the comparison happens between PW_PTRN_RT and PW_PTRN_ST.  
  272.     --  3. This function only change the state of the lock, it does not however change other signals.  
  273.     --  4. This function can be used by Unlocked to Locked Mechanism but the implementation will be different.  
  274.     --  5. This function also doesn't care about your Microphone turned on (along with LED) because it has nothing to do with it.  
  275.     -- 1. CL_TO_UNLCK_LSTN_STATE_CODE should be under PWV State.  
  276.     -- 2. CL_TO_LCK_LSTN_STATE_CODE should be under VTL State.  
  277.     --  
  278.     -- These two pre-requisites shouldn't conflict on '1' Value as they should be unique on multiple occasions.  
  279.  
  280.     PROCESS IS  
  281.     BEGIN  
  282.         WAIT ON CL_TO_UNLCK_LSTN_STATE_CODE, CL_TO_LCK_LSTN_STATE_CODE;  
  283.  
  284.         -- Two Signals on Wait Statement shouldn't have the same value!  
  285.         -- They should contain distinct values with another other to trigger certain signal modifications.  
  286.         -- Result of Conflict from Conditionals will only REPORT Not-So-Error Message. (See ELSE Clause Part.)  
  287.  
  288.         IF CL_TO_UNLCK_LSTN_STATE_CODE = 2 AND CL_TO_LCK_LSTN_STATE_CODE = 0 THEN  
  289.             REPORT "Processor #3 | Validating Password...";  
  290.             IF PW_PTRN_RT = PW_PTRN_ST THEN  
  291.                 CL_POST_STATE_CODE <= 0;  
  292.                 REPORT "Processor #3 | The Lock is now in Unlocked State.";  
  293.             ELSE  
  294.                 CL_POST_STATE_CODE <= 1;  
  295.                 REPORT "Processor #3 | The Lock is now in Locked State.";  
  296.             END IF;  
  297.         ELSIF CL_TO_LCK_LSTN_STATE_CODE = 2 AND CL_TO_UNLCK_LSTN_STATE_CODE = 0 THEN  
  298.             CL_POST_STATE_CODE <= 1;  
  299.             REPORT "Processor #3 | The Lock is in Locked State caused by Unlock To Lock.";  
  300.  
  301.         END IF;  
  302.     END PROCESS;  
  303.  
  304.     -- Internal Component Processor #4 — Runtime Unlock to Lock Phase Processor (No Interrupts)  
  305.     -- Input for Locking.  
  306.     -- Description    : Runs only when CL_POST_STATE_CODE is in 'ULK' state.  
  307.     --                  It does not record the first clap as a first index of PW_PTRN_RT.  
  308.     --  
  309.     -- Notes:  
  310.     --  1.  This does not run under Unlock To Lock Phase since it has different constraints  
  311.     --      and different parameters to take. I cannot optimize this mechanism into one  
  312.     --      functionality due to nature of VHDL Programming. (This means of not being able to apply DRY Principles.)  
  313.     --  2.  This process checks for the claps in a short amount of time! As it only takes a # of claps to Lock the Vault Back.  
  314.  
  315.     PROCESS IS  
  316.         VARIABLE CLAP_SLOT_ITER : INTEGER := 0;  
  317.         VARIABLE VERIFIED_TO_LCK_PH : BOOLEAN := TRUE;  
  318.     BEGIN  
  319.  
  320.         -- Pre-requisites  
  321.         -- It waits until :  
  322.         WAIT ON CL_POST_STATE_CODE; -- 1.2. With LED being turned on as well.  
  323.  
  324.         IF CL_POST_STATE_CODE = 0 THEN  
  325.             CL_TO_LCK_LSTN_STATE_CODE <= 1;  
  326.         ELSE  
  327.             WAIT FOR 1 SEC;  
  328.             CL_TO_LCK_LSTN_STATE_CODE <= 0;  
  329.  
  330.         END IF;  
  331.         WAIT FOR 500 MS;  
  332.         IF CL_PW_CLR_STATE_CODE = 0 AND CL_POST_STATE_CODE = 0 AND CL_TO_UNLCK_LSTN_STATE_CODE = 2 AND CL_TO_LCK_LSTN_STATE_CODE = 1 AND CL_PW_VECTOR_STATE_CODE = 0 AND CL_PW_STORE_DCT_STATE_CODE = 0 THEN  
  333.             -- Once a clap was heard, register the first clap so that we won''t be getting delays.  
  334.             -- Increment the index from zeroth to first index.  
  335.             CL_TO_LCK_LSTN_STATE_CODE <= 1;  
  336.             CL_TO_LCK_CLAP_SLTS(0) <= CL_MIC_DTCTR;  
  337.             CLAP_SLOT_ITER := CLAP_SLOT_ITER + 1;  
  338.  
  339.             REPORT "Processor #4 | Set First Clap in Zero-th Index of CL_TO_LCK_CLAP_SLTS";  
  340.  
  341.             -- Iterate the remaining claps required before processing to Locked Mode.  
  342.             -- The remaining clap slots will iterate even when not detecting the claps.  
  343.             -- This means that the system will disgard it if the clap under constraint intervals did not meet.  
  344.  
  345.             -- This part of the process DOES NOT manipulate the input. Testbench process is required.  
  346.             WHILE (CL_TO_LCK_LSTN_STATE_CODE /= 2) LOOP  
  347.                 WHILE (CLAP_SLOT_ITER < CLAP_CNT_TO_LCK_PH) LOOP  
  348.                     WAIT FOR CLAP_SLOT_INTERVAL_TO_LOCK; -- Wait for certain MS or whatever the constraint is before checking for the detection of claps.  
  349.                     -- CL_RT_CLK <= CL_RT_CLK + 1;  
  350.                     CL_TO_LCK_CLAP_SLTS(CLAP_SLOT_ITER) <= CL_MIC_DTCTR;  
  351.                     CLAP_SLOT_ITER := CLAP_SLOT_ITER + 1;  
  352.                     REPORT "Processor #4 | Clap Slot " & INTEGER'image(CLAP_SLOT_ITER) & " out of " & INTEGER'image(CLAP_CNT_TO_LCK_PH) & " | Value is " & STD_LOGIC'image(CL_MIC_DTCTR);  
  353.                 END LOOP;  
  354.  
  355.                 CLAP_SLOT_ITER := 0;  
  356.  
  357.                 REPORT "Processor #4 | Iteration To Clap Finished.";  
  358.  
  359.                 -- CL_RT_CLK <= 0;  
  360.                 WAIT FOR 250 MS;  
  361.                 -- Verify if the Claps contains all ones.  
  362.                 -- Or else, dismiss the request of Locking Phase.  
  363.  
  364.                 FOR eachClapsSlots IN 0 TO CLAP_CNT_TO_LCK_PH - 1 LOOP  
  365.                     REPORT "Processor #4 | Bit Checking | (" & INTEGER'image(eachClapsSlots) & " out of " & INTEGER'image(CLAP_CNT_TO_LCK_PH - 1) & ") | Value is " & STD_LOGIC'image(CL_TO_LCK_CLAP_SLTS(eachClapsSlots));  
  366.                     IF CL_TO_LCK_CLAP_SLTS(eachClapsSlots) = '0' THEN  
  367.                         VERIFIED_TO_LCK_PH := FALSE;  
  368.                         REPORT "Processor #4 | Bit Checking | Invalid to Lock Phase.";  
  369.                         EXIT; -- Breaking the loop here.  
  370.                     END IF;  
  371.                 END LOOP;  
  372.  
  373.                 IF VERIFIED_TO_LCK_PH THEN  
  374.                     -- Reset the Runtime Password Pattern Storage HERE!  
  375.                     -- Reset everything when returning to Locking State.  
  376.                     CL_TO_LCK_LSTN_STATE_CODE <= 2; -- VTL  
  377.                     REPORT "Processor #4 | Claps Verified with Timeframe Correct. Switching to Locked Mode.";  
  378.  
  379.                 ELSE  
  380.                     -- Or else, repeat this process by manipulating the state.  
  381.                     CL_TO_LCK_LSTN_STATE_CODE <= 3; -- Quick Spike before returning to Process Execution of this Process.  
  382.                     REPORT "Processor #4 | Claps Incomplete, Retained Locked Mode.";  
  383.  
  384.                     WAIT FOR 250 MS;  
  385.  
  386.                     -- Wait for 250 MS Before rerunning this process.  
  387.                     CL_TO_LCK_LSTN_STATE_CODE <= 1; -- Quick Spike before returning to Process Execution of this Process.  
  388.                 END IF;  
  389.  
  390.                 -- Cleanup.  
  391.                 FOR eachClapSlots IN 0 TO CLAP_CNT_TO_LCK_PH LOOP  
  392.                     CL_TO_LCK_CLAP_SLTS(eachClapSlots) <= '0';  
  393.                 END LOOP;  
  394.  
  395.                 VERIFIED_TO_LCK_PH := TRUE;  
  396.  
  397.                 WAIT FOR 500 MS;  
  398.             END LOOP;  
  399.         END IF;  
  400.  
  401.         -- Cleanup in Out of Scope of Loop.  
  402.         CL_TO_LCK_LSTN_STATE_CODE <= 0;  
  403.     END PROCESS;  
  404.  
  405.     -- Internal Component Processor #6 — Clap Input to Password Storage (Non-Runtime) (Password Container) (Has Interrupts)  
  406.     -- Password Setter.  
  407.     -- Description    : Inputs password to PW_PTRN_RT and saves to PW_PTRN_ST one-time only.  
  408.  
  409.     -- Notes:  
  410.     --  1. This process depends to Extra 2 - Password Vector Bit Detection. It should be the only one to trigger this process.  
  411.     --  2. Other signals were ignored in this process other than LED_LSTN_MODE and CL_MIC_DTCTR.  
  412.     --  3. This process never checks for PW_PTRN_ST's data as it only overrides it here.  
  413.     --     Extra 2 Password Vector Bit Detection should be the check it.  
  414.  
  415.     -- Pre-requisites:  
  416.     -- It waits until :  
  417.     --  1.  CL_PW_CLR_STATE_CODE turns to 'CPW', Cleared Password State.  
  418.     --  2.  CL_PW_VECTOR_STATE_CODE turns to 'NPW', No Password State.  
  419.     PROCESS IS  
  420.         VARIABLE BIT_ON_COUNTER : INTEGER := 0;  
  421.     BEGIN  
  422.  
  423.         WAIT ON CL_PW_CLR_STATE_CODE, CL_PW_VECTOR_STATE_CODE; -- Waits when it was Cleared for Password.  
  424.  
  425.         IF CL_PW_CLR_STATE_CODE = 5 OR CL_PW_VECTOR_STATE_CODE = 1 OR CL_PW_VECTOR_STATE_CODE = 2 THEN  
  426.  
  427.             -- Set to Ready To Listen and wait for Feedback.  
  428.             REPORT "Processor #6 | State of No Password Or Cleared Password Condition Met. Waiting for Feedback...";  
  429.             -- Waits for Testbench To Trigger Signals Required.  
  430.             WAIT UNTIL LED_LSTN_MODE = '1';  
  431.  
  432.             WHILE (CL_PW_STORE_DCT_STATE_CODE /= 4) LOOP  
  433.                 CL_PW_STORE_DCT_STATE_CODE <= 1;  
  434.                 REPORT "Processor #6 | CL_PW_STORE_DCT_STATE_CODE has been set to Listen to Claps Mode. Iterating...";  
  435.  
  436.                 -- Requires with Respect to Claps of Min and Max.  
  437.                 FOR ITERATION_INDEX IN 0 TO CLAP_WIDTH - 1 LOOP  
  438.                     -- This statement will cancel and wait for the claps again to record it to the storage.  
  439.                     IF BTN_DISCARD_CURR_SEQ = '1' THEN  
  440.                         REPORT "Processor #6 | Process Interrupted. Password to Storage Cancelled.";  
  441.                         CL_PW_STORE_DCT_STATE_CODE <= 3;  
  442.                         EXIT;  
  443.                     ELSE  
  444.                         -- CL_RT_CLK <= CL_RT_CLK + 1;  
  445.                         REPORT "Processor #6 | Iteration " & INTEGER'image(ITERATION_INDEX) & " Finished.";  
  446.                         WAIT FOR 1 SEC;  
  447.                     END IF;  
  448.                 END LOOP;  
  449.                 -- WAIT UNTIL CL_PW_STORE_DCT_STATE_CODE = 2;  
  450.                 -- Once we finish the loop, Store the Password on PW_PTRN_ST.  
  451.                 -- Keep in mind that the testbench will be the one to clear off PW_PTRN_RT!!!  
  452.  
  453.                 IF CL_PW_STORE_DCT_STATE_CODE /= 3 THEN  
  454.                     REPORT "Processor #6 | Checking for CLAP_WIDTH with PW_PTRN_RT (with Respect to CLAP_MIN_LEN_PW and CLAP_MAX_LEN_PW)";  
  455.                     WAIT FOR 10 MS; -- To compensate with the last bit.  
  456.  
  457.                     FOR EACH_BIT_IDX IN 0 TO CLAP_WIDTH LOOP  
  458.                         IF PW_PTRN_RT(EACH_BIT_IDX) = '1' THEN  
  459.                             BIT_ON_COUNTER := BIT_ON_COUNTER + 1;  
  460.                         END IF;  
  461.  
  462.                     END LOOP;  
  463.  
  464.                     IF BTN_DISCARD_CURR_SEQ /= '1' AND BIT_ON_COUNTER >= CLAP_MIN_LEN_PW AND BIT_ON_COUNTER <= CLAP_MAX_LEN_PW THEN  
  465.  
  466.                         CL_PW_STORE_DCT_STATE_CODE <= 4;  
  467.                         REPORT "Processor #6 | Signal Sent to Save the Password.";  
  468.                         WAIT FOR 250 MS;  
  469.                         CL_PW_STORE_DCT_STATE_CODE <= 0;  
  470.                         EXIT;  
  471.                     ELSE  
  472.                         IF BTN_DISCARD_CURR_SEQ = '1' THEN  
  473.                             REPORT "Processor #6 | Password Input has been interrupted.";  
  474.                             CL_PW_STORE_DCT_STATE_CODE <= 3; -- No need of process to handle PW_PTRN_RT.  
  475.                             WAIT FOR 1 SEC; -- Gives Compensation so that the user has the chance latch it away to avoid infinite loop.  
  476.                             -- Reset States.  
  477.                             BIT_ON_COUNTER := 0;  
  478.                             CL_PW_STORE_DCT_STATE_CODE <= 1; -- No need of process to handle PW_PTRN_RT.  
  479.                         ELSE  
  480.  
  481.                             REPORT "Processor #6 | Password Input were not allowed because its not respecting CLAP_MIN_LEN_PW and CLAP_MAX_LEN_PW Constraints. (" & INTEGER'image(BIT_ON_COUNTER) & ")";  
  482.                             CL_PW_STORE_DCT_STATE_CODE <= 5; -- No need of process to handle PW_PTRN_RT.  
  483.                             WAIT FOR 250 MS;  
  484.                             -- Reset States.  
  485.                             BIT_ON_COUNTER := 0;  
  486.  
  487.                             CL_PW_STORE_DCT_STATE_CODE <= 1; -- No need of process to handle PW_PTRN_RT.  
  488.                         END IF;  
  489.                     END IF;  
  490.                 ELSE  
  491.                     NEXT; -- This assume that the value of CL_PW_STORE_DCT_STATE_CODE is 3!  
  492.                 END IF;  
  493.                 WAIT FOR 250 MS;  
  494.                 CL_PW_STORE_DCT_STATE_CODE <= 0; -- No need of process to handle PW_PTRN_RT.  
  495.                 -- REPORT "Setting Values Back To Normal Mode.";  
  496.             END LOOP;  
  497.             -- ELSE  
  498.             --     REPORT "Processor #6 | Possible Conflict of Condition Signals. (CL_PW_CLR_STATE_CODE,CL_PW_VECTOR_STATE_CODE) = " & INTEGER'image(CL_PW_CLR_STATE_CODE) & ", " & INTEGER'image(CL_PW_VECTOR_STATE_CODE);  
  499.         END IF;  
  500.     END PROCESS;  
  501.  
  502.     -- Internal Component Processor #7 — Password Reset Functionality  
  503.     -- Password Modification to PW_PTRN_ST has been found on two processes.  
  504.     -- It's to play under each processes state and do modifications.  
  505.  
  506.     PROCESS IS  
  507.         VARIABLE PW_STORED_STATE : BOOLEAN := FALSE;  
  508.         VARIABLE PW_RESET_STATE : BOOLEAN := FALSE;  
  509.     BEGIN  
  510.         -- For Scenario only when user has already set a password and just wants to lock the vault.  
  511.         -- PW_PTRN_ST(1) <= '1';  
  512.         -- PW_PTRN_ST(3) <= '1';  
  513.         -- PW_PTRN_ST(5) <= '1';  
  514.  
  515.         WAIT ON CL_PW_VECTOR_STATE_CODE, CL_PW_CLR_STATE_CODE, CL_PW_STORE_DCT_STATE_CODE;  
  516.  
  517.         -- REPORT INTEGER'image(CL_PW_VECTOR_STATE_CODE) & INTEGER'image(CL_PW_CLR_STATE_CODE) & INTEGER'image(CL_PW_STORE_DCT_STATE_CODE);  
  518.         -- Has issues when it has malformed and can't reset.  
  519.         IF (CL_PW_VECTOR_STATE_CODE = 2 OR CL_PW_CLR_STATE_CODE = 5) AND CL_PW_STORE_DCT_STATE_CODE = 0 AND PW_RESET_STATE = FALSE THEN  
  520.             PW_STORED_STATE := TRUE;  
  521.             PW_RESET_STATE := FALSE;  
  522.             PW_PTRN_ST <= "00000000";  
  523.             FOR EACH_PW_INDEX IN 0 TO CLAP_WIDTH LOOP  
  524.                 PW_PTRN_ST(EACH_PW_INDEX) <= '0';  
  525.                 REPORT STD_LOGIC'image(PW_PTRN_ST(EACH_PW_INDEX));  
  526.             END LOOP;  
  527.             -- PW_PTRN_ST <= PW_PTRN_RT;  
  528.             REPORT "Processor #7 | Storage Password was Reset to Default (All Zeros).";  
  529.  
  530.             -- Unclear.  
  531.         ELSIF CL_PW_STORE_DCT_STATE_CODE = 4 AND (CL_PW_VECTOR_STATE_CODE = 0 AND CL_PW_CLR_STATE_CODE = 0) AND PW_STORED_STATE = FALSE THEN  
  532.             PW_PTRN_ST <= PW_PTRN_RT;  
  533.             PW_STORED_STATE := TRUE;  
  534.             PW_RESET_STATE := FALSE;  
  535.             REPORT "Processor #7 | Storage Password was Saved.";  
  536.         END IF;  
  537.     END PROCESS;  
  538.  
  539.     -- Internal Component Processor #8 | Set of Processes Status Code to Interpretable Status Display (Concurrent Overtime) (No Interrupts)  
  540.     -- Set of Process Converter from Status Code to Status Display Abbreviation.  
  541.     -- This is the process that outputs rhe status of the system to a Seven Segment or an LCD Display in Status Abbreviation Form.  
  542.     -- Current List of Known Values for Each Processes.  
  543.  
  544.     --      Pre-State of Processes, Before Setting Post-State of Clap Lock. (CL_XX_XX_[...])  
  545.     --          0. CL_XX_XX_.._DISP <= 'RDY'; -- Ready. -- Shared Across Except CL_PW_VECTOR_STATE_CODE.  
  546.  
  547.     --      Password Vector Bit Shift Detection State + 1 (CL_PW_VECTOR_STATE_CODE)  
  548.     --          0. CL_PW_VECTOR_STATE_DISP <= 'OKY'; -- No Errors.  
  549.     --          1. CL_PW_VECTOR_STATE_DISP <= 'NPW'; -- No Password.  
  550.     --          2. CL_PW_VECTOR_STATE_DISP <= 'MPW'; -- Malformed Password. (CLAP_WIDTH doesn't get respected)  
  551.  
  552.     --      No Password To Password Stored Detection State + 1 (CL_PW_STORE_DCT_STATE_CODE)  
  553.     --          1. CL_PW_STORE_DCT_DISP <= 'LTC'; --  Listening To Claps.  
  554.     --          2. CL_PW_STORE_DCT_DISP <= 'PRC'; -- Processing Claps.  
  555.     --          3. CL_PW_STORE_DCT_DISP <= 'IPR'; -- Interrupted Process. — BTN_DISCARD_CURR_SEQ  
  556.     --          4. CL_PW_STORE_DCT_DISP <= 'PWS'; -- Password Stored.  
  557.     --          5. CL_PW_STORE_DCT_DISP <= 'CNM'; -- Constraints Not Met.  
  558.  
  559.     --      Password Clearing Phase + 1 (CL_PW_CLR_STATE_CODE)  
  560.     --          1. CL_PW_CLR_STATE_DISP <= 'IPW'; -- Inputting Password.  
  561.     --          2. CL_PW_CLR_STATE_DISP <= 'CBS'; -- Checking Button Sequence.  
  562.     --          3. CL_PW_CLR_STATE_DISP <= 'CPW'; -- Process Interrupted.  
  563.     --          4. CL_PW_CLR_STATE_DISP <= 'ICP'; -- Invalid To Clear Password.  
  564.     --          5. CL_PW_CLR_STATE_DISP <= 'CLR'; -- Cleared Password.  
  565.  
  566.     --      Post-State of Clap Lock (After Multiple Statement Displays) Default. (CL_POST_STATE_CODE)  
  567.     --          0. CL_POST_STATE_DISP <= 'ULK'; -- Unlocked Mode.  
  568.     --          1. CL_POST_STATE_DISP <= 'LKD'; -- Locked Mode.  
  569.  
  570.     --      Runtime Listening Mode from Lock to Unlock Phase + 1 (CL_TO_UNLCK_LSTN_STATE_CODE)  
  571.     --          1. CL_TO_UNLCK_LSTN_STATE_DISP <= 'LTC'; --  Listening To Claps.  
  572.     --          2. CL_TO_UNLCK_LSTN_STATE_DISP <= 'PWV'; -- Password Validation.  
  573.     --          3. CL_TO_UNLCK_LSTN_STATE_DISP <= 'IPR'; -- Interrupted Process. — BTN_DISCARD_CURR_SEQ  
  574.     --          4. CL_TO_UNLCK_LSTN_STATE_DISP <= 'IPW'; -- Invalid Password.  
  575.  
  576.     --      For Unlock To Lock Phase (CL_TO_LCK_LSTN_STATE_CODE)  
  577.     --          1. CL_TO_LCK_LSTN_STATE_DISP <= 'QLC'; -- Quick Listening Clap Mode.  
  578.     --          2. CL_TO_LCK_LSTN_STATE_DISP <= 'VTL'; -- Invalid To Locking Phase.  
  579.     --          3. CL_TO_LCK_LSTN_STATE_DISP <= 'ITL'; -- Valid To Locking Phase.  
  580.  
  581.     PROCESS (CL_PW_VECTOR_STATE_CODE) IS  
  582.     BEGIN  
  583.         CASE CL_PW_VECTOR_STATE_CODE IS  
  584.             WHEN 0 =>  
  585.                 CL_PW_VECTOR_STATE_DISP <= "OKY";  
  586.             WHEN 1 =>  
  587.                 CL_PW_VECTOR_STATE_DISP <= "NPW";  
  588.             WHEN 2 =>  
  589.                 CL_PW_VECTOR_STATE_DISP <= "MPW";  
  590.             WHEN OTHERS =>  
  591.                 CL_PW_VECTOR_STATE_DISP <= "NKN";  
  592.         END CASE;  
  593.     END PROCESS;  
  594.  
  595.     PROCESS (CL_PW_STORE_DCT_STATE_CODE) IS  
  596.     BEGIN  
  597.         CASE CL_PW_STORE_DCT_STATE_CODE IS  
  598.             WHEN 0 =>  
  599.                 CL_PW_STORE_DCT_DISP <= "RDY";  
  600.             WHEN 1 =>  
  601.                 CL_PW_STORE_DCT_DISP <= "LTC";  
  602.             WHEN 2 =>  
  603.                 CL_PW_STORE_DCT_DISP <= "PRC";  
  604.             WHEN 3 =>  
  605.                 CL_PW_STORE_DCT_DISP <= "IPR";  
  606.             WHEN 4 =>  
  607.                 CL_PW_STORE_DCT_DISP <= "PWS";  
  608.             WHEN 5 =>  
  609.                 CL_PW_STORE_DCT_DISP <= "CNM";  
  610.             WHEN OTHERS =>  
  611.                 CL_PW_STORE_DCT_DISP <= "NKN";  
  612.         END CASE;  
  613.     END PROCESS;  
  614.  
  615.     PROCESS (CL_PW_CLR_STATE_CODE) IS  
  616.     BEGIN  
  617.         CASE CL_PW_CLR_STATE_CODE IS  
  618.             WHEN 0 =>  
  619.                 CL_PW_CLR_STATE_DISP <= "RDY";  
  620.             WHEN 1 =>  
  621.                 CL_PW_CLR_STATE_DISP <= "IPW";  
  622.             WHEN 2 =>  
  623.                 CL_PW_CLR_STATE_DISP <= "CBS";  
  624.             WHEN 3 =>  
  625.                 CL_PW_CLR_STATE_DISP <= "CPW";  
  626.             WHEN 4 =>  
  627.                 CL_PW_CLR_STATE_DISP <= "ICP";  
  628.             WHEN 5 =>  
  629.                 CL_PW_CLR_STATE_DISP <= "CLR";  
  630.             WHEN OTHERS =>  
  631.                 CL_PW_CLR_STATE_DISP <= "NKN";  
  632.         END CASE;  
  633.     END PROCESS;  
  634.  
  635.     PROCESS (CL_POST_STATE_CODE) IS  
  636.     BEGIN  
  637.         CASE CL_POST_STATE_CODE IS  
  638.             WHEN 0 =>  
  639.                 CL_POST_STATE_DISP <= "ULK";  
  640.             WHEN 1 =>  
  641.                 CL_POST_STATE_DISP <= "LKD";  
  642.             WHEN OTHERS =>  
  643.                 CL_POST_STATE_DISP <= "NKN";  
  644.         END CASE;  
  645.     END PROCESS;  
  646.  
  647.     PROCESS (CL_TO_UNLCK_LSTN_STATE_CODE) IS  
  648.     BEGIN  
  649.         CASE CL_TO_UNLCK_LSTN_STATE_CODE IS  
  650.             WHEN 0 =>  
  651.                 CL_TO_UNLCK_LSTN_STATE_DISP <= "RDY";  
  652.             WHEN 1 =>  
  653.                 CL_TO_UNLCK_LSTN_STATE_DISP <= "LTC";  
  654.             WHEN 2 =>  
  655.                 CL_TO_UNLCK_LSTN_STATE_DISP <= "PWV";  
  656.             WHEN 3 =>  
  657.                 CL_TO_UNLCK_LSTN_STATE_DISP <= "IPR";  
  658.             WHEN 4 =>  
  659.                 CL_TO_UNLCK_LSTN_STATE_DISP <= "IPW";  
  660.             WHEN OTHERS =>  
  661.                 CL_TO_UNLCK_LSTN_STATE_DISP <= "NKN";  
  662.         END CASE;  
  663.     END PROCESS;  
  664.  
  665.     PROCESS (CL_TO_LCK_LSTN_STATE_CODE) IS  
  666.     BEGIN  
  667.         CASE CL_TO_LCK_LSTN_STATE_CODE IS  
  668.             WHEN 0 =>  
  669.                 CL_TO_LCK_LSTN_STATE_DISP <= "RDY";  
  670.             WHEN 1 =>  
  671.                 CL_TO_LCK_LSTN_STATE_DISP <= "QLC";  
  672.             WHEN 2 =>  
  673.                 CL_TO_LCK_LSTN_STATE_DISP <= "ITL";  
  674.             WHEN 3 =>  
  675.                 CL_TO_LCK_LSTN_STATE_DISP <= "VTL";  
  676.             WHEN OTHERS =>  
  677.                 CL_TO_LCK_LSTN_STATE_DISP <= "NKN";  
  678.         END CASE;  
  679.     END PROCESS;  
  680. END ARCHITECTURE;  

VHDL Code File Name for CL_TESTBENCH - TestBench File

  1. LIBRARY IEEE;  
  2. USE IEEE.std_logic_1164.ALL;  
  3.  
  4. ENTITY CLAP_LOCK_VHDL_TESTBENCH IS  
  5. END CLAP_LOCK_VHDL_TESTBENCH;  
  6.  
  7. ARCHITECTURE CL_TESTBENCH_SIML OF CLAP_LOCK_VHDL_TESTBENCH IS  
  8.  
  9.     -- Create emitting error here for constant not respecting CLAP_MIN_LEN_PW and CLAP_MAX_LEN_PW to CLAP_WIDTH.  
  10.     CONSTANT CLAP_CNT_TO_LCK_PH : INTEGER := 2;  
  11.     CONSTANT CLAP_MIN_LEN_PW : INTEGER := 3;  
  12.     CONSTANT CLAP_MAX_LEN_PW : INTEGER := 4;  
  13.     CONSTANT CLAP_SLOT_INTERVAL_TO_LOCK : TIME := 400 MS;  
  14.     CONSTANT CLAP_WIDTH : INTEGER := 7;  
  15.  
  16.     SIGNAL CL_PW_VECTOR_STATE_CODE : INTEGER RANGE 0 TO 2 := 0;  
  17.     SIGNAL CL_PW_CLR_STATE_CODE : INTEGER RANGE 0 TO 5 := 0;  
  18.     SIGNAL CL_PW_STORE_DCT_STATE_CODE : INTEGER RANGE 0 TO 5 := 0;  
  19.     SIGNAL CL_POST_STATE_CODE : INTEGER RANGE 0 TO 1 := 1;  
  20.     SIGNAL CL_TO_UNLCK_LSTN_STATE_CODE : INTEGER RANGE 0 TO 4 := 0;  
  21.     SIGNAL CL_TO_LCK_LSTN_STATE_CODE : INTEGER RANGE 0 TO 3 := 0;  
  22.  
  23.     SIGNAL CL_PW_VECTOR_STATE_DISP : STRING (1 TO 3) := "RDY";  
  24.     SIGNAL CL_PW_CLR_STATE_DISP : STRING (1 TO 3) := "RDY";  
  25.     SIGNAL CL_PW_STORE_DCT_DISP : STRING (1 TO 3) := "RDY";  
  26.     SIGNAL CL_POST_STATE_DISP : STRING (1 TO 3) := "CLK";  
  27.     SIGNAL CL_TO_UNLCK_LSTN_STATE_DISP : STRING (1 TO 3) := "RDY";  
  28.     SIGNAL CL_TO_LCK_LSTN_STATE_DISP : STRING (1 TO 3) := "RDY";  
  29.  
  30.     SIGNAL BTN_RST_SEQUENCER, BTN_DISCARD_CURR_SEQ : STD_LOGIC := '0';  
  31.     SIGNAL LED_LSTN_MODE : STD_LOGIC := '0';  
  32.     SIGNAL CL_MIC_DTCTR : STD_LOGIC := '0';  
  33.     SIGNAL LED_SEC_BLINK_DISP : STD_LOGIC := '0';  
  34.     -- SIGNAL CL_RT_CLK : INTEGER RANGE 0 TO CLAP_WIDTH;  
  35.  
  36.     SIGNAL CL_TO_LCK_CLAP_SLTS : STD_LOGIC_VECTOR (CLAP_CNT_TO_LCK_PH DOWNTO 0) := (OTHERS => '0');  
  37.     SIGNAL PW_PTRN_RT : STD_LOGIC_VECTOR (CLAP_WIDTH DOWNTO 0) := (OTHERS => '0');  
  38.     SIGNAL PW_PTRN_ST : STD_LOGIC_VECTOR (CLAP_WIDTH DOWNTO 0) := (OTHERS => '0');  
  39.  
  40. BEGIN  
  41.  
  42.     instClapLockModule : ENTITY work.CLAP_LOCK_VHDL(CL_DIGITAL_SIM)  
  43.         GENERIC MAP(  
  44.             CLAP_CNT_TO_LCK_PH => CLAP_CNT_TO_LCK_PH,  
  45.             CLAP_MIN_LEN_PW => CLAP_MIN_LEN_PW,  
  46.             CLAP_MAX_LEN_PW => CLAP_MAX_LEN_PW,  
  47.             CLAP_SLOT_INTERVAL_TO_LOCK => CLAP_SLOT_INTERVAL_TO_LOCK,  
  48.             CLAP_WIDTH => CLAP_WIDTH  
  49.         )  
  50.         PORT MAP(  
  51.             BTN_RST_SEQUENCER => BTN_RST_SEQUENCER,  
  52.             BTN_DISCARD_CURR_SEQ => BTN_DISCARD_CURR_SEQ,  
  53.  
  54.             CL_MIC_DTCTR => CL_MIC_DTCTR,  
  55.             -- CL_RT_CLK => CL_RT_CLK,  
  56.  
  57.             CL_PW_VECTOR_STATE_DISP => CL_PW_VECTOR_STATE_DISP,  
  58.             CL_PW_CLR_STATE_DISP => CL_PW_CLR_STATE_DISP,  
  59.             CL_PW_STORE_DCT_DISP => CL_PW_STORE_DCT_DISP,  
  60.             CL_POST_STATE_DISP => CL_POST_STATE_DISP,  
  61.             CL_TO_UNLCK_LSTN_STATE_DISP => CL_TO_UNLCK_LSTN_STATE_DISP,  
  62.             CL_TO_LCK_LSTN_STATE_DISP => CL_TO_LCK_LSTN_STATE_DISP,  
  63.             CL_PW_VECTOR_STATE_CODE => CL_PW_VECTOR_STATE_CODE,  
  64.  
  65.             CL_PW_CLR_STATE_CODE => CL_PW_CLR_STATE_CODE,  
  66.             CL_PW_STORE_DCT_STATE_CODE => CL_PW_STORE_DCT_STATE_CODE,  
  67.             CL_POST_STATE_CODE => CL_POST_STATE_CODE,  
  68.             CL_TO_UNLCK_LSTN_STATE_CODE => CL_TO_UNLCK_LSTN_STATE_CODE,  
  69.             CL_TO_LCK_LSTN_STATE_CODE => CL_TO_LCK_LSTN_STATE_CODE,  
  70.  
  71.             CL_TO_LCK_CLAP_SLTS => CL_TO_LCK_CLAP_SLTS,  
  72.             LED_SEC_BLINK_DISP => LED_SEC_BLINK_DISP,  
  73.             LED_LSTN_MODE => LED_LSTN_MODE,  
  74.             PW_PTRN_RT => PW_PTRN_RT,  
  75.             PW_PTRN_ST => PW_PTRN_ST  
  76.         );  
  77.  
  78.     -- Simulation of Introduction of the Clap Lock  
  79.  
  80.     PROCESS IS  
  81.         VARIABLE TRIGGER_RIGHT_PASSWORD : BOOLEAN := FALSE;  
  82.         VARIABLE HAS_ITERATED_WHOLE_PROCESS : BOOLEAN := FALSE;  
  83.         VARIABLE SIMULATION_INF_LOOP : BOOLEAN := TRUE;  
  84.     BEGIN  
  85.         REPORT "Testbench | The system will check for the password storage container after 300 ms.";  
  86.  
  87.         WAIT FOR 300 MS;  
  88.  
  89.         REPORT "Testbench | Waiting for Input Clap...";  
  90.         CL_MIC_DTCTR <= '1';  
  91.         LED_LSTN_MODE <= '1';  
  92.  
  93.         -- Waits for Module to Set CL_PW_STORE_DCT_STATE_CODE to LTC.  
  94.  
  95.         REPORT "Testbench | Ready, Waiting for State Change to CL_PW_STORE_DCT_STATE_CODE ...";  
  96.         WAIT UNTIL CL_PW_STORE_DCT_STATE_CODE = 1;  
  97.  
  98.         -- Change the REPORT Display.  
  99.         REPORT "Testbench | CL_PW_STORE_DCT_STATE_CODE Value is " & INTEGER'image(CL_PW_STORE_DCT_STATE_CODE);  
  100.  
  101.         WHILE (CL_PW_STORE_DCT_STATE_CODE /= 4) LOOP  
  102.  
  103.             -- Input Password Per Pattern Slot for Processor #6  
  104.             FOR ITERATION_INDEX IN 0 TO CLAP_WIDTH - 1 LOOP  
  105.                 IF CL_PW_STORE_DCT_STATE_CODE = 3 THEN  
  106.                     REPORT "Testbench | Password has been reset due to Interrupted Process.";  
  107.                     PW_PTRN_RT <= "00000000";  
  108.                     EXIT;  
  109.                 ELSE  
  110.                     WAIT FOR 1 SEC;  
  111.                     LED_SEC_BLINK_DISP <= NOT LED_SEC_BLINK_DISP;  
  112.                     IF ITERATION_INDEX = 1 OR ITERATION_INDEX = 3 OR ITERATION_INDEX = 5 OR ITERATION_INDEX = 6 THEN  
  113.                         PW_PTRN_RT(ITERATION_INDEX) <= CL_MIC_DTCTR;  
  114.                         REPORT "Testbench | Iteration Index #" & INTEGER'image(ITERATION_INDEX) & " | With CL_MIC_DTCTR Value of " & STD_LOGIC'image(CL_MIC_DTCTR);  
  115.                     END IF;  
  116.                 END IF;  
  117.             END LOOP;  
  118.  
  119.             WAIT FOR 250 MS;  
  120.             IF CL_PW_STORE_DCT_STATE_CODE = 3 THEN  
  121.                 NEXT;  
  122.             END IF;  
  123.             LED_SEC_BLINK_DISP <= '0';  
  124.             PW_PTRN_RT <= "00000000";  
  125.         END LOOP;  
  126.  
  127.         WHILE (SIMULATION_INF_LOOP /= FALSE) LOOP  
  128.             IF HAS_ITERATED_WHOLE_PROCESS THEN  
  129.                 REPORT "The process has been iterated again. Reiterating in 3 Seconds.";  
  130.                 WAIT FOR 3 SEC;  
  131.             ELSE  
  132.                 REPORT "This is the first run of the process simulation introduction.";  
  133.             END IF;  
  134.  
  135.             CL_MIC_DTCTR <= '0';  
  136.             LED_LSTN_MODE <= '0';  
  137.  
  138.             WAIT FOR 1 SEC;  
  139.  
  140.             REPORT "Testbench | Waiting for Input Clap to Unlock the System...";  
  141.             LED_LSTN_MODE <= '1';  
  142.             CL_MIC_DTCTR <= '1';  
  143.             -- Wait for 250MS to compensate to reading the data.  
  144.             -- Lock To Unlock Process  
  145.             -- Active Microphone and the Timer along with Runtime Password Pattern Checker.  
  146.             WAIT FOR 250 MS;  
  147.             REPORT "Testbench | Feedback Received. Iterating to Unlock...";  
  148.  
  149.             WHILE (CL_POST_STATE_CODE /= 0) LOOP  
  150.                 FOR EACH_INDEX IN 0 TO CLAP_WIDTH LOOP  
  151.                     IF (BTN_DISCARD_CURR_SEQ = '0' AND LED_LSTN_MODE = '1') THEN  
  152.                         WAIT FOR 1 SEC;  
  153.                         LED_SEC_BLINK_DISP <= NOT LED_SEC_BLINK_DISP;  
  154.                         IF TRIGGER_RIGHT_PASSWORD /= FALSE THEN  
  155.                             PW_PTRN_RT(EACH_INDEX) <= CL_MIC_DTCTR;  
  156.                         ELSE  
  157.                             IF EACH_INDEX = 1 OR EACH_INDEX = 3 OR EACH_INDEX = 5 OR EACH_INDEX = 6 THEN  
  158.                                 PW_PTRN_RT(EACH_INDEX) <= CL_MIC_DTCTR;  
  159.                             END IF;  
  160.                         END IF;  
  161.                     ELSE  
  162.                         PW_PTRN_RT <= "00000000";  
  163.                         REPORT "PW_PTRN_RT has been reset.";  
  164.                         LED_SEC_BLINK_DISP <= '0';  
  165.  
  166.                     END IF;  
  167.                 END LOOP;  
  168.                 TRIGGER_RIGHT_PASSWORD := TRUE;  
  169.                 WAIT FOR 250 MS;  
  170.                 LED_SEC_BLINK_DISP <= '0';  
  171.                 PW_PTRN_RT <= "00000000";  
  172.             END LOOP;  
  173.  
  174.             -- Keep note that, after iteration, the PW_PTRN_RT should be reset here!  
  175.             -- The module cannot modify it since PW_PTRN_RT is in IN mode. INOUT cannot do 
  176.  
  177.             WAIT UNTIL CL_TO_LCK_LSTN_STATE_CODE = 2;  
  178.  
  179.             REPORT "Simulation has been finished.";  
  180.  
  181.             HAS_ITERATED_WHOLE_PROCESS := TRUE;  
  182.             CL_MIC_DTCTR <= '0';  
  183.             LED_LSTN_MODE <= '0';  
  184.             TRIGGER_RIGHT_PASSWORD := FALSE;  
  185.         END LOOP;  
  186.     END PROCESS;  
  187. END ARCHITECTURE;  

  1. After copying the VHDL Code, save and then right click the file and the click Compile > Compile Properties.


Figure 1.4 Compile Properties

  1. The “Project Compiler Settings” will appear and then on VHDL > Language Syntax, be sure to enable the “Use 1076-2008” in order to compile the files without error because there are rules that have changed on the latest syntax which is used on the VHDL Code. Then click ok. Be sure to do this on both files


Figure 1.5 Project Compiler Settings for the both files

  1. Compile the VHDL Files by hitting the Compile Icon on the menu bar for the two VHDL files.

Figure 1.6 Compiling the module and test bench file

  1. Both module and test bench files are now ready for simulation. On the menu bar, you can click Start Simulation and then the workspace will change. (You need to run the simulation on Test Bench File)


Figure 1.7 Starting simulation for both files

  1. Output Waveform: (Include at least three output waveform by moving the yellow vertical line. Explain each figure)

  1. No password detected into setting up the password.

Figure 2.1: Waveform for Setting up the password

Explanation: In this output waveform, you can see that there is a small amount of time where the system will detect if there is a stored password. After detecting for stored password, for the first simulation of the system, it tells that there is no password as you can see on CL_PW_VECTOR_STATE_DISP where it signals NPW that stands for “No Password”. Then the system will now directly go to the listening mode of claps which is indicated as LTC and then we input 1, 3, 5 and 7 as our clap password pattern.

  1. Password stored with no errors.

Figure 2.2 Password Stored without errors and ready for unlocking.

Explanation: After the system stored without errors as you can see on CL_PW_VECTOR_STATE_DISP it signals OKY which means “no errors” and that the password is ready for unlocking the lock using the clap pattern that we stored. The password is stored without errors because we have met the rules that the clap minimum length should be 3 claps and then the maximum clap length should be 4.

  1. Test for clap pattern.

Figure 2.3 Testing the clap pattern we have stored on the system.

Explanation: The system is now on listening mode and then after 8.5 seconds we assumed that we clapped and then the system is now ready for analyzing the pattern that the person will input for unlocking the clap lock system. There is a 1 second initialization time before you start counting your clap pattern. And the initialization time will be initialized when you clap once.

  1. Password pattern successful.

Figure 2.4 The system is unlocked

Explanation: As you can see from the CL_POST_STATE_DISP it signals ULK which means “Unlocked Mode” that tells us that the clap lock system is in an unlocked state because we have no mistakes or errors in doing the clap pattern that we stored. Also you can see on CL_TO_LCK_CLAP_SLTS it detects 2 consecutive claps which is initialization for locking the system and after that you can see that CL_POST_STATE_DISP signals LKD which means “Locked Mode”.

  1. Password verification if the pattern is still usable after 1 attempt of unlocking the system.

Figure 2.5 Testing for password pattern (2nd attempt)

Explanation: This waveform is just for verification if the password pattern is still stored and usable and as you can see on the output the password is recognized again by the clap lock system which means we have a successful VHDL Code for this system.

  1. Questions:

What errors did you encounter when creating the project? How did you debug it?

1. Unable to drive signals from multiple processes.

- The VHDL Compiler keeps on complaining about how multiple processes cannot modify a singleton signal on IN mode. What we did was to create more signals by dividing them even further to assign a particular state that can only be detected by other processes.

2. Changes on signals aren't reflected instantly.

- To make the damage less costly by reiterating or rewriting the whole code after realizing that the changes aren't reflecting immediately. We have to compensate by putting WAIT FOR 1 SEC or less than 1 second to make it sure that the process doesn't delay much.

3. Cannot divide basic functionalities on the testbench for the capability tests.

- We decided to combine all basic functionalities that drive the module's functionality by merging them into one and making spaces for each functionality with a WAIT FOR statement.

4. Rule enforcement from VHDL Compiler doesn't allow explicit actions such as the declaration of signals to modification all over the place.

- Due to some rule enforcement reasons that we cannot identify properly, we are forced to use the VHDL 2008 Compliant Compiler to make the codebase following the modern programming.

5. STD_LOGIC_1164 and its capabilities on IN, OUT and even INOUT modes are confusing the signals.

- Sometimes, switching to these modes causes multiple unknown and unexpected states that we didn't even try to attempt to. So far, we have managed to do modification of OUT signals inside the Module file, while IN signals can be modified in the testbench. The use of INOUT modes in the initial configuration does not work and understanding the MODES resolves the issue.

6. Simulator is very unstable and causes breakdown to the SSD of the Programmer.

- With the simulator being old and outdated, the use of ModelSim is really a not preferable choice. There are lots of bugs that may potentially break the programmer's computer. One time, it has gotten to an infinite loop, and the transcript file stream was saved to the point of allocating 60GB of SSD storage space. It has been resolved by removing the file. Though, with the time constraints, the use or the time it takes to find a suitable substitute does not make it for a time being, with the fact that this project has a time frame of 3 days in overall.

  1. Conclusion:

This is a project on CLAP SWITCH which can switch on/off any electrical circuit by the sound of a clap. The operation of the circuit is simple. If we clap on a specific pattern that is set to unlock the switch it will unlock with respect to time. The condenser microphone picks up the sound of claps. It produces a small electrical signal which is amplified by the succeeding transistor stage. Two transistors are cross-connected as a bi-stable multivibrator change state at each signal. This circuit can switch on and off a light, lock system, a fan, etc by the sound of a clap.

The clap activated switching device function properly by responding to both hand claps at about three to four-meter away and finger tap sound at very close range, since both are low-frequency sounds and produce the same pulse wave features. The resulting device is realizable, has good reliability and it’s relatively inexpensive. By using some modification its area of application can be extended in various fields. It can be used to raised alarm in the security

a system with noise, and also used at the place where silence was needed.

  1. Assessment: