Well.. seems I spoke too soon. I can read changing position values on eQEP2, but it will very often miss increments, record multiple or in the wrong direction. The same encoder and (3.3V) de-bounce circuit works perfectly when connected to DIO 0 an 1 using the encoder library in Bela. I get the same bad behavoir from eQEP2 when I repeatedly do cat /sys/devices/platform/ocp/48304000.epwmss/48304180.eqep/position or if I use the code below (eqep.h is the same code you linked to here. The code I am running is this
#include "eqep.h"
float gInterval = 0.1;
float gSecondsElapsed = 0;
int gCount = 0;
eQEP eqep2(eQEP2, eQEP::eQEP_Mode_Absolute);
std::string thePath = "/sys/devices/platform/ocp/48304000.epwmss/48304180.eqep";
bool setup(BelaContext *context, void *userData)
{
// Set the unit time period to 100,000,000 ns, or 0.1 seconds
eqep2.set_period(100000000L);
return true;
}
//bool gButton;
int position;
int new_position;
void render(BelaContext *context, void *userData)
{
for(unsigned int n=0; n<context->digitalFrames; n++){
gCount++;
if(gCount % (int)(context->audioSampleRate*gInterval) == 0) {
gSecondsElapsed += gInterval;
//new_position = eqep2.get_position();
FILE *fp = fopen((thePath + "/position").c_str(), "r");
fscanf(fp, "%d", &new_position);
fclose(fp);
if(new_position != position)
{
position = new_position;
rt_printf("eQEP2 position %3d\n", position);
}
}
}
}
void cleanup(BelaContext *context, void *userData)
{
}
and the output when I slowly turn the encoder in one direction (EC11 style with detents)
eQEP2 position -1
eQEP2 position 0
eQEP2 position 16
eQEP2 position 15
eQEP2 position 16
eQEP2 position 15
eQEP2 position 16
eQEP2 position 15
eQEP2 position 16
eQEP2 position 14
eQEP2 position 10
eQEP2 position 9
eQEP2 position 10
eQEP2 position 7
I've tried 10k and 2k pullups, both the same. Could it be possible that some other function for those pins is interfering with the eQEP? Any suggestions as to what I should try next to troubleshoot?