Outputting a pattern at up to 2MHz
I'm working on a project and I need to be able to output a specific pattern of highs and lows on multiple pins at the same time, with a different pattern on each pin. The patterns will always be the same, but the speed of the pattern needs to be adjustable.
My current code is similar to this:
repeat outa[16..18] := %000 waitcnt(cnt+=delay) outa[16..18] := %001 waitcnt(cnt+=delay) outa[16..18] := %010 waitcnt(cnt+=delay) outa[16..18] := %100 waitcnt(cnt+=delay)
I was attempting to use a delay variable to adjust the time in between state changes, therefore adjusting the output frequency. The issue I'm having is that, with waitcnt, the "delay" variable is not able to be smaller than "425" since the waitcnt takes too many clock cycles to process. If I remove the waitcnt line all together, the frequency of the state changes is only 100KHz.
I'm running at 80MHz and want to be able to output this pattern as fast as 2MHz, but as slow as 40KHz depending on the delay that I choose.
How can I rewrite this code to satisfy my requirements?