Hola a todos! he estado implementando el documento de Jesús, la verdad que los resultados me han sorprendido, el reloj es bastante "limpio" tengo que hacer más pruebas pero me ha parecido más preciso que el PLL de la FPGA (hay que medirlo bien pero visualmente lo parece).
También agradecer a Demócrito los enlaces,siempre tener referencias es super interesante así que millones de gracias por la info, tenemos que hacer un repo de enlaces para que no se desperdigue la información XD pero bueno eso es otra batalla.
Volviendo a nuestros anillos, he hecho las pruebas con la Alhambra II, para que más usuarios podáis probarlo si queréis, aunque mañana haré pruebas con la icecream y alguna otra placa que llevan la ice40 por ver como se comporta en cada una.
He implementado un ripple counter de 3 bits para dividir el reloj generado por 2,4 u 8, suficiente para cubrir aparentemente la máxima velocidad medida por Jesús (en el mejor de los casos en torno a 700Mhz que podríamos medir con el divisor de 8, entorno a 87Mhz, algo ya asumible por un osciloscopio de 100Mhz).
He hecho de momento solo dos tests uno con un ring oscilator con un buffer de 4 ff, en este caso la medida se aproxima mucho al documento de Jesús, os adjunto la captura (20Mhz detectados por el osciloscopio en continuo lo que quiere decir que dentro el oscilador en anillo va a 160Mhz aproximadamente, lo que cuadra bastante con la gráfica de Jesús):
La siguiente prueba he bajado el número de buffers a 1 (máxima frecuencia), aquí el osciloscopio muestra entorno a 58Mhz (oscila un poco 55-58-60) lo que vendría a significar una frecuencia del oscilador en el peor de los casos de 440Mhz, posiblemente no llego a la velocidad de Jesús porque en mi ejemplo no se pueda llegar a una frecuencia mayor, esto haré pruebas y quitaré el anillo para ver sin loops que análisis de tiempos da y ver si cuadra pero tiene buena pinta la verdad:
Para el que quiera apuntarse a este fiesta y no sepa por dónde empezar os paso estos tres ejemplos sencillos para Icestudio. Ahora mismo parte del proceso (generar el bitstream y flashearlo) hay que hacerlo desde línea de comandos, pero voy a cerrar unas mejoras que andaba preparando para poder pasar parámetros personalizados en icestudio, así que si os parece bien lo voy a preparar para que con este ejercicio de paso me valga para testear bien la funcionalidad (2x1! alguien da más? :) )
1) ring0.ice , este ejemplo sólo contiene el ripple counter (es un simple contador pero con la peculiaridad que los relojes de cada flip flop son la salida del anterior. En vez de implementarlo en verilog lo he hecho con bloques porque es algo muy sencillo y para educación queda muy visual. En este ejemplo símplemente con el pin SW2 hacéis de reloj y vais a ir viendo avanzar el contador en los leds. Este ejemplo funciona directamente desde Icestudio.
2) ring1.ice, este ejemplo libera el reloj ddel ripple counter del botón y utiliza directamente el de la alhambra II (12Mhz), tenéis que pulsar el sw2 para que funcione (reset) se encenderá el led6 y todo arrancará. Para visualizar este ejemplo debéis conectar el osciloscopio, podéis hacerlo al pin D1, al D2 o al D3 (o al D13 que contiene el reloj de 12Mhz por referencia). El D1 es el reloj del sistema dividido por 8 , el D2 por 4 y el D3 por 2, funciona perfecto. Esto es un ejemplo del ripple counter bajo un reloj real y que me valiera como prueba de que obtendrá algo con cierta exactitud (la verdad que a 12Mhz las medidas salen clavadas), este ejemplo funciona directamente desde Icestudio.
3) ring2.ice, aquí ya está el oscilador en anillo, el ejemplo funciona como el 2) (los pines para medir con el osciloscopio) y en el diseño podéis cambiar el número de buffers del anillopor si queréis probar. Este ejmplo requiere de momento de ejecución de comandos fuera de Icestudio, ahora os explico.
Para probar este último ejemplo, lo que tenéis que hacer es con icestudio darle a sintetizar, esto generará parte de los ficheros necesarios en la carpeta ice-build donde tengais el .ice.
Luego os vais y abrís un termina. os vais dentro de la carpeta ice-build correspondiente y tendréis que ejecutar a mano:
RUTA_OSS_CAD_TOOL/nextpnr-ice40 --hx8k --package tq144:4k --json hardware.json --asc hardware.asc --ignore-loops --pcf main.pcf
RUTA_OSS_CAD_TOOL/icepack hardware.asc hardware.bin
RUTA_OSS_CAD_TOOL/iceprog hardware.bin
RUTA_OSS_CAD_TOOL es la ruta a la carpeta de usuario de icestudio y luego depende del sistema operativo una ruta similar a la que os pongo:
~/.icestudio/apio/packages/tools-oss-cad-suite/libexec
esa es mi ruta en mi linux, pero seguro que con esto podéis encontrarla sin problemas, y si no preguntad y os ayudamos.
Se me acumula el trabajo 😅 pero esto está siendo muy divertido, estos días intentaré mezclar unas cosas que ando trabajando del PAL y del PET con esto y así vamos avanzando todos los temas a la vez.
Un abrazo a todos!
ENGLISH::
Hello everyone!
I've been implementing Jesús's document and the results have really surprised me. The clock is quite "clean". I need to do more tests, but it seems more precise than the FPGA's PLL (this needs to be measured properly, but visually it seems so).
I also want to thank Demócrito for the links. Having references is always super interesting, so many thanks for the info. We need to create a repository of links to keep the information organized, but that's another battle.
Going back to our rings, I did the tests with the Alhambra II, so more users can try it if they want. Tomorrow, I'll test it with the Icecream and some other boards that use the ice40 to see how it behaves on each.
I implemented a 3-bit ripple counter to divide the generated clock by 2, 4, or 8, which is enough to apparently cover the maximum speed measured by Jesús (in the best case around 700 MHz, which we could measure with the 8-divider at around 87 MHz, something manageable by a 100 MHz oscilloscope).
So far, I've only done two tests. One with a ring oscillator with a buffer of 4 flip-flops. In this case, the measurement closely matches Jesús's document. I attach the capture (20 MHz detected continuously by the oscilloscope, which means the ring oscillator is running at about 160 MHz, which fits well with Jesús's graph):
![IMG_2210.JPG](https://groups.google.com/group/fpga-wars-explorando-el-lado-libre/attach/3a20888925e09/IMG_2210.JPG?part=0.0.3&view=1)
In the next test, I reduced the number of buffers to 1 (maximum frequency). Here, the oscilloscope shows around 58 MHz (oscillates a bit between 55-58-60), which would mean the oscillator's frequency, in the worst case, is 440 MHz. I might not reach Jesús's speed because my example might not achieve a higher frequency. I will test and remove the ring to see the timing analysis without loops and see if it matches, but it looks promising:
![IMG_2211.JPG](https://groups.google.com/group/fpga-wars-explorando-el-lado-libre/attach/3a20888925e09/IMG_2211.JPG?part=0.0.4&view=1)
For anyone wanting to join this adventure and doesn't know where to start, here are three simple examples for Icestudio. Right now, part of the process (generating the bitstream and flashing it) needs to be done from the command line, but I'll finish some improvements I was preparing to allow passing custom parameters in Icestudio. So if it’s okay with you, I'll prepare it so that this exercise can also be used to test the functionality well (2x1! Who offers more? :) )
1) ring0.ice: This example only contains the ripple counter (it's a simple counter, but with the peculiarity that each flip-flop’s clock is the output of the previous one). Instead of implementing it in Verilog, I did it with blocks because it's very simple and visually educational. In this example, you simply use the SW2 pin as the clock and see the counter advancing on the LEDs. This example works directly from Icestudio.
2) ring1.ice: This example frees the ripple counter clock from the button and directly uses the Alhambra II's clock (12 MHz). You need to press SW2 to start it (reset), LED6 will light up, and everything will start. To visualize this example, you need to connect the oscilloscope. You can do this to pin D1, D2, or D3 (or D13, which contains the 12 MHz reference clock). D1 is the system clock divided by 8, D2 by 4, and D3 by 2. It works perfectly. This is an example of the ripple counter under a real clock and served as a test to see if it gets something accurately (at 12 MHz, the measurements are precise). This example works directly from Icestudio.
3) ring2.ice: Here is the ring oscillator. The example works like
ring1.ice (pins for measuring with the oscilloscope), and you can change the number of buffers in the ring if you want to test it. This example currently requires running commands outside of Icestudio. Here's how to do it:
To test this last example, you need to synthesize it with Icestudio, which will generate part of the necessary files in the
ice-build folder where the
.ice file is located.
Then, open a terminal, navigate to the corresponding
ice-build folder, and execute manually:
PATH_TO_OSS_CAD_TOOL/nextpnr-ice40 --hx8k --package tq144 --json hardware.json --asc hardware.asc --ignore-loops --pcf main.pcf
PATH_TO_OSS_CAD_TOOL/icepack hardware.asc hardware.bin
PATH_TO_OSS_CAD_TOOL/iceprog hardware.binPATH_TO_OSS_CAD_TOOL is the path to the Icestudio user folder and then depends on the operating system, something similar to what I put here:
~/.icestudio/apio/packages/tools-oss-cad-suite/libexecThat's my path on Linux, but with this, you should find it without problems, and if not, ask and we'll help you.
Work is piling up 😅 but this is very fun. These days I'll try to mix some things I'm working on with the PAL and the PET with this, and we'll advance everything together.
Hugs to everyone!