I have been struggling with a logic problem that seems simple but turns into a mind-bender.
I have a free running counter cycling 0-255 and wrapping around back to zero. So it just keeps counting along, incremented by an interrupt.
I'd like to have a variable software timer generated from this as follows. I have a two bit number set to either 0,1,2,3
when the number is 0 the timer should react at every count (ie all free running counts are valid)
when the number is 1, the timer should react at every other free running count (eg 1,3,5,7,9,11...) or (2,4,6,8...)
when the number is 2, the timer should react every 4 counts-I don't care what the counts are, as long as it divides by4
when the number is 3 , the timer should react every 8 counts
I'd like to not have to reset the free running counter, or add a secondary counter of any sort. I'm hoping to take the freee running count & the two bit number and apply some logic (and,or,xor...) & maybe some shifting operations to determine if a valid time is present in the free running counter. Any thoughts are welcome.