Application | This example code uses the ECAP function to emulate PWM Capture mode. | BSP Version | Linux-6.6.y | Hardware | NuMaker-HMI-MA35D1 V1.0 |
In real applications, the ECAP (Enhanced Input Capture Timer) is usually used together with QEI (Quadrature Encoder Interface). This is commonly used in motor detection and control systems. QEI decodes the encoder A/B phase signals to get the motor position and speed. By combining ECAP and QEI, the system can get both the motor mechanical position and speed at the same time. However, this sample program uses the ECAP module to emulate the PWM capture mode function. It measures the frequency and duty cycle of an external PWM or pulse signal, and extends the ECAP usage range and flexibility in real systems. The ECAP module built into the MA35D1 series microprocessor (MPU) can provide a measurement function similar to EPWM Capture mode. It can measure parameters such as the frequency and duty cycle of an external PWM or pulse signal. The ECAP module provides multiple independent Input Capture units. Each unit includes the following features: - One 16-bit up-count timer/counter
- Auto-reload and Compare-Match mechanism
- Three independent input capture channels
Each capture channel can detect digital signal edge changes on the input pin (rising edge, falling edge, or both edges). When a configured edge event is detected, ECAP latches the current counter value into the related capture register. By continuously reading the captured counter value difference between different edges (for example: rising-to-next-rising, rising-to-falling), the system can calculate: - Input PWM period (Period)
- High level time (High Time)
- Low level time (Low Time)
- Duty cycle (Duty Cycle)
In this way, the ECAP module can emulate PWM input capture mode. It can accurately measure the timing features of an external PWM or other pulse signals. It can also work with interrupts to automatically move the measurement result to memory, reduce CPU load, and improve measurement efficiency. You can download the sample code at EC_MA35D1_ECAP_Emulate_PWM_Capture_V1.00.
|