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?
Comments
You'll probably want to write that in assembly. You could pass a pointer to your pattern, it's length, and the delay between changes to the assembly cog.
Another possibility is using FlexSpin to compile to assembly.
If you can get by with 1mhz, search for “Arbitrary Pattern Generator”
Maybe I misunderstand the requirements but couldn't this be a variation on this theme?
https://forums.parallax.com/discussion/123170/propbasic-reciprocal-frequency-counter-0-5hz-to-40mhz-40mhz-now