Forum Discussion
Altera_Forum
Honored Contributor
11 years agoYou have created an array of objects which you selectively increment. It looks like you only increment one of the 128 counters on any given moment. So you created a big mux to supply one argument to the adder, the other argument being fixed to 1, and write the result back. So there is a path from j deasserting to í asserting.
You don't mention the required clock speed so I'm guessing a bit but a 24 bit adder/counter is relatively slow, and the large mux makes that a lot worse. IMO you better instantiate 128 counters which are directly tied to their channel edge detector. The resource usage may/will be larger but it will run a lot faster. If that's not fast enough you'll have to create a faster counter by splitting the counter into smaller parts and generating registered lookahead carries to cascade the split counters. Another option, and closest to the code you have written so far, and if the edges for a each channel are spread wide apart enough you could pipeline your code, putting a register between the 'read' of variable i, incrementing it and writing it back. Yet another option is to use a dual port RAM (M4k or M9k) to hold the variables and write sequential code to read, increment and write back the result into ram. Clearing the results may be an issue though, as you have to cycle through the RAM to do so. This will have the lowest LE usage. Regards, Josy