PWM

玩iot camera笔记之3测试试用3路pwm

发布于 2016-09-19 16:44:00
在测试PWM的时候,发现只能启动PWM0,PWM1 PWM2 启动失败,求大神(已解决!根据网友提示并参考lua pwm库)
代码放在 firmware-20160908applicationsmain.c
里面,添加对应所需的头文件
/* pwm init test
*
*
*
* */
#include
#include
#include


在main函数后面添加代码并添加到main函数里面,以便启动完 /init.sh脚本后,启动我的测试pwm



int pwmSet()
{
rt_device_t pwm_dev;
struct pwm_device pwm;
int ret;
pwm_dev = rt_device_find("pwm");
rt_kprintf("pwm_dev->device_id = %d
" , pwm_dev->device_id);
ret = rt_device_open(pwm_dev, RT_DEVICE_OFLAG_RDWR);
rt_kprintf("rt_device_open end
");

/* 打开设备时就使能了
ret = rt_device_control(pwm_dev, ENABLE_PWM, &pwm);
rt_kprintf("ENABLE_PWM end
");
*/

//ret = rt_device_control(pwm_dev, GET_PWM_DUTY_CYCLE, &pwm);
pwm.id=0;//pwm0
pwm.working= 1;
//38kHz =26.3
pwm.counter_ns = 13000;//for duty
pwm.period_ns = 26000;
ret = rt_device_control(pwm_dev, SET_PWM_DUTY_CYCLE, &pwm);
rt_kprintf("SET_PWM_DUTY_CYCLE end
");

#if 1
ret = rt_device_control(pwm_dev, GET_PWM_DUTY_CYCLE, &pwm);
rt_kprintf("GET_PWM_DUTY_CYCLE id= %d pwm.counter_ns = %d pwm.period_ns = %d
" , pwm.id,pwm.counter_ns , pwm.period_ns);
#endif

#if 1
pwm.id=1;//pwm1
pwm.working= 1;
//38kHz =26.3
pwm.counter_ns = 13000;//for duty
pwm.period_ns = 26000;
ret = rt_device_control(pwm_dev, SET_PWM_DUTY_CYCLE, &pwm);
rt_kprintf("SET_PWM_DUTY_CYCLE pwm1 end
");

#endif


}
MSH_CMD_EXPORT(pwmSet, pwmSet);





然后让系统启动后自动启动pwm,在main函数的return 前面添加一行
	pwmSet();

return 0;


重新编译并启动,发现PWM0有输出38KHZ的方波,但是隔壁的PWM1 PWM2 都是低电平,没反应,难道芯片挂了?
求救啊

查看更多

关注者
0
被浏览
1.7k
2 个回答
独行客
独行客 2016-09-19
已经解决
在初始化时添加端口复用,切到pwm端口
	fh_iomux_pin_switch(49, 1);//pwm1

fh_iomux_pin_switch(50, 1);//pwm2
fh_iomux_pin_switch(51, 1);//pwm0

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览