Page 3 of 3

Re: Laser trigger

Posted: January 26th, 2016, 5:33 am
by rojhann
Sure thing!

The password is "mojofpga": https://goo.gl/Bfgib5

There is the project, and a video I took from the led blinking (which shows the value of the counter used in the "distributor", the numbers seem to come in disorder).

Usually, I send a square signal~4Hz (120ms up, 120ms down, etc...) and look at the 1st channel (pin 33). I set the mode to 3 (follow) and then send a sequence (like 43690).

Thanks a lot!

Re: Laser trigger

Posted: February 1st, 2016, 8:44 am
by rojhann
Hey!

Do you think the error could lie else where than in my lucid code?

If the video is accurate, it is very strange that all the numbers will come one after the other but in disorder.

Could some interpreter/compilater be incriminated?

thanks!

Re: Laser trigger

Posted: February 1st, 2016, 5:10 pm
by embmicro
I'm pretty sure I figured out your problem. Try using

Code: Select all

    if(oldTrigger.q == 0 && trigger_sync.q[1] == 1)
      ctr_s.d = ctr_s.q + 1;
instead of

Code: Select all

    if(oldTrigger.q == 0 && trigger == 1)
      ctr_s.d = ctr_s.q + 1;
Metastability is fun!

EDIT: You should also update your flag1-flag4 updates (lines 44-47 in distributor.luc) to use the trigger_sync signal instead. You basically never want to use an unsynchronized input directly.

Re: Laser trigger

Posted: February 2nd, 2016, 9:43 am
by rojhann
I should have thought about this! I remember playing with the trigger_sync, but I never put it in the if. It reassures me that the answer is so simple and elegant.

One question: is it the fact that the output of the two flipflops is more "stable" than the external input that solved the issue?

I have trouble picturing the difference between the metastability that occured when setting to 0 the counter in the "trigger" and when incrementing the counter of such pulses in the "distributor". Although I guess if the trigger counter is set to 0 multiple times, the effect is very similar but that wouldn't be the case in the distributor counter incrementation.

Anyway, it is really amazing! Thanks a lot, again! I'm very fond of those mojo, even though my understanding of electronics is very basic. With this functionnality I can now expand their scope on our set-up. One mojo is already used daily to image samples. ^^

Re: Laser trigger

Posted: February 17th, 2016, 12:18 pm
by embmicro
When you have a few flip-flops to synchronize the signal you just drastically reduce the probability that the last flip-flop will be unstable. If you use the signal directly then any/all the bits of your counter could be unstable causing sporadic values. With a chain of flip-flops even if the first one is unstable, it's likely its output is stable enough for the next one to be stable. There is always a chance that it's not and some instability will sneak through. More flip-flops in the chain reduces the probability but the payoff quickly dies after two.

I had a friend help me run our booth at the Maker Faire one year and he was working on a demo that had some switch inputs to the FPGA. He didn't synchronize the inputs and his FSM was transitioning to states that should have been impossible to get to. He thought the board was bad, the power was bad, servos were bad, etc... We then added some synchronizing flip-flops and boom it works.