|
| 1 | +"""Basic JESD204 Calculator.""" |
| 2 | + |
| 3 | +from typing import Optional |
| 4 | + |
| 5 | +import pandas as pd |
| 6 | +import streamlit as st |
| 7 | + |
| 8 | +from ..utils import Page |
| 9 | + |
| 10 | + |
| 11 | +class JESDBasic(Page): |
| 12 | + """Basic JESD204 calculator page.""" |
| 13 | + |
| 14 | + def __init__(self, state: Optional[object]) -> None: |
| 15 | + """Initialize basic JESD204 calculator page. |
| 16 | +
|
| 17 | + Args: |
| 18 | + state: Application state object |
| 19 | + """ |
| 20 | + self.state = state |
| 21 | + |
| 22 | + def write(self) -> None: |
| 23 | + """Render the basic JESD204 calculator page.""" |
| 24 | + st.title("Basic JESD204 Calculator") |
| 25 | + |
| 26 | + # Horizontal line |
| 27 | + st.markdown("---") |
| 28 | + |
| 29 | + # Add int boxes for L, M, Np, JESD Class |
| 30 | + jesd_params, output_table = st.columns(2) |
| 31 | + with jesd_params: |
| 32 | + st.header("JESD204 Parameters") |
| 33 | + |
| 34 | + L_c, M_c = st.columns(2) |
| 35 | + |
| 36 | + with L_c: |
| 37 | + L = st.number_input( |
| 38 | + "L (number of lanes)", min_value=1, step=1, value=4 |
| 39 | + ) |
| 40 | + with M_c: |
| 41 | + M = st.number_input( |
| 42 | + "M (number of converters)", min_value=1, step=1, value=4 |
| 43 | + ) |
| 44 | + |
| 45 | + np_c, class_c = st.columns(2) |
| 46 | + with np_c: |
| 47 | + Np = st.number_input( |
| 48 | + "Np (Bits per sample)", min_value=1, step=1, value=16 |
| 49 | + ) |
| 50 | + |
| 51 | + with class_c: |
| 52 | + jesd_class = st.selectbox( |
| 53 | + "JESD204 Class", ["JESD204B", "JESD204C"] |
| 54 | + ) |
| 55 | + |
| 56 | + label_c, value_c = st.columns(2) |
| 57 | + with label_c: |
| 58 | + clock_ref_source = st.selectbox( |
| 59 | + "Clock Reference Source", ["Sample Rate", "Lane Rate"] |
| 60 | + ) |
| 61 | + |
| 62 | + with value_c: |
| 63 | + if clock_ref_source == "Sample Rate": |
| 64 | + sample_rate = st.number_input( |
| 65 | + "Sample Rate (SPS)", |
| 66 | + min_value=1.0, |
| 67 | + step=1.0, |
| 68 | + value=100e6, |
| 69 | + ) |
| 70 | + else: |
| 71 | + lane_rate = st.number_input( |
| 72 | + "Lane Rate (Gbps)", min_value=0.1, step=0.1, value=10.0 |
| 73 | + ) |
| 74 | + |
| 75 | + if jesd_class == "JESD204B": |
| 76 | + encoding_factor = float(10) / float( |
| 77 | + 8 |
| 78 | + ) # Assuming 16-bit samples for simplicity |
| 79 | + else: |
| 80 | + encoding_factor = float(66) / float( |
| 81 | + 64 |
| 82 | + ) # Assuming 16-bit samples for simplicity |
| 83 | + |
| 84 | + # Lane rate = (M * Np * Sample Rate * encoding_factor) / L |
| 85 | + if clock_ref_source == "Sample Rate": |
| 86 | + rate = ( |
| 87 | + (M * Np * sample_rate * encoding_factor) / L / 1e9 |
| 88 | + ) # Convert to Gbps |
| 89 | + label = "Lane Rate (Gbps)" |
| 90 | + if jesd_class == "JESD204B": |
| 91 | + core_clock = rate / 40 * 1e3 # Convert to MHz |
| 92 | + else: |
| 93 | + core_clock = rate / 66 * 1e3 # Convert to MHz |
| 94 | + else: |
| 95 | + # lane_rate_gbps = lane_rate |
| 96 | + rate = ( |
| 97 | + (lane_rate * 1e9 * L) / (M * Np * encoding_factor) / 1e6 |
| 98 | + ) # Convert to MSPS |
| 99 | + label = "Sample Rate (MSPS)" |
| 100 | + if jesd_class == "JESD204B": |
| 101 | + core_clock = lane_rate / 40 * 1e3 # Convert to MHz |
| 102 | + else: |
| 103 | + core_clock = lane_rate / 66 * 1e3 # Convert to MHz |
| 104 | + |
| 105 | + with output_table: |
| 106 | + st.header("Derived Parameters") |
| 107 | + df = pd.DataFrame( |
| 108 | + { |
| 109 | + "Parameter": [label, "Core Clock (MHz)"], |
| 110 | + "Value": [rate, core_clock], |
| 111 | + } |
| 112 | + ) |
| 113 | + st.table(df) |
0 commit comments