NUC972平台PWM输出38k红外调制信号


kernel配置文件.config选择pwm0有效,且输出管脚是PB2

CONFIG_PWM=y
CONFIG_PWM_SYSFS=y
CONFIG_PWM_NUC970=y
# CONFIG_NUC970_PWM0_NONE is not set
# CONFIG_NUC970_PWM0_PA12 is not set
CONFIG_NUC970_PWM0_PB2=y
# CONFIG_NUC970_PWM0_PC14 is not set
# CONFIG_NUC970_PWM0_PD12 is not set
CONFIG_NUC970_PWM1_NONE=y
# CONFIG_NUC970_PWM1_PA13 is not set
# CONFIG_NUC970_PWM1_PB3 is not set
# CONFIG_NUC970_PWM1_PD13 is not set
CONFIG_NUC970_PWM2_NONE=y
# CONFIG_NUC970_PWM2_PA14 is not set
# CONFIG_NUC970_PWM2_PD14 is not set
# CONFIG_NUC970_PWM2_PH2 is not set
CONFIG_NUC970_PWM3_NONE=y
# CONFIG_NUC970_PWM3_PA15 is not set
# CONFIG_NUC970_PWM3_PD15 is not set
# CONFIG_NUC970_PWM3_PH3 is not set

应用程序里初始化PWM38K方波输出,信号占空比1:3,红外38KHz调制信号输出配置完成

#define NUCPWM0 "/sys/class/pwm/pwmchip0/pwm0"
#define NUCPWM0CREATE "echo 0 >/sys/class/pwm/pwmchip0/export"
#define NUCPWM0DESTROY "echo 0 >/sys/class/pwm/pwmchip0/unexport"
#define NUCPWM0ENABLE "echo 1 >/sys/class/pwm/pwmchip0/pwm0/enable"
#define NUCPWM0DISABLE "echo 0 >/sys/class/pwm/pwmchip0/pwm0/enable"
#define NUCPWM038K "echo 26000 >/sys/class/pwm/pwmchip0/pwm0/period"
#define NUCPWM038K1DIV3 "echo 9000 >/sys/class/pwm/pwmchip0/pwm0/duty_cycle"

应用代码

unsigned char enable_970pwm0(void) {
    if (access(NUCPWM0, F_OK) == 0)
        return 1;
    system(NUCPWM0CREATE);
    system(NUCPWM0ENABLE);
    return 1;
}
unsigned char disable_970pwm0(void) {
    if (access(NUCPWM0, F_OK) == -1)
        return 1;
    system(NUCPWM0DISABLE);
    return 1;
}
unsigned char start_970pwm038k(void) {
    enable_970pwm0();
    system(NUCPWM038K);
    system(NUCPWM038K1DIV3);
    //	printf("enable pwm0 38K OK\n");
    return 1;
}

相关