初级会员
- 积分
- 189
- 金钱
- 189
- 注册时间
- 2019-6-28
- 在线时间
- 27 小时
|
如题:我打开了定时器的PWM功能,PWM闪烁正常。但是定时器的5秒定时不准,基本是几毫秒级别的
static rt_thread_t tid1 = RT_NULL;
struct rt_device_pwm *pwm_dev;
rt_device_t hw_dev;
rt_uint32_t period=500000;
rt_uint32_t pulse = 50000;
rt_uint32_t dir;
rt_err_t ret = 0;
rt_uint32_t freq = 10000;
rt_hwtimer_mode_t mode;
rt_hwtimerval_t timeout_s;
int main(void)
{
hw_dev = rt_device_find("timer3");
if(hw_dev!=NULL)
{
rt_kprintf("timer3 find ok\r\n");
}
ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
if (ret != RT_EOK)
{
rt_kprintf("open timer3 device failed!\n");
return ret;
}
rt_device_set_rx_indicate(hw_dev, timeout_cb);
rt_device_control(hw_dev, HWTIMER_CTRL_FREQ_SET, &freq);
mode = HWTIMER_MODE_PERIOD;
rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
timeout_s.sec = 5;
timeout_s.usec = 0;
rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s));
pwm_dev = (struct rt_device_pwm *)rt_device_find("pwm3");
if(pwm_dev!=NULL)
{
rt_kprintf("pwm find ok\r\n");
}
rt_pwm_set(pwm_dev, 2, period, pulse);
rt_pwm_enable(pwm_dev, 2);
tid1 = rt_thread_create("thread1",
thread1_entry, RT_NULL,
500,
23, 10);
if (tid1 != RT_NULL)
rt_thread_startup(tid1);
return 0;
}
|
|