Forum Discussion
Altera_Forum
Honored Contributor
14 years agoI'll need to look at my code to give you a more detailed answer. Here's a quick response that may address some of your questions.
1- I'll look at my code tonight for an example to post. 2- Assuming your add_two.v module runs asynchronously (it is if you're not using a clock), then you need to determine the worst case latency in the calculation. If your clock period is 20ns, but your computation time is 45ns, then you'll need a NOP or pause instruction for 2 additional cycles before you can read the result. The easiest way to compute an entire array would be one byte (or word) at a time using the PIO. The Nios CPU would iterate over each index in the arrays. Write a number to PIO1, write a number to PIO2, then read from PIO3 when the computation is done. As I've said, this may take more than one clock cycle. Also, you would not be taking advantage of parallelism this way, so a custom instruction or Avalon slave component might be necessary for your speed requirements. It's always best to start simple and work your way up. 3- Look in your system.h file or possibly another included header. You'll see a# define for IORD and IORW. Altera just uses these# defs for a shortcut, but if I remember correctly they are merely pointers to your PIO registers hardware address. One other comment - you should probably take advantage of the data types defined in alt_types.h. If your C code is using 32-bit ints, you're writing a 32-bit number to an 8-bit register. This could be causing memory overflow issues if you have another register at the next memory location. I would need to refresh my memory, but isn't the Avalon-MM a 16-bit addressable bus? -J