10-bit PWM encoder with Galago ARM based microprocessor

Hello torg,

The voltage levels look OK. What you want is a 5V-tolerant pin that can be configured as an input-capture for one of the timers. The Galago overview was nice but didn’t tell me whether any are brought out and I didn’t investigate further. If you don’t have a timer input available you can use a general purpose logic input, but your precision may vary by a few clock cycles from event to event.

I don’t have a tutorial handy but basically you have to set up your timer to “capture” (the time of) both rising and falling edges from your encoder. Most likely you’d have a small routine, probably interrupt-driven, that sets the capture polarity as needed.

Period = current_rising_edge_time - saved_rising_edge-time

Pulse_width = current_falling_edge_time - saved_rising_edge_time

Duty = Pulse_width / Period

There might be complications from timer count roll-over. Or it may turn out that you can just store the variables in a 32 (or 16) bit integer and the subtraction automatically does what you want.