Mux-OR as DFF (Combinational Loops)

195 views
Skip to first unread message

DemocritoBinary

unread,
Jul 6, 2026, 4:32:51 PMJul 6
to FPGAwars: explorando el lado libre
Hola!

Estaba deseando probar los Loops Combinacionales y con el nuevo Icestudio ahora es posible. Me he diseñado dos flip-flops tipo D.

Este es el primero que hice.

Mux_as_DFF.png

Y luego me acordé que se podía simplificar una parte con una puerta OR, quedando así.

logic_dff.png
Adjunto ambos circuitos para quien quiera probarlos. Por otra parte dejo un vídeo adjunto a este post para que Icestudio te permita habilitar los Loops Combinacionales. Recomiendo tener esa opción normalmente deshabilitada, pero si vas a trabajar a propósito con Loops Combinaciones, entonces dale a esa opción.

Saludos.
enable loops.mkv
Logic_DFF.ice
Mux_as_DFF.ice

Carlos Venegas

unread,
Jul 6, 2026, 4:37:08 PMJul 6
to fpga-wars-explora...@googlegroups.com
Muchas gracias Demócrito! si subes el vídeo a youtube lo metemos en el iceTutorial ;)

--
Has recibido este mensaje porque estás suscrito al grupo "FPGAwars: explorando el lado libre" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a fpga-wars-explorando-el...@googlegroups.com.
Para ver este debate, visita https://groups.google.com/d/msgid/fpga-wars-explorando-el-lado-libre/58abc771-2ecd-489e-999a-466f7d71cab8n%40googlegroups.com.

Carlos Venegas

unread,
Jul 6, 2026, 4:52:23 PMJul 6
to fpga-wars-explora...@googlegroups.com
Por cierto me encanta ver aplicado el concepto "físico" de retroalimentación del FF y ver que funciona!

Lo acabo de probar  y funciona muy bien!

DemocritoBinary

unread,
Jul 6, 2026, 5:09:39 PMJul 6
to FPGAwars: explorando el lado libre
Sí, es el típico (o al menos así funciona) flip-flop Set-Reset. Y además no necesita anti-rebotes.

Dejo dos vídeos de YouTube para que lo incluyas en la ayuda, porque hay dos formas de habilitar los Loops Combinacionales.


DemocritoBinary

unread,
Jul 6, 2026, 5:22:11 PMJul 6
to FPGAwars: explorando el lado libre
Ahora que lo pienso, creo que no se les puede llamar DFF (flip-flops tipo D) sino una báscula o quizás en inglés "Latch". No lo he pensado antes...

Creo que por regla general un flip-flop se caracteriza por tener una entrada de disparo que captura la entrada del dato. Y no es el caso.

DemocritoBinary

unread,
Jul 6, 2026, 5:49:51 PMJul 6
to FPGAwars: explorando el lado libre
Ya que estaba con este tema en mi cabeza he decidido convertirlo en un "lach" real.

Este es el esquema.

true dff.png

Si en la entrada "DATA" ponemos un 1 no ocurre nada, pero al dar un flanco o manteniendo en alto la entrada "CLOCK" a la salida queda memorizado ese dato. Y si a la entrada "DATA" ponemos un 0, al dar un flanco o manteniendo en alto la entrada "CLOCK", se pondrá a cero la salida.

Adjunto circuito de prueba.

True_Lach.ice

DemocritoBinary

unread,
Jul 6, 2026, 6:11:50 PMJul 6
to FPGAwars: explorando el lado libre
Donde dije "Lach" quise decir "Latch".
Message has been deleted

Carlos Venegas

unread,
Jul 8, 2026, 1:54:59 AM (14 days ago) Jul 8
to fpga-wars-explora...@googlegroups.com
Algo ha pasado Demócrito y no salen tus imágenes!, reenvía el mensaje que no se ve lo que quieres contar.

Y por cierto gracias por estar probando todas las cosas nuevas y ayudarme a ir sacándolo a la luz, millones de gracias!!

El mié, 8 jul 2026 a las 7:52, DemocritoBinary (<democri...@gmail.com>) escribió:
Si os descargáis la nueva build o wip (no sé si ya estaba antes, me lo explicó ayer Carlos) podréis hacer lo siguiente:

Imagina que tienes este circuito, o crear vosotros uno con una simple AND:

logic_latch.png
Si le dais a la opción "Apio Shell" (1)

graph.png
y si luego escribís en el terminal que os saldrá la palabra "graph" (2) y le dais a "enter", se generará un grafo de vuestro circuito, en este caso sería este:

Captura de pantalla 2026-07-08 001156.png

Dentro de las opciones de la ventana gráfica lo podréis agrandar o empequeñecer y salvarlo como SVG. Por otra parte, si observáis los cables, veréis que conserva los nombres originales de esos pines seguidos de un guion bajo con un alfanumérico aleatorio. Esto es una manera de convivir cómo trabaja internamente sin perder el nombre del cable (que lo podamos identificar y seguir).

Yo he puesto este circuito y puede parecer complejo, pero se puede comenzar con una simple puerta y luego aumentar la complejidad para comprender la perspectiva.

Saludos.

DemocritoBinary

unread,
Jul 8, 2026, 1:56:55 AM (14 days ago) Jul 8
to FPGAwars: explorando el lado libre
Si os descargáis la nueva build o wip (no sé si ya estaba antes, me lo explicó ayer Carlos) podréis hacer lo siguiente:

Imagina que tienes este circuito o crear vosotros uno con una simple AND:

esquema icestudio.png

Si le dais a la opción "Apio Shell" (1)

apio shell.png

y si luego escribís en el terminal que os saldrá, la palabra "graph" (2) y le dais a "enter", se generará un grafo de vuestro circuito, en este caso sería este:

graph.png

Dentro de las opciones de la ventana gráfica lo podréis agrandar o empequeñecer y salvarlo como SVG. Por otra parte, si observáis los cables, veréis que conserva los nombres originales de esos pines seguidos de un guion bajo con un alfanumérico aleatorio. Esto es una manera de convivir cómo trabaja internamente sin perder el nombre del cable (que lo podamos identificar y seguir).

Yo he puesto este circuito y puede parecer complejo, pero se puede comenzar con una simple puerta y luego aumentar la complejidad para comprender la perspectiva.

Saludos.

El martes, 7 de julio de 2026 a las 0:11:50 UTC+2, DemocritoBinary escribió:

Jo mo

unread,
Jul 8, 2026, 12:13:22 PM (13 days ago) Jul 8
to FPGAwars: explorando el lado libre
Hola Democrilto,

Thanks for the detailed explanation!  I didn't know about that new graph command (And all the useful gems hidden inside the 'apio shell').  

That visual output could be handy for following the data flow in parallel with the reading of the main.v code , 

Two comments/questions: 
- If it was easy to implement, will an unfold option be useful or not?. By unfold i mean displaying also what is inside the blocks on the same svg or pdf .

- it could be interesting to be able to copy (in the OS clipboard) the text of a net in the svg displayed directly on that design graph window. (eg: for pasting it in a search box in a text editor,... )

For the implementation of that last function (the text copy in svg, by right clicking), if you find it useful, i may be able to give an hand.


Cheers, and happy icestudio tinkering!


Carlos Venegas

unread,
Jul 8, 2026, 12:31:16 PM (13 days ago) Jul 8
to fpga-wars-explora...@googlegroups.com
The unfold is very easy!! tell you in the afternoon that i'm out now, but you dont' need develop nothing for this ;)

Carlos Venegas

unread,
Jul 8, 2026, 1:53:53 PM (13 days ago) Jul 8
to fpga-wars-explora...@googlegroups.com
The apio shell is an "explorer shell" for new funcionalities or refine current ones.

Unfolding an entire design can result in something "too large" to visualize; Yosys's `flatten` command reduces the design all the way down to logic gates, and an unwieldy design could easily contain over 7,000 nodes.

The most interesting aspect of `apio graph` is the ability to visualize the design module by module.

You can do this by running:

graph -t module_name

The module names must match those generated in `main.v`.

The tool could be further developed, if there is sufficient interest, to make it navigable, automatically generating `apio graphs` as you move through the design.

We’ve added this to the "to-do" list, but it is certainly an interesting idea.

To generate the unfolded view, now is not workint as is with graph you need to use two commands.

1) yosys with flatten:
  apio raw -- yosys -p "read_verilog -sv main.v; flatten; show -format dot -colors 1 -wireshape plaintext -prefix _build/default/graph main"

  2) dot ->  svg:
  apio raw -- dot -Tsvg _build/default/graph.dot -o _build/default/graph.svg

You could find the svg with all unfold design.
 
I extend apio graph for tomorrow  apio graph --flatten ;) could be interesting and plus i think could be usefule a comando @view file (to open svg/pdf/images....) from apio shell in our viewer.

Good afternoon!!


Jo mo

unread,
Jul 8, 2026, 2:38:20 PM (13 days ago) Jul 8
to FPGAwars: explorando el lado libre
Nice Charli,
On my side, just for fun, i quickly played with deepseek and managed to run the second function  "copy text on svg"  by writing the code (see joined .txt)  on the F12 debug console (not a permanent solution). see video

Have a great evening.
icestudio_2026-07-08_20.29.04.webm
textcopy on the svg.txt

Carlos Venegas

unread,
Jul 8, 2026, 2:45:17 PM (13 days ago) Jul 8
to fpga-wars-explora...@googlegroups.com
Cool!! XD

I did the @view and graph --flat tomorrow morning in your home ;)

I'm working integrating my simulation tool in this version of icestudio is very near to be in your hands!!

DemocritoBinary

unread,
Jul 9, 2026, 3:49:51 AM (13 days ago) Jul 9
to FPGAwars: explorando el lado libre
Joaquim, I apologize if what I said sounded defensive. You know I care about you a lot.

Returning to the topic of combinational loops:

Regarding my last post about the Latch, I converted it into a module, assuming it would function like a conventional Latch, and connected them in a chain to create a counter. It doesn't work. I find this interesting, and if I manage to figure out why, I'll let you know, but it seems like one of those "mysteries of science."

DemocritoBinary

unread,
Jul 9, 2026, 3:52:53 AM (13 days ago) Jul 9
to FPGAwars: explorando el lado libre
Excuse the translation (from Google), where I said " You know I care about you a lot  "You know I appreciate you very much".

Jo mo

unread,
Jul 9, 2026, 5:22:36 AM (13 days ago) Jul 9
to FPGAwars: explorando el lado libre
Hola Democrito, 

No problem at all, and i take both sentences with pleasure :-)
And i also appreciate you very much ;-)
Let"s move on guys.

About your issue, in case it helps, few month ago i also had a problem of not working design when inserting a part of that design inside a block.  The problem was that i was entering a 58mhz clock inside a block trough a block input port that had the option "show clock" ticked  .  So i am supposing, my custom clock was not overriding the system clock on this port. Problem solved when "show clock" option unticked!
Your issue is probably different, if you are, not dealing with clocks.
Maybe to really confirm 100% that feedback loop is the problem, try keeping it outside the block?!
Capture.JPG

Big Hug!

DemocritoBinary

unread,
Jul 9, 2026, 10:34:38 AM (12 days ago) Jul 9
to FPGAwars: explorando el lado libre
Hi Joaquim!
I finally found the problem. You can't use latches to create the bits of a counter because latches are transparent as long as the clock is held high. There are workarounds to achieve this, but they require two latches per bit and a configuration known as "master-slave". I studied this many years ago, but I had completely forgotten these details.
The same issue that occurs with the counter would also apply to shift registers, as they need to be edge-triggered (on the rising or falling edge), never operating in latch mode.
I really appreciate your comment and you sharing your experiences with me, as it's another way to learn and keep those insights in mind.
Sending you a big hug!

DemocritoBinary

unread,
Jul 9, 2026, 10:45:25 AM (12 days ago) Jul 9
to FPGAwars: explorando el lado libre
The latch I was using is this one:

Captura de pantalla 2026-07-09 164241.png

DemocritoBinary

unread,
Jul 9, 2026, 12:01:08 PM (12 days ago) Jul 9
to FPGAwars: explorando el lado libre
He conseguido crear un contador (up) con latches maestro-esclavo y funciona perfectamente.

Pondré imágenes que irán de abajo (latch básico) hasta arriba, que será un contador de 4 bits.

latch.png

Ahora pasamos al maestro-esclavo, esto nos permitirá funcionar por flanco de subida en este caso.
master-slave_latch.png
Finalmente, tomamos 4 de estos maestros-esclavos y los unimos en cascada para hacerlos funcionar como un contador de 4 bits (up).
contador.png
Podéis observar que he puesto dos relojes, funciona con ambos igual de bien, tanto si el bombeo es por niveles (0/1), como por tics.

Esta forma de construir un contador creo que se le etiqueta como asíncrono, porque los cambios se propagan y eso requiere un tiempo (aunque muy corto). Lo ideal es una arquitectura síncrona, en el que todos los flip-flops cambian de estado en el mismo instante.

Adjunto circuito por si alguien le interesa este tema o le apetece recordar viejos tiempos.

Un saludo!


4_bits_master-slave_latch_counter.ice

Carlos Venegas

unread,
Jul 9, 2026, 12:04:09 PM (12 days ago) Jul 9
to fpga-wars-explora...@googlegroups.com
Muy interesante Demócrito! desde luego esto es "entender" la raíz del asunto, muy ilustrativo!

--
Has recibido este mensaje porque estás suscrito al grupo "FPGAwars: explorando el lado libre" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a fpga-wars-explorando-el...@googlegroups.com.

Jo mo

unread,
Jul 9, 2026, 1:46:38 PM (12 days ago) Jul 9
to FPGAwars: explorando el lado libre
Hola Democrito,

This logic latch design looks simple but my old brain have some difficulty to understand it ;-)
And i am not alone, my computer too. Just for info, do not waste your time on that if you do not need for yourself!  When i try to build your Alhambra's .ice file (with no changes), 
I am getting, on the output console, the error you can see in the joined .txt file.  So no .bit file generated.

Have a nice evening
4 bits master slave latch counter_build error.txt

Carlos Venegas

unread,
Jul 9, 2026, 1:50:02 PM (12 days ago) Jul 9
to fpga-wars-explora...@googlegroups.com
Joaquim, try activate this in tools->preferences
Captura de pantalla 2026-07-09 a las 19.49.06.png

Jo mo

unread,
Jul 9, 2026, 2:41:08 PM (12 days ago) Jul 9
to FPGAwars: explorando el lado libre
Thanks Carlos, it works now! And i just saw that i missed to look at Democrito's video (on his first post) explaining how to activate this !
Every day, i am discovering a new hidden Icestudio corner ;-)

Carlos Venegas

unread,
Jul 9, 2026, 2:44:31 PM (12 days ago) Jul 9
to fpga-wars-explora...@googlegroups.com
If you check in project section the option is saved in the .ice Democrito probably has the global option activated XD

DemocritoBinary

unread,
Jul 9, 2026, 2:58:33 PM (12 days ago) Jul 9
to FPGAwars: explorando el lado libre
Ups! así es Carlos!

DemocritoBinary

unread,
Jul 9, 2026, 3:11:10 PM (12 days ago) Jul 9
to FPGAwars: explorando el lado libre
Acabo de terminar un micro-tutorial con todo lo que se ha hablado aquí, pero extremadamente simplificado y corregido todos los conceptos erróneos.

He utilizado una IA llamada manus. Aún así he tenido que pulir muchas cosas debido a que no le dí un buen prompt (y me queda mucho por aprender en este sentido, ya que muchas veces tratamos de que nos lean el pensamiento).

Lo he alojado en GitHub: https://github.com/Democrito/latch

Carlos Venegas

unread,
Jul 9, 2026, 3:56:31 PM (12 days ago) Jul 9
to fpga-wars-explora...@googlegroups.com
Que grande! muy bien documentado!! habrá  que moverlo para darle visibilidad!.

Un gran trabajo!!

Jo mo

unread,
Jul 10, 2026, 11:13:40 AM (11 days ago) Jul 10
to FPGAwars: explorando el lado libre
Great tutorial Democrito,

Few weeks ago, i thought that one day, it could be interesting to ask an IA ( like manus or glm5.2) to make a well organized ice-studio Manual. Giving it as input all the contents on this google group + the icetudio+apio github pages!  Than of course, few weeks will be necessary to a real human for cross-checking everything! ;-)  ...We will see...

DemocritoBinary

unread,
Jul 10, 2026, 12:49:42 PM (11 days ago) Jul 10
to FPGAwars: explorando el lado libre
I completely agree with you, Joaquim. For me, documentation is one of the things I struggle with most, and it fills me with immense laziness. If we could give an AI "the sources" to create a summary of an entire thread and turn it into an illustrative/educational document, that would be fantastic. Even though I used an AI, it took me about two hours to get everything the way I thought it should be, and documenting on GitHub isn't exactly the easiest thing in the world.

Thanks for your comment!

DemocritoBinary

unread,
Jul 11, 2026, 5:53:25 AM (11 days ago) Jul 11
to FPGAwars: explorando el lado libre
He actualizado el tutorial (añadido y quitado cosas) sobre los loops combinacionales.

Lo que comenzó como una pequeña tontería personal que quise compartir, me he dado cuenta que quien se dedica a la docencia, al tener la posibilidad de usar loops combinacionales, ahora puede realmente enseñar los principios básicos de la electrónica secuencial usando FPGAs sin tener que estar traduciendo conceptos (porque las FPGA internamente ya tiene su propia forma de funcionar).

Ahora sí que se puede dar fundamentos básicos gracias a tener esta opción el nuevo Icestudio. Creo que a nivel didáctico esto es más importante de lo que parece.

Carlos Venegas

unread,
Jul 11, 2026, 3:16:02 PM (10 days ago) Jul 11
to fpga-wars-explora...@googlegroups.com
Está super el tutorial, se merecería un vídeo tutorial!  en cuanto cierre el tema simulador voy a intentar meter antes de que cerremos release la parte de comunidad, porque quiero que sea muy fácil compartir desde el propio icestudio diseños, tutoriales, vídeos y que podamos hacer crecer mucho más la comunidad.

Un gran abrazo!

DemocritoBinary

unread,
Jul 11, 2026, 4:41:55 PM (10 days ago) Jul 11
to FPGAwars: explorando el lado libre
Gracias Carlos!
Reply all
Reply to author
Forward
0 new messages