The code implements a trigger-based laser alternation using Moku:Go, where a falling edge on the camera's fire pulse initiates alternation between OutputA and OutputB. The process involves setting Trigger, OutputA, and OutputB to 0 or LO_LVL after a certa

Hi, I’m trying out a trigger based laser alternation with Moku:Go. I get a fire pulse from the camera and there I’m looking for the falling edge to alternate.

If the file pulse stops the alternations stops also immediately but it could happen that OutputA <= LO_LVL; and OutputB <= HI_LVL; to this time point. Then the fire pulse is stopped there is an base line signal of 0 V on the analog BNC port.

Therefore I was looking for a method to set the Trigger, OutputA, and OutputB to = 0 or LO_LV
This I try to do with an break down criteria shown in the following code.

ACTIVITY: process(Clk) is
begin
if falling_edge(Clk) then
if Trigger = ‘0’ then
TriggerLowCounter <= TriggerLowCounter + 1;
else
TriggerLowCounter <= (others => ‘0’); – Reset the counter if Trigger is high
end if;
if TriggerLowCounter = RESET_THRESHOLD then
setback <= ‘1’;
OutputA <= LO_LVL;
OutputB <= LO_LVL;
TriggerLowCounter <= (others => ‘0’); – Reset the counter after setting Reset
end if;
end if;
end process;

setback <= ‘1’ is the criteria to make sure that the alternation process becomes stopped, but it worked not so well as wanted.
The current code is compiling but there are a few number of warnings.

I need a best parctice solution for reset the signals states after in activity.

In addition, the full code I use:
library IEEE;
use IEEE.Std_Logic_1164.all;
use IEEE.Numeric_Std.all;
architecture Behavioural of CustomWrapper is
constant HI_LVL : signed(15 downto 0) := to_signed(32750, 16); – 5V scaled to signed 16 bits
constant LO_LVL : signed(15 downto 0) := to_signed(0, 16); – 0V scaled to signed 16 bits
constant Vref : signed(15 downto 0):= to_signed(16375, 16); – 2.5V scaled to signed 16 bits
constant RESET_THRESHOLD :integer := 10000000;

signal Step: std_logic;
signal Trigger, TriggerDly : std_logic;
signal DCLevelAddr : unsigned(6 downto 0);
signal TriggerLowCounter : unsigned(6 downto 0);
signal setback :  std_logic;

begin
SCHMITT: process(Clk) is
begin
if falling_edge(Clk) then
if setback = ‘1’ then
Trigger <= ‘0’;
elsif InputA >= Vref then – Compare with the reference voltage
Trigger <= ‘1’;
elsif InputA < Vref then
Trigger <= ‘0’;
end if;
TriggerDly <= Trigger;
end if;
end process;

ACTIVITY: process(Clk) is
begin
    if falling_edge(Clk) then
        if Trigger = '0' then
          TriggerLowCounter <= TriggerLowCounter + 1;
        else
            TriggerLowCounter <= (others => '0'); -- Reset the counter if Trigger is high
        end if;
        if TriggerLowCounter = RESET_THRESHOLD then
             setback <= '1';
             OutputA <= LO_LVL;
             OutputB <= LO_LVL;
             TriggerLowCounter <= (others => '0'); -- Reset the counter after setting Reset
        end if;
     end if;
end process;
        
-- Step the DC index on each falling edge
Step <= Trigger and not TriggerDly;

ADDR_COUNTER: process(Clk) is
begin
    if falling_edge(Clk) then
        if setback = '1' then
            DCLevelAddr <= (others => '0');
        elsif Step = '1' then -- Will wrap after 127
            DCLevelAddr <= DCLevelAddr + 1;
        end if;
      end if; 
end process;
        
ALTERNATION: process(Clk) is
begin
    if falling_edge(Clk) then
        if setback = '1' then
            setback <= '0';
        elsif Trigger = '1' and DCLevelAddr mod 2 = 0 then 
            OutputA <= HI_LVL;
            OutputB <= LO_LVL;
        elsif Trigger = '1' and not DCLevelAddr mod 2 = 0 then 
            OutputA <= LO_LVL;
            OutputB <= HI_LVL;
        end if; 
      end if;
end process;

end architecture;

Hi @roflo ,

It seems like this post is a duplicated post. As I mentioned in the previous post, the warning message shouldn’t cause issue when the MCC is deployed on Moku. Would you mind confirming this point? Thanks.

Dear Hanklong,

Yes ist still the same Problem. And I tried to explain my Problem as understanable as possible.

Maybe is it good to connet Both of my questions.

But the the Problem still remains.

Best Flo

Here the linke to my simular question.

Hi Roflo,

Yes, the clk signal is the clock source on Moku:Go. Here is the link for the information of the clk frequencies on different devices.

https://compile.liquidinstruments.com/docs/slots.html

Yes, it is possible to use counter as a timer in your code. In other words, on Moku:Go, 31.25 M unstopped counts is 1 second. Thanks.

Best regards,
Hank

Hi your answer introduces tow changes in my code.

constant RESET_THRESHOLD :integer := 31250000;
signal TriggerLowCounter : unsigned(32 downto 0);

ACTIVITY: process(Clk) is
begin
if falling_edge(Clk) then
if Trigger = ‘0’ then
TriggerLowCounter <= TriggerLowCounter + 1;
else
TriggerLowCounter <= (others => ‘0’); – Reset the counter if Trigger is high
end if;
if TriggerLowCounter >= RESET_THRESHOLD then
setback <= ‘1’;
TriggerLowCounter <= (others => ‘0’); – Reset the counter after setting Reset
else
setback <= (others => ‘0’);
end if;
end if;
end process;

Did I understand you correctly?

Hi @roflo ,

Thank you for your prompt feedback.

I feel the code changes you have made should be able to do what you wanted. However, I would recommend you to use the same signal types in your codes just for code sanity, i.e., it would be better to change RESET_THRESHOLD to unsigned type.

Thank you very much for your efforts.

Best regards,
Hank

Hi @hanklong,

I try it. But the code for the alternation is only running If I use the system variable Reset as replacement for setback. But in this case the LO-Signal reset don‘t work.

Do you have any idea how I can fix it?

Hi @roflo ,

In your codes, there are several issues:

  1. You are trying to assign the values to the signal “setback” in two processes, “ACTIVITY” and “ALTERNATION”. And you might have noticed that, “ACTIVITY” is trying to set “setback” to ‘1’ when “TriggerLowCounter” is larger than "RESET_THRESHOLD ", but “ALTERNATION” is trying to set “setback” to ‘0’ when “setback” is high. In other words, you could NOT assign the correct value to “setback” correctly.

  2. You mentioned that you wanted to check the falling edge on the input signal. But your code is actually checking the rising edge. The “Step” is high only when “Trigger” is high and “TriggerDly” is low.

Step <= Trigger and not TriggerDly;

My recommendations are:

  1. Don’t drive one signal in two processes. It will cause issue in your experiment.
  2. Use a control register to reset the “setback” signal, instead of letting it reset itself.

Thanks,
Hank

Hi @hanklong,

thank you, for your suggestions. I would like to avoid an external devices for the control register. Could you send me an example how do you mean your suggestion 2.) in vhdl code?

Best,
roflo

Hi @roflo ,

Sorry for this late reply. Control register is actually a type of input ports in MCC, you can configure the control registers in the Moku app interface. This link can be helpful:
https://compile.liquidinstruments.com/docs/controls.html#control-registers

You can use one bit of the control register as reset, when that bit is high, then reset “setback” to ‘0’, otherwise, maintain “setback” as its current value. For example, the following code gives you the ability to reset your program. After you reset the “setback”, the program will be able to initiate another round of on/off switch and stop after 1 second wait.

Please note that this program might automatically stop (setback = ‘1’) if it doesn’t receive valid signals within 1 second.

Reset <= Control0(0);
ACTIVITY: process(Clk) is
begin
    if falling_edge(Clk) then
        if Reset = '0' then
          setback <= '0';
        else
        if Trigger = '0' then
          TriggerLowCounter <= TriggerLowCounter + 1;
        else
            TriggerLowCounter <= (others => '0'); -- Reset the counter if Trigger is high
        end if;
        if TriggerLowCounter = RESET_THRESHOLD then
             setback <= '1';
             OutputA <= LO_LVL;
             OutputB <= LO_LVL;
             TriggerLowCounter <= (others => '0'); -- Reset the counter after setting Reset
        end if;
      end if;
     end if;
end process;

Hi @hanklong,

Thank you for the insperation. Out of my understanding, the Control Register are associated with the DIO Input/output of the Moku:Go. In your exsample is control0(0) that mean there is no 3.3V Signal on the 1 Pin of the DIO Port?

For later Applications I need to Handel 2 Analog Inputs and the Control Register Input.
Is this possible in general? And how I have to configurate Slot before I can run the bitstream on it?

Best Rollo

Hi @roflo ,

The Control Register isn’t connected to the DIO, it is actually a manual setting in Moku app interface. I have attached two screenshots to this reply:

Please click on this three-dot icon. Then you will see the available Control Registers to control your program. In the example code I provided above, I was using the LSB of Control0 to reset the program.

Hi @hanklong,
thanks you for your advice. Currently I don’t understand the sense of the control register. Do you have any additional information to learn more about the usage of the control register?

best roflo

Hi @roflo ,

The control registers are just registers for you to interact with the MCC program. For example, the following line could allow you assign the least significant 16-bit value of Control0 to OutputA:

OutputA <= Control0(15 downto 0);

In your code, the ‘setback’ was set to ‘1’ to disable the MCC program. You can write a simple line to reset ‘setback’ after it is activated. In this way, you will be able to keep the MCC program disabled until you use the control registers to reset ‘setback’. This is a simply example code:

reset <= Control0(0);

process(clk) is
begin
if rising_edge(clk) then
if reset = ‘0’ then
setback <= ‘0’;
else
setback <= setback;
end if;
end if;
end process;

Best regards,
Hank