Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| waveforms_-_rom_logic [2016/11/28 08:14] – [5. Example: Binary counter with Count Enable input.] Mircea Dabacan | waveforms_-_rom_logic [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| The core of any of the instrumentation Digilent devices (Electronics Explorer, Analog Discovery, Analog Discovery 2, Digital Discovery, etc.) is an FPGA circuit loaded with the associated configuration file. The WaveForms software communicates with the FPGA and provides user interfaces as a workbench of instruments. | The core of any of the instrumentation Digilent devices (Electronics Explorer, Analog Discovery, Analog Discovery 2, Digital Discovery, etc.) is an FPGA circuit loaded with the associated configuration file. The WaveForms software communicates with the FPGA and provides user interfaces as a workbench of instruments. | ||
| + | |||
| The Digital Pattern Generator (Patterns) instrument handles the DIO (Digital Input/ | The Digital Pattern Generator (Patterns) instrument handles the DIO (Digital Input/ | ||
| + | |||
| The figure below shows the block diagram associated with a single DIO pin. The Input Buffers (IB) and Output Buffers (OB) are intrinsic to the FPGA IO bank structure. The Pattern Memory is implemented in the FPGA block RAM. All other blocks are implemented in the programmable area of the FPGA. | The figure below shows the block diagram associated with a single DIO pin. The Input Buffers (IB) and Output Buffers (OB) are intrinsic to the FPGA IO bank structure. The Pattern Memory is implemented in the FPGA block RAM. All other blocks are implemented in the programmable area of the FPGA. | ||
| + | |||
| A DIO line can be set as Output in at most one Pattern Generator object. When a line is used by the Static I/O as an output element (Slider, Button, or Switch), this has priority over the signal configuration in Patterns (not shown in the block diagram). | A DIO line can be set as Output in at most one Pattern Generator object. When a line is used by the Static I/O as an output element (Slider, Button, or Switch), this has priority over the signal configuration in Patterns (not shown in the block diagram). | ||
| + | |||
| Signals and Buses generate time sequenced output values: the sampling rate derives from the system clock, and the sample values are either algorithmically generated (clocks, pulses, counters, etc.) or read from a Pattern Memory (custom). In the latter case, a Counter points the current sample in the Pattern Memory. | Signals and Buses generate time sequenced output values: the sampling rate derives from the system clock, and the sample values are either algorithmically generated (clocks, pulses, counters, etc.) or read from a Pattern Memory (custom). In the latter case, a Counter points the current sample in the Pattern Memory. | ||
| + | |||
| For the ROM logic, a Boolean function Truth Table is stored in the Pattern Memory. An n-bit input bus (from DIO pins) builds the address for the Pattern Memory. | For the ROM logic, a Boolean function Truth Table is stored in the Pattern Memory. An n-bit input bus (from DIO pins) builds the address for the Pattern Memory. | ||
| - | Since the size of the Pattern Memory is limited to 2n locations, the input buffer IB is only present for the first n DIO pins (0 to n-1). However, any DIO pin can implement a Boolean function of DIO pins 0 to n-1. | + | |
| + | Since the size of the Pattern Memory is limited to 2< | ||
| For Analog Discovery, Analog Discovery 2 and Electronics Explorer default configurations, | For Analog Discovery, Analog Discovery 2 and Electronics Explorer default configurations, | ||
| + | |||
| Since the Pattern Memory is implemented in an FPGA Block RAM, the Boolean function is synchronized on the prescaled clock. | Since the Pattern Memory is implemented in an FPGA Block RAM, the Boolean function is synchronized on the prescaled clock. | ||
| Line 30: | Line 38: | ||
| A DIO pin used as input (argument) in its own Boolean function closes a feedback loop, and the DIO pin is a state bit. One or more state bits build a state variable in a Finite State Machine (FSM). | A DIO pin used as input (argument) in its own Boolean function closes a feedback loop, and the DIO pin is a state bit. One or more state bits build a state variable in a Finite State Machine (FSM). | ||
| + | |||
| The figure below shows the generic block diagram of a Mealy FSM mapped on a ROM logic object. A Moore FSM does not use the Inputs in Output Logic block. | The figure below shows the generic block diagram of a Mealy FSM mapped on a ROM logic object. A Moore FSM does not use the Inputs in Output Logic block. | ||
| + | |||
| Notice that the pins used both as inputs and outputs (DIOx) form the State Variable; the pins used as inputs only (DIOy) are FSM inputs and the pins used as outputs only (DIOz) are FSM (synchronized) outputs. The state variable is always available at the FPGA DIOx pins. | Notice that the pins used both as inputs and outputs (DIOx) form the State Variable; the pins used as inputs only (DIOy) are FSM inputs and the pins used as outputs only (DIOz) are FSM (synchronized) outputs. The state variable is always available at the FPGA DIOx pins. | ||
| + | |||
| The FSM can be implemented in a single or in multiple ROM logic objects. In the latter case, a clean design would use a ROM logic object for the Next State Logic and the State Register, and another one for the Output Logic and the Output Register. | The FSM can be implemented in a single or in multiple ROM logic objects. In the latter case, a clean design would use a ROM logic object for the Next State Logic and the State Register, and another one for the Output Logic and the Output Register. | ||
| Line 38: | Line 49: | ||
| // | // | ||
| - | ===== 3. ROM logic User Interface in WaveForms | + | ===== 3. ROM logic User Interface in WaveForms ===== |
| In the Pattern Generator, click the green “plus” sign and select ROM logic, as shown below. | In the Pattern Generator, click the green “plus” sign and select ROM logic, as shown below. | ||
| Line 50: | Line 61: | ||
| In the Pop-up window, select the Properties tab. Select or type in the synchronizing frequency. Use the green “plus” signs to add input and output signals in the left and right lists. Use the green arrows to move signals up or down in the lists. The list order will be preserved in the Truth Table tab. | In the Pop-up window, select the Properties tab. Select or type in the synchronizing frequency. Use the green “plus” signs to add input and output signals in the left and right lists. Use the green arrows to move signals up or down in the lists. The list order will be preserved in the Truth Table tab. | ||
| + | |||
| Select the Truth Table tab. Edit or import the truth table. Use the Truth Table rules: | Select the Truth Table tab. Edit or import the truth table. Use the Truth Table rules: | ||
| * Change the signal names in the Properties tab, if convenient (optional). Changed names will be used in the Truth Table. | * Change the signal names in the Properties tab, if convenient (optional). Changed names will be used in the Truth Table. | ||
| * If a signal is used in both input and output panes, it is a State Variable; the input pane shows its value in the Current State and the output pane indicates its value in the Next State. | * If a signal is used in both input and output panes, it is a State Variable; the input pane shows its value in the Current State and the output pane indicates its value in the Next State. | ||
| * Use 0, 1 or X (don’t care) in the input pane. | * Use 0, 1 or X (don’t care) in the input pane. | ||
| - | * An expanded Truth Table (no X input values) with n input signals has 2n lines. A line including k X values is the collapsed version of 2k lines of the expanded Truth Table. | + | * An expanded Truth Table (no X input values) with n input signals has 2< |
| - | * Make sure that all possible input cases are covered, i.e. the logical reunion of all input lines is 2n. | + | * Make sure that all possible input cases are covered, i.e. the logical reunion of all input lines is 2< |
| * Use 1, 0, “SignalName” or “/ | * Use 1, 0, “SignalName” or “/ | ||
| * The table lines are “sequential”, | * The table lines are “sequential”, | ||
| Line 64: | Line 76: | ||
| ===== 4. Example: Three input, synchronous AND gate. ===== | ===== 4. Example: Three input, synchronous AND gate. ===== | ||
| - | In Figure | + | In Figure |
| - | In the Truth Table tab, the first line describes the default case, with the output signal value of 0. With three X-es in the input pane, this line is equivalent to 23=8 expanded lines. However, the second line overrides one line out of the eight, forcing the output signal to 1 when all inputs are 1. | + | |
| - | The equivalent VHDL code is: | + | |
| - | -- Line 1 in the truth table | + | In the Truth Table tab, the first line describes the default case, with the output signal value of 0. With three X-es in the input pane, this line is equivalent to 2< |
| - | + | The equivalent VHDL code is: | |
| - | AND3: process(i2, | + | |
| - | + | -- Line 1 in the truth table | |
| - | begin | + | |
| - | + | | |
| - | o3 <= ‘0’; | + | o3 <= ‘0’; |
| - | + | | |
| - | -- Line 2 in the truth table | + | if i2 = ‘1’ and i1 = ‘1’ and i0 = ‘1’ then |
| - | + | | |
| - | if i2 = ‘1’ and i1 = ‘1’ and i0 = ‘1’ then | + | end if; |
| - | + | | |
| - | o3 <= ‘1’; -- overrides o3 for a particular case | + | |
| - | + | ||
| - | end if; | + | |
| - | + | ||
| - | end process; | + | |
| Notice that the Truth Table lines are “sequential”, | Notice that the Truth Table lines are “sequential”, | ||
| Line 99: | Line 104: | ||
| To observe the dynamic behavior of the synchronized 3-input AND gate, define a binary counter on DIO2…DIO0 in the Pattern Generator. Set the clock frequency to 3MHz. (However, the closest frequency WaveForms can generate is 2.941MHz.) This frequency is chosen not to be integer multiple or submultiple of the ROM logic frequency (5MHz). Also define a 5MHz clock on DIO4 (same as for the ROM logic). This clock is not used by the ROM logic, but will serve as reference for observation in the Logic Analyzer. | To observe the dynamic behavior of the synchronized 3-input AND gate, define a binary counter on DIO2…DIO0 in the Pattern Generator. Set the clock frequency to 3MHz. (However, the closest frequency WaveForms can generate is 2.941MHz.) This frequency is chosen not to be integer multiple or submultiple of the ROM logic frequency (5MHz). Also define a 5MHz clock on DIO4 (same as for the ROM logic). This clock is not used by the ROM logic, but will serve as reference for observation in the Logic Analyzer. | ||
| + | |||
| Open a Logic Analyzer. Add/Bus with DIO2…DIO0, | Open a Logic Analyzer. Add/Bus with DIO2…DIO0, | ||
| + | |||
| Run a Single step in the Logic analyzer. Observe that DIO3 (the AND gate output) does not synchronize with the edges of Bus1 inputs, but with DIO4: DIO4 is not the actual ROM Logic clock, but it has the same frequency and phase, so it can be used as an image of the actual ROM Logic clock. Since the ROM Logic is synchronized to the completion of each clock period, and DIO4 starts with a 0 and continues with a 1, the DIO3 seems to be synchronized on the falling edge of DIO4. | Run a Single step in the Logic analyzer. Observe that DIO3 (the AND gate output) does not synchronize with the edges of Bus1 inputs, but with DIO4: DIO4 is not the actual ROM Logic clock, but it has the same frequency and phase, so it can be used as an image of the actual ROM Logic clock. Since the ROM Logic is synchronized to the completion of each clock period, and DIO4 starts with a 0 and continues with a 1, the DIO3 seems to be synchronized on the falling edge of DIO4. | ||
| Line 109: | Line 116: | ||
| ===== 5. Example: Binary counter with Count Enable input. ===== | ===== 5. Example: Binary counter with Count Enable input. ===== | ||
| - | In the figure below, DIO8 is renamed CE and is used as Count Enable. DIO7…DIO0 are renamed c7…c0 and are the state/ | + | In the figure below, DIO8 is renamed CE and is used as Count Enable. DIO7…DIO0 are renamed c7…c0 and are the state/ |
| - | Line 1 in the Truth Table (equivalent to 28=256 expanded lines) means: when LSB c0=’0’: all bits c7…c1 keep value; c0 changes to ‘1’ only if CE=’1’. All other lines cover the cases when c0=’1’. | + | |
| - | Line 2 (equivalent to 27=128 expanded lines): means when c1=’0’ and c0=’1’: both will swap if CE=’1’ or keep their value if CE=’0’; all other bits keep their value. | + | Line 1 in the Truth Table (equivalent to 2< |
| - | All nine lines are equivalent to 29=512 expanded lines and define all possible cases (8 bit+1 Count Enable). | + | |
| + | Line 2 (equivalent to 2< | ||
| + | |||
| + | All nine lines are equivalent to 2< | ||
| To verify the behavior, add a clock signal on DIO8 (Frequency=1kHz, | To verify the behavior, add a clock signal on DIO8 (Frequency=1kHz, | ||
| + | |||
| In the Logic Analyzer, Add/Bus DIO7…DIO0 and Add/Signal DIO8. Run Pattern Generator and Single step Logic Analyzer. Observe the behavior of the binary counter. | In the Logic Analyzer, Add/Bus DIO7…DIO0 and Add/Signal DIO8. Run Pattern Generator and Single step Logic Analyzer. Observe the behavior of the binary counter. | ||
| Line 125: | Line 137: | ||
| In the figure below, an n-bit binary counter generates a digital sawtooth signal. The comparator drives DIOx = 1 when the sample value is greater than the counter content. | In the figure below, an n-bit binary counter generates a digital sawtooth signal. The comparator drives DIOx = 1 when the sample value is greater than the counter content. | ||
| + | |||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| + | |||
| The DIOx carrier frequency is: | The DIOx carrier frequency is: | ||
| - | f_carrier=f_cnt/2^n | + | |
| + | | ||
| If the n-bit sample is constant, the DIOx pin is driven with constant Duty Factor: | If the n-bit sample is constant, the DIOx pin is driven with constant Duty Factor: | ||
| - | DF=(nbit sample)/ | + | |
| + | $$DF=(sample)/ | ||
| + | |||
| A 5-bit bus is created to generate the modulator n-bit samples (DIO4…DIO0). For the first experiment, the bus type is set to Number, to generate a static value between 0 and 31. | A 5-bit bus is created to generate the modulator n-bit samples (DIO4…DIO0). For the first experiment, the bus type is set to Number, to generate a static value between 0 and 31. | ||
| - | A 5-bit counter is implemented in a ROM logic object, as below, on DIO9…DIO5, | + | |
| - | A second ROM logic (sheet PWM in RomLogicTrouthTables.xls) compares DIO9…DIO5 = c4…c0 = “5BitCounter” with DIO4…DIO0 = s4…s0 = ”Sample”. DIO10 = CY = ”CarryOut” is High when “Sample” is higher. Notice again how higher order bits (later lines in the Truth Table) override the lower order bits (earlier lines in the Truth Table). | + | {{: |
| - | An external RC Low Pass Filter (100kΩ, 1nF) is used to build the analog signal, removing the carrier from the PWM signal. The WaveForms scope shows the PWM signal (C1) and the filtered signal (C 2). | + | |
| - | | + | // |
| - | f_carrier=f_cnt/2^n =1MHz/2^5 =31.25kHz; | + | |
| - | | + | A 5-bit counter is implemented in a ROM logic object, as below, on DIO9…DIO5, |
| - | Variable n-bit sample can be used as a modulator signal. For the second experiment, set a custom 5-bit Bus 1 in the Pattern Generator, to drive a sinus signal with 100 samples per period. Generate a .csv file, with 100 values of form (sheet SinusSamples in RomLogicTrouthTables.xls): | + | |
| - | 〖sample〗_i=16+int(15*sin((2∙π∙i)/ | + | {{: |
| + | |||
| + | // | ||
| + | |||
| + | A second ROM logic (sheet PWM in {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| + | An external RC Low Pass Filter (100kΩ, 1nF) is used to build the analog signal, removing the carrier from the PWM signal. The WaveForms scope shows the PWM signal (C1) and the filtered signal (C2). | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| + | Notice the C1 frequency and duty factor (both on the graphical view and measurement pane): | ||
| + | |||
| + | $$f_{carrier}=f_{cnt}/2^n =1MHz/2^5 =31.25kHz;$$ | ||
| + | $$DF=sample/ | ||
| + | |||
| + | Modify the sample value in the Pattern Generator and observe the effect on the scope signals. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| + | Variable n-bit sample can be used as a modulator signal. For the second experiment, set a custom 5-bit Bus 1 in the Pattern Generator, to drive a sinus signal with 100 samples per period. Generate a .csv file, with 100 values of form (sheet SinusSamples in {{: | ||
| + | |||
| + | $$sample_i=16+int(15*sin((2∙π∙i)/ | ||
| Make Bus1 custom and import the .csv file. You can also copy the samples from the Excel file and paste them into the Sample column, in the Edit Custom Bus window. | Make Bus1 custom and import the .csv file. You can also copy the samples from the Excel file and paste them into the Sample column, in the Edit Custom Bus window. | ||
| - | Set the clock frequency to 100kHz, for a sinus frequency of: | + | |
| - | f_modulator=f_sample/(#Sample)=200KHz/ | + | Set the clock frequency to 200kHz, for a sinus frequency of: |
| + | |||
| + | $$ f_{modulator}=f_{sample}/(100)=200KHz/ | ||
| + | |||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| The scope shows the variable Duty Factor PWM signal on C1, and an analog signal on C2, approximating a sinus. The carrier frequency is constant (same as above). The Duty Factor is variable with a mean value of 50%. | The scope shows the variable Duty Factor PWM signal on C1, and an analog signal on C2, approximating a sinus. The carrier frequency is constant (same as above). The Duty Factor is variable with a mean value of 50%. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| + | |||
| ===== 7. Example: PDM modulator. ===== | ===== 7. Example: PDM modulator. ===== | ||
| - | In the figure below, an n-bit accumulator is used to add the sample value over and over. The Carry Out bit is the Pulse Density Modulated (PDM) signal. The accumulator is refreshed with fcnt frequency, while samples succeed with fsample | + | In the figure below, an n-bit accumulator is used to add the sample value over and over. The Carry Out bit is the Pulse Density Modulated (PDM) signal. The accumulator is refreshed with f< |
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| For being able to switch very fast from PWM to PDM and back, a second pattern Generator instance is open from the already existing one: | For being able to switch very fast from PWM to PDM and back, a second pattern Generator instance is open from the already existing one: | ||
| - | A 5-bit PDM modulator is implemented in the PDM Accumulator ROM logic object, with DIO 9…DIO5 = a4…a0 as “Accumulator”, | + | |
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| + | A 5-bit PDM modulator is implemented in the PDM Accumulator ROM logic object, with DIO 9…DIO5 = a4…a0 as “Accumulator”, | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| The truth table is fully expanded, with 1024 lines. The left pane contains all binary values of DIO9…DIO0. The right pane contains the 5-bit + carry accumulated sum: | The truth table is fully expanded, with 1024 lines. The left pane contains all binary values of DIO9…DIO0. The right pane contains the 5-bit + carry accumulated sum: | ||
| - | (CY, | + | |
| - | To compare with PWM, similar examples are used. The same external RC filter, the clock frequency of the modulator, the sinus sample LUT and sample frequency are all the same as in the corresponding PWM experiments. | + | $$(CY, |
| - | In the static experiment, the same duty factor is generated, with a much higher frequency, resulting in a much smaller ripple of the analog signal. | + | |
| + | To compare with PWM, similar examples are used. The same external RC filter, the clock frequency of the modulator, the sinus Sample Memory | ||
| + | |||
| + | In the static experiment, the same duty factor is generated, with a much higher frequency, resulting in a much smaller ripple of the analog signal. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| In the dynamic experiment, the same sinus custom Bus1 was used, as for the PWM. The average Duty Factor is again around 50%, the frequency is variable and the average frequency is much higher compared to PWM, for the same clock frequency. The ripple of the analog signal is also much smaller. | In the dynamic experiment, the same sinus custom Bus1 was used, as for the PWM. The average Duty Factor is again around 50%, the frequency is variable and the average frequency is much higher compared to PWM, for the same clock frequency. The ripple of the analog signal is also much smaller. | ||
| - | The lowest instantaneous frequency of the PDM signal happens when the sample value is either 1LSB or 2n-1LSB, and is the same as the constant frequency of the PWM signal. For all other values of the samples, the resulting instantaneous frequency is higher, up to half of the clock frequency, when the sample value is at half of the range. | + | |
| + | The lowest instantaneous frequency of the PDM signal happens when the sample value is either 1LSB or 2< | ||
| Having both instances of the Pattern generator open, is very easy to run them alternatively for easy comparison on the scope instrument. Hitting Run on one instance automatically turns the other instance in Busy state. | Having both instances of the Pattern generator open, is very easy to run them alternatively for easy comparison on the scope instrument. Hitting Run on one instance automatically turns the other instance in Busy state. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| The spectrum analyzer instrument is used to analyze data in the frequency domain. The two traces correspond to the two scope channels in the experiments above. In the spectral view, a cursor is set at fcarrier. Some parameters of the modulated and analog signals are shown in the measurements window. | The spectrum analyzer instrument is used to analyze data in the frequency domain. The two traces correspond to the two scope channels in the experiments above. In the spectral view, a cursor is set at fcarrier. Some parameters of the modulated and analog signals are shown in the measurements window. | ||
| + | |||
| The carrier fundamental and harmonics are significant for PWM, while PDM spread those components more uniformly in the spectrum. | The carrier fundamental and harmonics are significant for PWM, while PDM spread those components more uniformly in the spectrum. | ||
| + | |||
| The measurements have much better values for SFDR, SNR, SINAD and ENOB in the case of PDM. | The measurements have much better values for SFDR, SNR, SINAD and ENOB in the case of PDM. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | // | ||
| + | |||
| + | |||

