# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] deletable=true editable=true
# ## Pattern Generation and Trace for IC NTE74HC161 TTL, Synchronous 4-Bit Counter
# This notebook shows and example of generating patterns and tracing the outputs for an off-the-shelf IC using PYNQ DI overlay.  
# The input stimulus is provided and output respose is captured in the notebook using the WaveJson format.  
# The Pattern is generated at 10Mhz. We are applying a 112 vectors in a single shot
#
# #### References
# http://datasheet.octopart.com/NTE74HC163-NTE-Electronics-datasheet-22129263.pdf

# + [markdown] deletable=true editable=true
# ## Step 1: Overlay Management
# Users have to import all the necessary classes. Make sure to use the right bitstream.

# + deletable=true editable=true run_control={"frozen": false, "read_only": false}
from pynq import Overlay

Overlay('interface.bit').download()

fsm_spec = {'inputs': [('not_start','D14'),('Q','D15'),
                       ('E','D16')],
        'outputs': [('Clear','D0'), ('Clk','D1'), ('A','D2'), ('B','D3'), 
                    ('C','D4'), ('D','D5'), ('Enable_P','D8'), ('Load','D7'),
                    ('Enable_T','D6')],
        'states': ['S0', 'S1', 'S2'],
        'transitions': [['0--', 'S0', 'S0', '000000000'],
                        ['1--', 'S0', 'S1', '000000000'],
                        ['1--', 'S1', 'S2', '000000000'],
                        ['0--', 'S1', 'S0', '000000000'],
                        ['1--', 'S2', 'S1', '110000111'],
                        ['0--', 'S2', 'S0', '110000111'],
                        ['0--', '*',  'S0', '']]}
            

# + deletable=true editable=true
from pynq.intf import ARDUINO
from pynq.intf import FSMGenerator

fsm = FSMGenerator(ARDUINO, fsm_spec, use_analyzer=True)

# + deletable=true editable=true
fsm.display()

# + deletable=true editable=true
fsm.start(num_samples=40, frequency_mhz=10)
fsm.waveform.display()

# + deletable=true editable=true
fsm.data_samples

# + deletable=true editable=true
fsm.transitions
# -



StarcoderdataJupyterScriptsDedupFiltered