cancel
Showing results for 
Search instead for 
Did you mean: 

use Wheel Coders to get position information with timers input channels

aloui
Associate II
Posted on April 17, 2009 at 13:43

use Wheel Coders to get position information with timers input channels

3 REPLIES 3
aloui
Associate II
Posted on May 17, 2011 at 13:09

Hello,

May someone help me on this point:

I'm working in a school project on a 2 wheels robot, and i've chosen to use STM32 to drive the base according to data encoming from higher level processor which orders my card to drive the base anywhere and precisely. So i'm using wheel coders to detect the real movement and i use PID to regulate the movement.

I want to calculate the numbers of ticks generated by a wheelcoder which gives me 2 signals permitting to detect whether we should count up or down.

Is this thing possible directly by hardware? because i need him to calculate the number of ticks (which may increment or decrement according to the input signal) and in regular intervals i want to check it out to calculate the position.

I have 2 wheel coders on my small robot, and i dont want to use an external counter for this, so i want to know how to program the STM32 timers to do this job for me, and how should i connect the pins to the signals coming from the wheelcoders. should i use 2 channels from the same timer for each wheelcoder? and what to do then on the software level.

Any help would be appreciated.

Thanks

aloui
Associate II
Posted on May 17, 2011 at 13:09

Well I have seen some codes on this forum.

But i have some problems with the pins.

My incoders uses 5V as a power supply, so i have to find pins that are 5V tolerent.

I need the USART1 because i need the boot loader and i use it for debugging and other stuff.

I need USART3 also because i need to connect it to a zigbee module.

I need the SPI and CAN links because i need to link my card to another one which will give orders to move.

I need about 6 pins to drives the 2 motors via a H bridge

And I'm using a 48 pins model and I cant use a higher version.

So i have a real shortage of pins.

I managed to get TIM2 CH1 and CH2 for one of my coders, but for the other all i could do is connect it to TIM1_CH1N and TIM1_CH2N.

Can I use this configuration to get the ticks from the second wheel coder?

darcy
Associate II
Posted on May 17, 2011 at 13:09

Hi, judging from parts of your question I'm guessing you haven't finished reading the relevant sections of the STM32 reference manual.

A few steps that should put you on your way...

1. Read the section titled ''Encoder Interface Mode'', which can be found in both the Advanced and Basic Timers sections.

This will answer which pins to connect to - also make sure you use the timer block diagram (start of section) to get an idea about what all the TI1FP1 type names are referring to. Use TIMx channel 1 & 2

2. Pull up the datasheet for the encoder which will tell you what the recommended h/w is (e.g. pull-up/down, recommended values etc)

3. Search this forum for ''encoder'' - which is really the first thing you should have done before posting ;) You will find (with just a few minutes searching) at least one cut/paste working example. Make sure you have the STM32 FW Library as that will speed up your dev time substantially - especially when starting out.

The STM32 can keep count of the pulses for you (in h/w) and all you need to do is read the CNT register of a timer. The encoder section in the RM will tell you about this..