stm8s的tim1的pwm输出求助
答案:2 悬赏:80 手机版
解决时间 2021-03-08 16:41
- 提问者网友:锁深秋
- 2021-03-08 07:11
stm8s的tim1的pwm输出求助
最佳答案
- 五星知识达人网友:何以畏孤独
- 2021-03-08 07:30
//用固件库方便些#include "stm8s_lib.h"#define CCR1_Val ((u16)2047) #define CCR2_Val ((u16)1535) #define CCR3_Val ((u16)1023) #define CCR4_Val ((u16)511) void main(void) { TIM1_DeInit(); /* Ti...
全部回答
- 1楼网友:零点过十分
- 2021-03-08 07:51
//用固件库方便些#include "stm8s_lib.h"#define ccr1_val ((u16)2047)
#define ccr2_val ((u16)1535)
#define ccr3_val ((u16)1023)
#define ccr4_val ((u16)511)
void main(void)
{
tim1_deinit();
tim1_timebaseinit(0, tim1_countermode_up, 4095, 0);
tim1_oc1init(tim1_ocmode_pwm2, tim1_outputstate_enable, tim1_outputnstate_enable, ccr1_val, tim1_ocpolarity_low, tim1_ocnpolarity_high, tim1_ocidlestate_set, tim1_ocidlestate_reset);
tim1_oc2init(tim1_ocmode_pwm2, tim1_outputstate_enable, tim1_outputnstate_enable, ccr2_val, tim1_ocpolarity_low, tim1_ocnpolarity_high, tim1_ocidlestate_set, tim1_ocidlestate_reset);
tim1_oc3init(tim1_ocmode_pwm2, tim1_outputstate_enable, tim1_outputnstate_enable, ccr3_val, tim1_ocpolarity_low, tim1_ocnpolarity_high, tim1_ocidlestate_set, tim1_ocidlestate_reset);
// tim1_oc4init(tim1_ocmode_pwm2, tim1_outputstate_enable, ccr4_val, tim1_ocpolarity_low, tim1_ocidlestate_set);
//gpio_init(gpiod,gpio_pin_7,gpio_mode_out_pp_low_fast);
//opt_init1.opt2=(opt_init1.opt2|0x10);
tim1_cmd(enable);
tim1_ctrlpwmoutputs(enable);
while (1)
{
}
}#ifdef full_assert
void assert_failed(u8 *file, u16 line)
#else
void assert_failed(void)
#endif
{
while (1)
{
}
} //不用固件库直接操作我只试过 tim2 tim3 不过tim1应该差不多,你自己参考,我只知道这么多了,莫追问void tim2_init(void) //tim2 ch1 工作于模式1
{
tim2_ccmr1= 0x60; // pwm 模式 1,tim2 ch1
tim2_ccer1= 0x03; // cc1配置为输出
tim2_ccer2= 0x03; // cc3使能
tim2_arrh = 0x03; // 配置pwm分辨率为10位,arr=0x3ff
tim2_arrl = 0xff; // pwm频率=8m/0x03ff=7820hz
tim2_cr1 |= 0x01; // 计数器使能,开始计数
}void run(void)
{ tim2_ccr1=value;
tim2_ccr3=value;
tim3_ccr2=value;
tim3_ccr1=value; //注意每个通道都要设ccr
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯