Trouble Reading GPIO Pin Value
Posted: Wed Mar 03, 2021 10:31 am
Hi,
I have a system using a MOD54415 where amongst other things has four rotary encoders hooked up to it.
They are connected to pins J1[5] and J1[6], J1[7] and J1[9], J1[10] and J1[13], and J2[45] and J2[47]. They were working fine but the encoders weren't super accurate, so I've been playing around with adding the low pass filter design recommend in the datasheet (part # PEC11R-4215F-N0024), but running it off of 3.3V.
After adding the filter circuits the encoders behaved much better except for the ones connected to the J2 pins and the one on J1 10 and 13. I checked the resistances on the pins and found that the ones that work read at around 1.2Mohm where the ones that didn't read at around 9-10kohm (J2 45, 46, and J1 13).
The netburner wasn't detecting any level change from the encoder connected to the two J2 pins and was only seeing a change in the pin connected to J1[10] not J1[13]. Changing the filter resistor out for a 2kohm on the pins with the lower resistance enabled the netburner to see the level change but it wasn't as accurate.
We were suspecting maybe the slew rate of the pins was too slow, I attempted changing the slew rate of the J1[13] pin via
but I may have not done that correctly as I've never messed around with changing the slew rates before and it didn't change anything.
Would there be something I could be overlooking in the code that I need to enable? I'll include the inits and the encoder logic below.
I could also very well be heading down the wrong path and these differences in resistances that I'm seeing are not the root of the issue.
I changed this around in the code for the system to not use semaphores and tasks for each encoder rather the check task just makes a function call. But functionally they operate the same. The a1-4 variables are declared globally.
Thanks,
Jeremy
I have a system using a MOD54415 where amongst other things has four rotary encoders hooked up to it.
They are connected to pins J1[5] and J1[6], J1[7] and J1[9], J1[10] and J1[13], and J2[45] and J2[47]. They were working fine but the encoders weren't super accurate, so I've been playing around with adding the low pass filter design recommend in the datasheet (part # PEC11R-4215F-N0024), but running it off of 3.3V.
After adding the filter circuits the encoders behaved much better except for the ones connected to the J2 pins and the one on J1 10 and 13. I checked the resistances on the pins and found that the ones that work read at around 1.2Mohm where the ones that didn't read at around 9-10kohm (J2 45, 46, and J1 13).
The netburner wasn't detecting any level change from the encoder connected to the two J2 pins and was only seeing a change in the pin connected to J1[10] not J1[13]. Changing the filter resistor out for a 2kohm on the pins with the lower resistance enabled the netburner to see the level change but it wasn't as accurate.
We were suspecting maybe the slew rate of the pins was too slow, I attempted changing the slew rate of the J1[13] pin via
Code: Select all
sim1.gpio.srcr_fb2 |= 0x03;
Would there be something I could be overlooking in the code that I need to enable? I'll include the inits and the encoder logic below.
I could also very well be heading down the wrong path and these differences in resistances that I'm seeing are not the root of the issue.
Code: Select all
#define P5A 10
#define P5B 13
//P5
J1[P5A].function(PINJ1_10_GPIO); //Channel A input
J1[P5B].function(PINJ1_13_GPIO); //Channel B input
sim1.gpio.srcr_fb2 |= 0x03;
void EncoderCheckTask(void *pd)
{
int lastA1 = J1[P1A], lastA2 = J1[P2A], lastA3 = J1[P5A], lastA4 = J1[P6A];
while(1)
{
a1 = J1[P1A];
a2 = J1[P2A];
a3 = J1[P5A];
a4 = J1[P6A];
if((a1 != lastA1) && (lastA1 == 1))
{
//Rotary encoder turn detected
OSSemPost(&ENCODER_1);
}
else if ((a2 != lastA2) && (lastA2 == 1))
{
OSSemPost(&ENCODER_2);
}
else if ((a3 != lastA3) && (lastA3 == 1))
{
OSSemPost(&ENCODER_3);
}
else if ((a4 != lastA4) && (lastA4 == 1))
{
OSSemPost(&ENCODER_4);
}
lastA1 = a1;
lastA2 = a2;
lastA3 = a3;
lastA4 = a4;
}
}
void TaskEncoderP5(void *pd)
{
int b;
int counter = 0;
while(1)
{
OSSemPend(&ENCODER_3, 0);
b = J1[P5B];
if(b != a3)
{
counter++;
}
else
{
counter--;
}
iprintf("%d ", counter);
}
}
Thanks,
Jeremy