Bug fix for reset problem
cgracey
Posts: 14,155
In the cog.v file, there are problems in the assignments to the outa and dira registers, apparently.
I'm not at my computer right now, but from what pik33 posted, the dira and outa assignments need to be changed to:
The ena signal must be used to reset outa and dira. I don't know how I missed this on the AHDL-to-Verilog translation. I'll update the main files when I get back from DEFCON.
I'm not at my computer right now, but from what pik33 posted, the dira and outa assignments need to be changed to:
always @(posedge clk_cog or negedge ena) if (!ena) outa <= 32'b0; else if (setouta) outa <= alu_r; always @(posedge clk_cog or negedge ena) if (!ena) dira <= 32'b0; else if (setdira) dira <= alu_r;
The ena signal must be used to reset outa and dira. I don't know how I missed this on the AHDL-to-Verilog translation. I'll update the main files when I get back from DEFCON.
Comments
Great, thanks Chip, I'm just getting stuck into the P1 emulation now and just hooked up an EEPROM (actually I bridged another Prop board) so I will give this a go.
Edit: compiled and tested ok with clk_cog as below:
That's right!
Thanks for pointing this out. I'm going to correct my first post.
http://forums.parallax.com/showthread.php/156860-Here-are-the-files-needed-for-running-P8X32A-on-the-BeMicroCV?p=1285152&viewfull=1#post1285152
When I revert to this fix:
With this fix, the Nano works as expected (F7 and F10 work repeatedly)
I don't really want to commit the "unofficial" fix even though it works if there will be a fixed "official" fix at some future point. Doing that would just lead to two slightly different sources floating around.
Can anyone else confirm or deny the working of the "official" fix?
The actual P8X32A chip only hard resets the DIRA register. OUTA gets reset during loading, being written with a zero. It doesn't make sense to my why OUTA should need to be hard reset. It's the DIRA that must be immediately reset on a cog stop or chip reset, to free the pins. Once DIRA is zeroed, it doesn't matter what OUTA holds.
It doesn't hurt anything to reset both DIRA and OUTA, though. It just shouldn't be necessary to do OUTA.
But surely if my program wakes up from reset it may well set DIRA to output in the expectation that the OUTA is low until told otherwise. Which could be some time later. Driving a HIGH out when not expected might lead to bad outcomes.
OK, wait, you said OUTA is set during loading which is before my program can set DIRA I presume.
Thank you for the explanation - we need to collect this wisdom in a book for the P1V architecture class.
My immediate concern was that resetting just DIRA in the FPGA left me with a dead Nano while resetting both left me with a properly functioning Nano. I may have messed up my build process so I was hoping someone could test the DIRA only fix to see if it is me or if it is the fix that broke my version of this .jic file.
I was going to put the "offical" fix into my GitHub repository and roll it up to Heater's but don't want to do that until it is independently tested.
I'm going to review the reset sequence this morning. I might have over-simplified something in there when doing the translation.
Thank you!
Later, when review happens, say Chip finds out he did oversimplify. It's very highly likely a few files get touched. So then that gets done, and the history rolls forward.
Sometime in the future, people would see the initial repo, heater doing tab cleanup, you pushing the bug fix, then a more complete fix later on.
When it's deemed "Good", then a tag can be added.
And we've not yet discussed revisions!! Which revision or version is this?
I think it should be something like 1.0, initial release from Parallax.
When the big fix is complete, then perhaps that's version 1.1, reset issue fixed up proper.
etc...
Since then tabs have been removed and README's changes a bit maybe but there is no new version. No reason to be.
One could tag all significant releases or fixes or whatever like "Reset bug fix". Not very meaningful though. There may be a hundred reset bug fixes in the future.
I guess we don't need to resolve that now either. Use dates, until such time as a better nomenclature makes sense.
At the end of the day any user of your stuff does not care if major numbers mean new features were added and minor numbers were bug fixes only, or major numbers mean you broke it by changing the API, or whatever.
What they do care about is that they had a version that they used and it worked and they would like to be able to find it again.
They certainly don't want to go back to older versions than the one they have tried and tested.
They may be willing to try newer versions, as long as they can go back to the old one when you break it in an update.
So, any orderable, monotonically increasing version identifier will do.
I used the date there because who am I to say this is version 0.0.1 or 1.0.0 or whatever? No it was released on that historic day. So that is what I called it.
I looked through the reset circuitry and it seems to be fine. I don't know why you're having this problem. Could you please mail your cog.v file to my forum account? How about the one that works and the one that doesn't work? I don't know what else to check. Thanks.
That section in cog.v should be:
Probably not!
I had lost these lines somewhere along the line: which led to the confusing discussion about OUTA not needing to be cleared.
I cut and pasted too much when going from the first fix with two always blocks to you final fix which was just a replacement for the second always block.
I will rebuild correctly and report back.
(This is a good case for a problem with forum snippets)
Works for me on the DE2-115.
Your *COMPLETE* patch works fine.
I'll go sit in the corner for a while. Sorry I wasted your time.
Thanks!
I used the same cog.v file but just commented out the outa reset code and rebuilt to test and it failed. UN-commented outa reset code, rebuilt and its its OK
Ron
Ron
It got confusing the first fix - provided by Chip and Pik33 had 2 always blocks; one for OUTA and one for DIRA, the original code also had two blocks so it was an easy cut and paste replacing the two blocks with two new blocks.
The "official code provided by Chip in the BE-micro thread just have one always block for DIRA. So I put the one block in place of the two blocks and that caused OUTA to never be reset.
When Chip posted his entire code section in post #20 of this thread, showing the section comment, the two reg statements and the two always blocks, it dawned on me what I had messed up in cutting and pasting the snippets from the various threads.
If you take the code from post #20 and use it to replace the entire "// outa/dira" section in cog.v, you should be in good shape.
I'm building BE-micro and DE2 now for testing.
Ron
I just tried:
Edit | Replace Tabs With Spaces
And it literally replaced tabs ($09) with spaces ($20), on a one-to-one basis, without preserving the indention levels by using variable numbers of spaces. I don't see any other options in Quartus. Is there another way that you know of?
I've always wished that some character (like $1F) would be an escape function where the following byte would determine the number of spaces to spit out. That would make text files really compact.