# 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

**URL:** <https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892>\
**Category:** Moku Cloud Compile\
**Created:** [January 31, 2024, 3:58pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892 "2024-01-31T15:58:38Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [January 31, 2024, 3:58pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/1 "2024-01-31T15:58:38Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![hanklong](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/hanklong/32/288_2.png) [@hanklong](https://forum.liquidinstruments.com/u/hanklong)\
**Post date:** [January 31, 2024, 5:38pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/2 "2024-01-31T17:38:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [January 31, 2024, 7:29pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/3 "2024-01-31T19:29:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [January 31, 2024, 7:32pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/4 "2024-01-31T19:32:44Z")

</div>

Here the linke to my simular question.

> [@Signal Reset \<= '1' if Input A signal is constant for one second](https://forum.liquidinstruments.com/t/signal-reset-1-if-input-a-signal-is-constant-for-one-second/888/7):
>
> Hi hanklong, It is good to know. But the problem I have remains. Maybe it is an understanding problem on my side when I run a Clk process. 1.) clk is the internal clock of the Moku Go box right? If this is the case then the individual processes are run in MHz frequency or ? so it should be possible to count the number of times in which the signal in Inputs 0 can be used as an If Else condition? Best roflo

---

<div class="post-metadata">

**Author:** ![hanklong](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/hanklong/32/288_2.png) [@hanklong](https://forum.liquidinstruments.com/u/hanklong)\
**Post date:** [January 31, 2024, 9:28pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/5 "2024-01-31T21:28:38Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [February 1, 2024, 10:55am UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/6 "2024-02-01T10:55:53Z")

</div>

> [@hanklong](#):
>
> 31.25 M

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?

---

<div class="post-metadata">

**Author:** ![hanklong](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/hanklong/32/288_2.png) [@hanklong](https://forum.liquidinstruments.com/u/hanklong)\
**Post date:** [February 2, 2024, 3:31am UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/7 "2024-02-02T03:31:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [February 2, 2024, 8:55am UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/8 "2024-02-02T08:55:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hanklong](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/hanklong/32/288_2.png) [@hanklong](https://forum.liquidinstruments.com/u/hanklong)\
**Post date:** [February 2, 2024, 9:40pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/9 "2024-02-02T21:40:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [February 5, 2024, 9:28am UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/10 "2024-02-05T09:28:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hanklong](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/hanklong/32/288_2.png) [@hanklong](https://forum.liquidinstruments.com/u/hanklong)\
**Post date:** [February 8, 2024, 5:31am UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/11 "2024-02-08T05:31:14Z")

</div>

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](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.

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [February 8, 2024, 8:19am UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/12 "2024-02-08T08:19:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hanklong](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/hanklong/32/288_2.png) [@hanklong](https://forum.liquidinstruments.com/u/hanklong)\
**Post date:** [February 8, 2024, 6:10pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/13 "2024-02-08T18:10:00Z")

</div>

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:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/liquidinstruments/original/1X/6201e35269e64971fb92f78a02f6f2873780fbf6.png)

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.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/liquidinstruments/original/1X/d3ecfaa347a5d4f09536a80476716d49b7859f83.png)

---

<div class="post-metadata">

**Author:** ![roflo](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@roflo](https://forum.liquidinstruments.com/u/roflo)\
**Post date:** [February 12, 2024, 12:42pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/14 "2024-02-12T12:42:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hanklong](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/hanklong/32/288_2.png) [@hanklong](https://forum.liquidinstruments.com/u/hanklong)\
**Post date:** [February 15, 2024, 11:17pm UTC](https://forum.liquidinstruments.com/t/the-code-implements-a-trigger-based-laser-alternation-using-moku-go-where-a-falling-edge-on-the-cameras-fire-pulse-initiates-alternation-between-outputa-and-outputb-the-process-involves-setting-trigger-outputa-and-outputb-to-0-or-lo-lvl-after-a-certa/892/15 "2024-02-15T23:17:52Z")

</div>

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
