一、硬件设计
PC04 ------------PWM4
二、通过shell开启PWM
配置参数
cmd_pwm config pc04 freq=1000 max_level=100 active_level=1
accuracy_priority=freq
启动
cmd_pwm set_level pc04 10
三、通过写程序控制
先用IConfigTool工具,使能libhardware2--->pwm
代码中包含头文件:
#include <libhardware2/pwm.h>
设置pwm参数的信息结构体
struct pwm_config_data pwm12_config = {.shutdown_mode = PWM_abrupt_shutdown, /* 设置PWM在停止输出时立刻将pwm设置成空闲时电平 */.idle_level = PWM_idle_low, /* 设置PWM空闲电平为高电平 */.accuracy_priority = PWM_accuracy_freq_first, /* 设置输出PWM时,优先满足PWM调制后频率的精度 */.freq = 1000, /* 设置PWM调制后频率为1KHz */.levels = 100, /* 设置PWM最大级数为100 */.id = 0, /* 申请PWM成功后的id */
};
开启pwm
int pwm1 = pwm_request( "PC04" );pwm_config(pwm1, &pwm12_config);pwm_set_level( pwm1, 30 );