Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 5 months ago. This question has been closed. Reason: Off Topic
QEI.h on LPC1768
Hello guys!
I've learned about QEI and l've tried to check encoder pulses using QEI.h file
Even though my encoder pulses per revolution is 1200, I've just got only 600 pulses per one revolution.
I'm just wondering why I didn't get the 1200 pulses... I just think I've still got X2_ENCODER value not X4_ENCODER value.
So could you check my code and tell me why haven't I got the right values?
Thanks.
Charlie.
---- code-----
- include "QEI.h"
- include "mbed.h"
AnalogIn ain(p20);
PwmOut INA(p21); InputA(Clockwise rotating)
PwmOut INB(p23); InputB(Counterclockwise rotating)
PwmOut PWM(p22); pwm outputs
Serial pc(USBTX,USBRX); tx,rx
QEI Wheel(p13, p14, NC, 1200, QEI::X4_ENCODING);
/* Function prototype */
void motorControl(bool dir, float pwmVal);
int main()
{
int data;
while(1)
{
float i; PWMduty
i = ain;
data = ain *100;
motorControl(1,i); Clockwise rotating
pc.printf("Pulses is: %d PWMduty : %d %% \n\r",Wheel.getPulses(),data);
wait_ms(100);
}
}
This is a motor control function which controls
the speed and direction of a motor
void motorControl(bool dir, float pwmVal)
{
PWM.write(0); Duty cycles are initially zero
PWM.period_ms(1);
if(dir==1) forward direction
{
INA.write(1);
INB.write(0);
PWM.write(pwmVal);
}
else if(dir==0) reverse direction
{
INA.write(0);
INB.write(1);
PWM.write(pwmVal);
}
}