Welcome in the forum.
We usually do not solve your projects by programming them.
But we can give you some hints:
Use a timer/counter (TCPWM) to get your cycle-time of 50ms
Use a second TCPWM and configure the "count" input, connect that to your INPUT.
At tc of the first timer, stop the second one, read its current value,clear counter and start again. Signal your main() infinite loop that a cycle is ready and the new value might be inspected.
You may play a bit with capturing the 2nd counter etc.
thank you for the rapid response!
i'll try it!