Project - FEZ Cerbuino Bee Hardware Encoder Interface

FEZ Cerbuino Bee Hardware Encoder Interface

Reading out encoder positions through software requires a lot o resources and even if it is the only task of the processor, it is likely to miss some pulses if the pulse frequency is too high.

My mission was use a FEZ Cerbuino Bee to interface and display the position of 3 encoders on an LCD display. So it did’n feel it would work correctly unless the encoders were interfaced through a hardware circuit, that fortunately, the STM32F4xx has plenty of.

So I got to work to understand how to get a project to run RLPLite and went on to the ST support site to find out how to configure Timers (TIMs) for encoder interface…

I found that theoretically we can interface up to 6 encoders through (TIM1,TIM2,TIM3,TIM4,TIM5 and TIM8)

In this project, I have implemented 2 Native code functions:
1 - Native_SetEncoder(…) (Sets up encoders 2 to 5)
2 - Native_GetEncoderPosition(…)(Gets Current encoder counter value)

In the Visual Studio Project I call Native_SetEncoder(…) at startup to set up the encoders, and invoke Native_GetEncoderPosition(…) on a timer event.

I then found out that TIM5 is being used by NETMF, perhaps to generate the timer event. so I just activate encoders for TIM2,TIM3 and TIM4.

If you just run this project, you will see on the debug output window the current values of all 4 TIMs:
TIM2: Connected to PA15 and PB3 (Arduino Digital Header)
TIM3: Connected to PC6 and PC7 (Zig Bee Socket)
TIM4: Connected to PB6 and PB7 (Gadgeteer Socket 2)
TIM5: Some continuous counting value

Oh, the encoder inputs are configured with pull ups, so use line driver, npn or push pull encoders, and if you use mechanical switch encoders, connect the common pin to the GND.

OK, that’s it, Enjoy.

Fernando.

3 Likes

Well done. Glad to see good use of encoders.

Video?

Gus, what would it take to get this code into the firmware? Seems like the perfect sort of contribution.

Yeah very nice feature. Let us see how many users need it and used it first. Or someone can actually build in firmware then we can test and make official.

Thanks for sharing, exactly what I need :slight_smile:

Hi Guys,

I’m glad this code is useful, for me it will be!
Gus, A video? I haven’t thought of that. But I’ll try to “produce” something and post it.