How to read properly

I have some issues programming a nucleo-STM32F401RE.

  1. When connected to a AMT103-v encoder, the board seems unresponsive. If i disconnect the wires, it works as intended. Checked the wires, everything is ok. What is the main cause of this unresponsiveness?
    This is how i setup it up
    QEI encoder(PG_11, PC_14, PF_2, 2084, QEI::X4_ENCODING);
    This is how i read
    printf(“PULSURI: %d \t\t\t REVOLUTIE: %d \t\t\t INDEX: %d\r\n”, encoder.getPulses(), encoder.getRevolutions(), encoder.getIndex());

  2. I have a setup where a Raspberry PI is connected via wires to the STM32. The raspberry is transmitting the PWM motor values via a PWM signal and the STM32 picks up the values and powers the motor.
    Sometimes, the STM32 is pickup half the values (eg. i send value 20 and the STM reads 10), or sometimes the STM32 generates full power (suddently). I guess the main problem is generated by misreads (noisy rise and falls). Any suggestion on what can i do?

Code:
PwmIn RPIengine(PD_12);
engine.period(0.0002f);

while (true)
{
speed = RPIengine.dutycycle();
engine.write(speed);
}

Hi Bogdan,

I assume that you use additional library because PwmIn and QEI are not in Mbed OS 5.1x.
For the first part of the question are the used pins all DIO pins? I couldn’t find PG_11. I would check those.

For the Pwm read I would add some delay = sleep inside of the while loop. If it does not help I would convert Pwm to analog voltage and use analog input to read the value. And again add sleep to the while loop.

Regards,
Pekka