9 years, 4 months ago.

I'm not able to use QEI...

I want to use 7S series by Nemicon. This is my program.

________

  1. include "mbed.h"
  2. include "QEI.h"
  1. define ROTATE_PER_REVOLUTIONS 100

Ticker flipper; Serial pc(USBTX, USBRX); Use X4 encoding. QEI wheel(p30, p29, NC, 624, QEI::X4_ENCODING); Use X2 encoding by default. QEI wheel (p30, p29, NC, 624);

float t; float p; float r; float R;

void flip(){ wheel.getCurrentState();

p = wheel.getPulses(); r = 600*wheel.getPulses()/(ROTATE_PER_REVOLUTIONS*4); R = 600*wheel.getRevolutions();

pc.printf("Pulses: %d\n\r", p); pc.printf("Rotate: %f\n\r", r); pc.printf("Rotate Rev: %f\n\r",R); pc.printf(" \n\r");

wheel.reset(); }

int main() { flipper.attach(&flip, t=0.1); the address of the function to be attached (flip) and the interval

pc.baud(115200); pc.printf(" Hello world!\n\r");

while(1){

}

______

Connections

signal A -> R(1k) -> p30

signal B -> R(1k) -> p29

Vcc -> VU

GND -> GND

I got pulses but always 0. Please give me advices.

Question relating to:

1 Answer

9 years, 2 months ago.

Try printing pulses as %f:

pc.printf("Pulses: %f\n\r", p);