I want to generate a signal using the Digital In and PWM blocks, then measure the rising edges using the Edge Detector. With the Quadrature Encoder Counter (QEP) on Timer 4, I would like to count these edges and turn on the LED each time a rising edge is detected. Unfortunately, it’s not working, and I’m not sure what I’m doing wrong. Maybe the issue lies in the connections on the board – could you help me correct that?
Thank you for your question!
To count edges, you can use either the Quadrature Encoder Counter (QEP) block, or the Edge Counter block from the STM32 Target Support Package. Is this part of the model working?
To use the Edge Detection block to switch on an LED, the input to the Edge Detection block should be connected to a Digital In block from the STM32 Target Library and the output from the Edge Detection block should be connected to a D Flip-flop or SR Flip-flop to store the edge detection event in memory. The output of the Flip-flop should then be connected to a Digital Out block from the STM32 Target Library to output the signal on the pin connected to the LED.
I hope this information is helpful! If you would like to request further assistance, please attach the PLECS model in question.
Thank you very much for your help. I still have one problem with the Quadrature Encoder Counter (QEP). I’m using the Nucleo-F303RE and trying to use the QEP with the reset by pulse option. However, I’m facing an issue where this feature is not supported by the target. Is there any way to make it work?
Resetting a Quadrature Encoder Counter (QEP) by index pulse is only available for targets belonging to the G4 family. A workaround using other blocks (e.g. the Digital In block) to capture the index pulse could not be implemented in a robust manner because the discretization step size of the model would need to be guaranteed to be smaller than the duration of the index pulse.