Introduction to the PWM Capture Function of the Rockchip RK3562 Platform and Application Cases
Description
PWM (Pulse Width Modulation) is very common in embedded systems. It provides a method for generating pulse periodic wave-forms for motor control or can function as a digital-to-analog converter with some external components.
RK3562 supports 16 interrupt-driven on-chip PWM channels and offers capture mode with the following features:
- Measurement of high/low polarity effective periods of input waveforms;
- Generation of a single interrupt when the input waveform polarity changes;
- 32-bit high polarity capture register
- 32-bit low polarity capture register
- 32-bit current value register
- Capture results can be stored in an 8-depth FIFO FIFO data can be read by CPU or DMA
- Channel 3 supports a 32-bit power key capture mode
- Supports switching IO between channel 3 and channels 0/1/2
- Supports input pulse counters
- Supports input filters to eliminate noise
The capture mode of the RK3562 uses the PWM channel clock to measure the high/low effective periods of the PWM channel input waveforms and generates interrupts when the polarity of the input waveform changes. It can also capture the pulse counts of the input waveform, which can be used to measure waveform information such as duty cycle and frequency.
Application Scenario
PWM capture is a technique used to measure the cycle, frequency, and duty cycle of external signals. In the power sector, real-time data acquisition is essential for analyzing and monitoring grid power due to the normal fluctuations in grid frequency. The PWM capture technology can be utilized to detect grid frequency in real-time.
This article will use a signal generator to produce square waves of specific frequencies to simulate signal input in real application scenarios and provide a simple demonstration of the PWM capture function of the RK3562.
Cases
Development Board Model: OK3562-C + FET3562J-C
Forlinx Material Version: OK3562-C_Linux 5.10.198_User Manual_R1
Development Board System: Linux 5.10.198 (CPU0, 1, 2) + RT-Thread (CPU3)
Hardware Preparation:
One set of OK3562-C development board
One signal generator
Several Dupont wires
Software Preparation:
Please contact Forlinx to get it!
Source Code Compilation:
Extract the source code and enter the OK3562-linux-source directory
Execute ./build.sh defconfig:forlinx_ok3562_linux_rtos_defconfig to change the compilation configuration to run Linux on 3 CPUs and RT-Thread on 1 CPU in AMP mode;
Execute ./build.sh for a full compilation and wait for the process to complete;
The compiled update.img image is saved in the rockdev directory.
Testing Steps:
1. Follow the user manual in the software materials to burn the image. After burning, power on the device; RT-Thread will print the following:
2. Execute fl_pwmcap to enable PWM capture functionality and start detecting the input signals. Successful startup will appear as shown below:
3. Turn on the signal generator and change the output mode to continuous pulse waveform, with a frequency set to 10 kHz and a duty cycle of 90%.
After enabling the output of the signal generator, the board will start printing the measured period and duty cycle (the 89% duty cycle is due to the program's calculation not preserving decimal points, causing some errors).
Change the duty cycle of the signal generator to 30%, and the board output will reflect this change to 30%.
Change the frequency of the signal generator to 500 kHz and duty cycle to 75%, and continue observing the board output:
Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!