SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By torgfromdamorgue
#153106
Hi, I am fairly new to electronics so I need some help to set up my circuits.

I am trying to use this (http://www.usdigital.com/products/encod ... MgeWoNX0Wc) absolute shaft encoder fro US Digital with the Galago microprocessor (http://www.kickstarter.com/projects/kuy ... ngs-better).

I don't really understand how PWM works and which pins I am allowed to use on the galago to get input from the encoder. Dumb question: Can I use a 10 bit device on a 16 or 32 bit i/o? Also the encoder is going to be powered with 5V while the galago operates on 3.3V. I looked at the Cortex-M3 tolerances and it looks like it is 5V tolerant on the input, just can't produce 5V output. This leads me to believe that I can read values from the encoder without having to use a logic level converter.

Any suggestions/Lessons I can look at?

All help will be appreciated

Thanks!
By hsutherl
#153217
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.