Flip-Flop type D

Hi, I need a flip-flop-d, I’m inefficient with logic but I get to a point and I’m stuck.
Not find a Pulse Node in Boolean

I read this but I do not know if it’s what I’m looking for, I suppose there’s something simpler

Hello @cesars!

In digital circurity the D-flip-flop is build with NAND gates (and you buil it like this). NAND gates have boolean inputs. A clock signal in XOD is just a “trigger”. I think it is only a signal to trigger some action but it is not a signal you can measure by value. It is not low or high and has not 3.3 or 5 volts level. It is just a kind of “information” to trigger an event associated with the pin of a node. There are nodes generating pulse signals from special events (e.g. pulse-on-true). The other way around you can try to use the flip-n-times-node (I didn’t make a test if this works for you, so you have to try it :grin:). Set “N” to 1 and the on and off time depending on the maximum speed you want to trigger your D-Flip-Flop. “Set” is the clock input.

It seems like it should be easy to auto-cast a pulse to a boolean and just have it true during the pulse, but a pulse is instantaneous. How do you have a boolean that is only true for an unmeasurably short period of time? In this case, how do you have the clock pulse interpreted as “true” long enough for the flip-flop to lock in the new data value? If you make it true & immediately switch it back to false, do the NAND nodes go to read the changed value & just see “false”?

One work-around in this case would be to create a NAND patch that has a pulse for one of its inputs and only sets its output when pulse is dirty (ignoring changes to other inputs).

Thanks for the answers.
The nand do not seem to be the solution, in XOD I’m not achieving the goal.
At least for now …
I added two defer for the latch, but I do not get out of there. I’m looking for other alternatives

Can you use the buffer node? It is for numbers, but there is auto-casting between boolean and numbers. It will only update output when you pulse the UPD pin, which I think is exactly what you are trying to do with the D flip-flop.

You are a genius :grinning: , I have achieved something that will be very helpful

thanks

1 Like

To do something optimal should be with C++, I found the following but I do not know how to implement it. I understand very little about C++ :confounded:

You need a class to represent the flip-flip, you need to keep track of
three things, the current state of the flip-flip, the current state of
the input data, and the current clock state. Three bool variables will do.

Then you need a method the tell the flip-flip that the input data has
changed, it should look something like this

void setInput(bool input)

and a method to signal a change in the clock

void clock(bool clock)

and lastly some way to read the state from the flip-flop

bool getState()

but in XOD …Flip-Flop code

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    bool oldState = getValue<output_MEM>(ctx);
    bool newState = oldState;
    bool olddata = getValue<input_DATA> ???

    if (isInputDirty<input_TGL>(ctx)) {
        newState = !oldState;
    } else if (isInputDirty<input_DATA>(ctx)) {
        newState = true;
    } else {
        newState = false;
    }

    if (newState == oldState)
        return;

    emitValue<output_MEM>(ctx, newState);
}

Existing flip-flop has TGL/SET/RST pins (toggle, set to true, reset to false). If TGL, swap the state; else if SET (not DATA as you have above), set state to true; else (we are here because input changed & TGL/SET didn’t change, so RST did) set state to false.

If you want to change existing flip-flop node to flip-flop-d, you would want an UPD pin of type pulse, and a DATA pin (number would be more generic & should work with boolean input/output). You don’t care what DATA is until you get a pulse on UPD, so the code becomes something like:

if (isInputDirty<input_UPD>(ctx)) {
emitValue<output_MEM>(ctx, getValue<input_DATA>(ctx));
}

And this is what the buffer node does…

yes, the idea was to use some code to create the D

:+1:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.