Read 2 encoders on VESC

Support for creating custom user applications on the VESC.
clement91190
Posts: 4
Joined: 16 Apr 2017, 10:36
Location: Paris

Read 2 encoders on VESC

Postby clement91190 » 16 Apr 2017, 10:49

Hi,

I'd like to read 2 optical encoders with one VESC board ( one is for the position of the motor itself for sensored FOC and position control and the other for a torque sensor). Position control will be piloted from that secondary encoder to do precise torque control.

They both have GND, A , B and 5V connections, I am wondering how I could connect the second one. I only need the CAN bus. Is there an additional interupt I could use ? Otherwise If I find an I2C encoder, could I reprogram the I2C port to be master ?

Thanks.

rew
Posts: 898
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Read 2 encoders on VESC

Postby rew » 16 Apr 2017, 11:50

The STM32F405 has a timer capable of handling ENCODER inputs. Once you have programmed the timer, the hardware does the rest. To get the current position, you simply read the timer register.

As far as I know the VESC software uses this feature to handle the encoder. This would imply that Benjamin assigned the pins carefully to allow those pins to be routed to the correct timer.

You will need to:
* find a second timer with encoder capabilities. (doable, read the datasheet/reference manual).
* Find if that timer is available on the VESC (read the sources, especially mcuconf.h ).
* Find the pins that this timer can map to.
* Check if those are free on the VESC, or if YOU can MAKE them free.
* If necessary repeat.

clement91190
Posts: 4
Joined: 16 Apr 2017, 10:36
Location: Paris

Re: Read 2 encoders on VESC

Postby clement91190 » 18 Apr 2017, 01:58

I see, why do you recommend that over using interrupt pins ?

rew
Posts: 898
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Read 2 encoders on VESC

Postby rew » 18 Apr 2017, 09:03

An encoder with 600 PPR will have 2400 signal changes per revolution. Running at 10000 RPM, or 166 RPS, that means 400k interrupts per second. So you'll have to process that interrupt in 2.5 microseconds, and have time left to do all the other things that the ESC needs to do.

Save a few registers, process, restore registers can easily add up to a few microseconds. 400k interrupts per second is something that requires looking at the assembly to optimize it into working order.

That's why there is hardware to do this.

clement91190
Posts: 4
Joined: 16 Apr 2017, 10:36
Location: Paris

Re: Read 2 encoders on VESC

Postby clement91190 » 28 Apr 2017, 06:00

Ah I see, I should have added that it will be for slow speed (max 300RPM). Thanks for the tips.


Return to “Custom Applications”

Who is online

Users browsing this forum: No registered users and 1 guest