Did I find a bug in cog_ctr.v?
andrewsi
Posts: 59
So in cog_ctr.v, there's a simulated PLL at the end using this code:
This is checking the 5 CTRMODE bits in the CTRA/CTRB registers, and I think what it's trying to do is ensure that the 3 MSBs are all zeroes, and that at least one of the 2 LSBs is one. In other words, the whole expression is true (and thus the PLL is enabled) when the mode is set to 00001, 00010, or 00011, but not in any other case. This would make sense since these are the three PLL-enabled counter modes.
However, I think the "~&ctr[30:28]" should actually be "~|ctr[30:28]" instead, shouldn't it? The present form is effectively a NAND of those 3 bits, so it's true if any of them are zero, which would enable the fake PLL in all sorts of counter modes where it really shouldn't be. I think it should be the second form (NOR) instead, which would only allow the fake PLL to be enabled when all three bits are zero, but none of the other cases.
Have I made a fundamental error here (which would not surprise me in the slightest), or have I actually found a bug?
always @(posedge clk_pll) if (~&ctr[30:28] && |ctr[27:26]) pll_fake <= pll_fake + {4'b0, frq};
This is checking the 5 CTRMODE bits in the CTRA/CTRB registers, and I think what it's trying to do is ensure that the 3 MSBs are all zeroes, and that at least one of the 2 LSBs is one. In other words, the whole expression is true (and thus the PLL is enabled) when the mode is set to 00001, 00010, or 00011, but not in any other case. This would make sense since these are the three PLL-enabled counter modes.
However, I think the "~&ctr[30:28]" should actually be "~|ctr[30:28]" instead, shouldn't it? The present form is effectively a NAND of those 3 bits, so it's true if any of them are zero, which would enable the fake PLL in all sorts of counter modes where it really shouldn't be. I think it should be the second form (NOR) instead, which would only allow the fake PLL to be enabled when all three bits are zero, but none of the other cases.
Have I made a fundamental error here (which would not surprise me in the slightest), or have I actually found a bug?
Comments
I think you're right. Here's some equivalent code in dig.v
This is a shift register and it only appends a 1 bit when the previous 1 bit has shifted out the top leaving all 0 bits. That's the TRUE case and what you've found is an expression that is SUPPOSED to return 1 when all 0s are found.
Looks like a bug to me.
Out of pure curiousity, how did you find this? It's not something that exactly leaps off the page!
Whew! OK. Glad I asked.
Do you know how much of an Artix-7 50 the P1v uses? And, more to my interest, how long does it take Vivado to compile? I'm too old to do desk checking anymore and the Cyclone V is a real pig - no amount of deodorant is gonna change that. Avnet is selling the eval board for 2 and change. 50k something or others sounds like a reasonable breadboard. Also, what's the link to the github project? I'm not following along this project all that closely.
I fixed the bug in my Master and Altera branches (the two main branches I'm working in), and updated my pull-request to Mindrobots that he still hasn't merged at this time.
I had to fix it in 7 locations in 2 branches, if I counted correctly... I really need to get busy merging the Altera and Xilinx trees together; this one-character change was easy to merge but if we find anything more complicated, or if we add more targets, the amount of work to synchronize source code quickly goes out of hand.
===Jac
The Artix chips do have some additional local clock routes that can be used in more limited circumstances (i.e. not fully global but limited to particular clock regions) but I haven't made any attempt to do floorplanning to minimize consumption of the global clock buffers.
The github project Jac is running is at http://www.github.com/jacgoudsmit/P8X32A_Emulation. It contains only my ISE version with some basic constraints but it seems to run fine. My Vivado version is in a different repository at andrewsil1/P8X32A_Vivado. What's there builds and runs OK, but depending on what I check in it may become temporarily unstable as I play with the constraints more.