QEI 32bit for STM32F103C8

Working libraries, libraries being ported and related hardware
Post Reply
User avatar
mikikg
Posts: 10
Joined: Tue Mar 07, 2017 4:08 pm
Location: Serbia
Contact:

QEI 32bit for STM32F103C8

Post by mikikg » Tue Mar 07, 2017 4:19 pm

Hello,

I need to interface optical quadrature encoder (QEI, 2000 division per turn) to STM32F103C8.
I need HW supported for QEI, means to detect pulses as fast as possible.

Is there some library for that or any advice how to do that?

Tnx in advance.

zmemw16
Posts: 1156
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: QEI 32bit for STM32F103C8

Post by zmemw16 » Wed Mar 08, 2017 12:42 am

ain't google wonderful
search
optical quadrature encoder (QEI, 2000 division per turn)
https://www.google.co.uk/url?sa=t&rct=j ... vdWSBL78Vg

User avatar
mikikg
Posts: 10
Joined: Tue Mar 07, 2017 4:08 pm
Location: Serbia
Contact:

Re: QEI 32bit for STM32F103C8

Post by mikikg » Wed Mar 08, 2017 2:23 pm

@zmemw16

Thank you for the info.

User avatar
mikikg
Posts: 10
Joined: Tue Mar 07, 2017 4:08 pm
Location: Serbia
Contact:

Re: QEI 32bit for STM32F103C8

Post by mikikg » Thu Mar 09, 2017 4:55 pm

I found one example in ~/Documents/Arduino/hardware/Arduino_STM32/examples/Sensors/HardTimerAsEncoder/HardTimerAsEncoder.ino

In general this work.

I have one practical question, what to do with "Index" input, I see in code that this input is not handled, and on other side I notice that losing steps is possible and without handler for Index input, error will accumulate over time, question, is it good practice to reset step counter when Index pulse arrive (via ISR)?

I suppose when using Index input to reset counter will at least leeds to smaller error which may occurs in one full revolution of encoder.

Is there maybe some example for encoders with Index support?

BTW: Currently for testing I'm using Toky HY38A6-P4AR-2000 encoder
http://www.klaesb.com/catalogue/251a82f ... a307e1.pdf

User avatar
mikikg
Posts: 10
Joined: Tue Mar 07, 2017 4:08 pm
Location: Serbia
Contact:

Re: QEI 32bit for STM32F103C8

Post by mikikg » Fri May 05, 2017 5:01 pm

Hi again,

what is the fastest possible equivalent code for this function for TIM2 methods:

Code: Select all

void z_idx_isr_func() {
  timer.setCount(0);
  if (timer.getDirection()) {
    ints--;
  } else {
    ints++;
  }
}
I need to handle Encoder Z input via ISR and need to execute this function before I get next pulse from encoder, If that is missed strange thing happens : (

stevestrong
Posts: 1139
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: QEI 32bit for STM32F103C8

Post by stevestrong » Fri May 05, 2017 6:19 pm

What do you mean under "equivalent" code?
Simply check what is done within those 2 "timer.x" functions called in the ISR, and replace them with that code.

User avatar
mikikg
Posts: 10
Joined: Tue Mar 07, 2017 4:08 pm
Location: Serbia
Contact:

Re: QEI 32bit for STM32F103C8

Post by mikikg » Sat May 06, 2017 5:58 am

By "equivalent" I mean functional same code but written on some other way to get faster execution.

How I can access directly TIM2 registers without Arduino abstraction layer?

All other code in my program are OK but this single ISR function must be as fast as possible.
Handling Z (Index) input is requirement for my construction, I can't lay on timer overflow and do turns +/- on that ISR, I need to handle physical Z signal in addition to encoder's A/B signal.

BTW: this is the last time I'm using mechanical/optical encoders in may projects, for new project I will probably use one of those magnetic sensors, that is totally new and better approach, I2C/SPI device and readout absolute position ... : )
http://ams.com/eng/Products/Magnetic-Position-Sensors

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest