IR Pulse Number Detection
This sample code guide is designed to help users easily and comprehensively understand IR sample. This sample demonstrates the pulse number detection with IR.
Requirements
For hardware requirements, please refer to the Requirements.
Wiring
Connect P2_1 to PWM output.
Configurations
The following macros can be configured to modify pin definitions.
#define DETECT_PIN P2_1
The following macros can be configured to modify the maximum number of pulse detections.
#define MAX_DETECT_PULSE_CNT 100
The entry function is as follows, call this function in
main()
to run this sample code. For more details, please refer to the Initialization.ir_detect_pulse_demo();
Building and Downloading
For building and downloading, please refer to the Building and Downloading.
Experimental Verification
Preparation Phase
Pulse detection is performed every 100ms, and the pulse detection data is printed in Debug Analyzer after each pulse detection.
ir_detect_callback index xx level xx time xx
Code Overview
This section introduces the code and process description for initialization and corresponding function implementation in the sample.
Source Code Directory
For project directory, please refer to Source Code Directory.
Source code directory:
sdk\src\sample\io_demo\ir\detect_pulse_demo\ir_detect_pulse_demo.c
.
Initialization
Call
ir_detect_pulse_init
to initialize IR pulse detection module.Call
ir_detect_pulse_register_callback
to register callback to IR pulse detection module.Call
os_timer_create()
to create a software timer.Call
io_dlps_register()
to initialize IO store/restore and do not need to worry about which IO peripheral requires specific handling.Call
bt_power_mode_set()
to set Bluetooth MAC deep sleep mode.Call
power_mode_set()
to switch the system to DLPS mode.
Functional Implementation
Software Timer Callback Handle
When the software timer timeout, the software timer callback function will be executed:
Call
ir_detect_pulse_start
to start IR pulse detection and DLPS will be disabled.
IR Pulse Detection Callback Handle
When IR pulse detection ends, the IR pulse detection callback function will be executed:
Get pulse detection data.
Call
ir_detect_pulse_stop
to stop IR pulse detection and DLPS will be enabled.