登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
Gitee AI
NEW
我知道了
查看详情
登录
注册
1月18日,北京,聊聊2025如何加入技术开发?
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
3
Star
6
Fork
3
珠海杰理科技
/
fw-AW31N_BLE_SDK
代码
Issues
24
Pull Requests
0
Wiki
统计
流水线
服务
Gitee Pages
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
我知道了,不再自动展开
更新失败,请稍后重试!
Issues
/
详情
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
[分享内容]: PWM输出
待办的
#IAIAJD
JL-小辛
创建于
2024-08-06 20:08
### PWM个数 AW31最多可以输出6路独立频率、独立占空比的PWM timer0、timer1、timer2、timer3 mcpwm0、mcpwm1 ### 使用例子 ``` static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠 void pwm_idle_set(u8 is_idle) { pwm_idle = is_idle; sleep_run_check_enalbe(is_idle); // 区别于632, 需多加此调用 } static u8 pwm_idle_query(void) { return pwm_idle; } REGISTER_LP_TARGET(pwm_lp_target) = { .name = "pwm_lp", .is_idle = pwm_idle_query, }; int timer_pwm_set(u32 id, u32 freq, u32 duty) { log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty); gptimer_set_pwm_freq(id, freq); gptimer_set_pwm_duty(id, duty); // log_info("%s[get:%d -> freq:%d duty:%d]", __func__, id, // gptimer_get_pwm_freq(id), gptimer_get_pwm_duty(id)); return 0; } int timer_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty) { log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty); pwm_idle_set(0); gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出 const struct gptimer_config pwm_config = { .pwm.freq = freq, //设置输出频率 .pwm.duty = duty, //设置占空比 .pwm.port = pin / 16, //设置pwm输出IO .pwm.pin = BIT(pin % 16), //设置pwm输出IO .mode = GPTIMER_MODE_PWM, //设置工作模式 }; u32 tid = gptimer_init(id, &pwm_config); log_info("%s[gptimer_init:%d]", __func__, tid); /* gptimer_pwm_flip(tid); //pwm翻转反向 */ gptimer_start(tid); gptimer_dump(); return tid; } int timer_pwm_run(u32 id, u8 en) { log_info("%s[en:%d]", __func__, en); if(en){ pwm_idle_set(0); gptimer_resume(id); }else{ pwm_idle_set(1); gptimer_pause(id); /* gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */ } return 0; } int mcpwm_pwm_set(u32 id, u32 freq, u32 duty) { log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty); if((freq == 0)&&(duty == 0)){ freq = 1; // freq == 0, duty == 0 会输出高 } mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq); mcpwm_set_duty(id, duty); return 0; } int mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty) { log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty); struct mcpwm_config cfg; cfg.ch = id; //通道号 cfg.aligned_mode = MCPWM_EDGE_ALIGNED; //边沿对齐 cfg.frequency = freq; //频率 cfg.duty = duty; //占空比 cfg.h_pin = pin; //任意引脚 cfg.l_pin = -1; //任意引脚,不需要就填-1 cfg.complementary_en = 0; //两个引脚的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上 cfg.detect_port = -1; //任意引脚,不需要就填-1 cfg.edge = MCPWM_EDGE_FAILL; cfg.irq_cb = NULL; cfg.irq_priority = 1; //优先级默认为1 cfg.deadtime_ns = 1000; //死驱时间,1000ns int mid = mcpwm_init(&cfg); log_info("%s[mcpwm id:%d]", __func__, mid); mcpwm_start(mid); return mid; } int mcpwm_pwm_run(u32 id, u8 en) { log_info("%s[en:%d]", __func__, en); if(en){ pwm_idle_set(0); mcpwm_start(id); }else{ pwm_idle_set(1); mcpwm_pause(id); /* gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */ } return 0; } ``` ### demo 【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm-usb https://kdocs.cn/l/cafBqpI4EdVf ### 相关问题 ![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
### PWM个数 AW31最多可以输出6路独立频率、独立占空比的PWM timer0、timer1、timer2、timer3 mcpwm0、mcpwm1 ### 使用例子 ``` static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠 void pwm_idle_set(u8 is_idle) { pwm_idle = is_idle; sleep_run_check_enalbe(is_idle); // 区别于632, 需多加此调用 } static u8 pwm_idle_query(void) { return pwm_idle; } REGISTER_LP_TARGET(pwm_lp_target) = { .name = "pwm_lp", .is_idle = pwm_idle_query, }; int timer_pwm_set(u32 id, u32 freq, u32 duty) { log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty); gptimer_set_pwm_freq(id, freq); gptimer_set_pwm_duty(id, duty); // log_info("%s[get:%d -> freq:%d duty:%d]", __func__, id, // gptimer_get_pwm_freq(id), gptimer_get_pwm_duty(id)); return 0; } int timer_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty) { log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty); pwm_idle_set(0); gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出 const struct gptimer_config pwm_config = { .pwm.freq = freq, //设置输出频率 .pwm.duty = duty, //设置占空比 .pwm.port = pin / 16, //设置pwm输出IO .pwm.pin = BIT(pin % 16), //设置pwm输出IO .mode = GPTIMER_MODE_PWM, //设置工作模式 }; u32 tid = gptimer_init(id, &pwm_config); log_info("%s[gptimer_init:%d]", __func__, tid); /* gptimer_pwm_flip(tid); //pwm翻转反向 */ gptimer_start(tid); gptimer_dump(); return tid; } int timer_pwm_run(u32 id, u8 en) { log_info("%s[en:%d]", __func__, en); if(en){ pwm_idle_set(0); gptimer_resume(id); }else{ pwm_idle_set(1); gptimer_pause(id); /* gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */ } return 0; } int mcpwm_pwm_set(u32 id, u32 freq, u32 duty) { log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty); if((freq == 0)&&(duty == 0)){ freq = 1; // freq == 0, duty == 0 会输出高 } mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq); mcpwm_set_duty(id, duty); return 0; } int mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty) { log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty); struct mcpwm_config cfg; cfg.ch = id; //通道号 cfg.aligned_mode = MCPWM_EDGE_ALIGNED; //边沿对齐 cfg.frequency = freq; //频率 cfg.duty = duty; //占空比 cfg.h_pin = pin; //任意引脚 cfg.l_pin = -1; //任意引脚,不需要就填-1 cfg.complementary_en = 0; //两个引脚的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上 cfg.detect_port = -1; //任意引脚,不需要就填-1 cfg.edge = MCPWM_EDGE_FAILL; cfg.irq_cb = NULL; cfg.irq_priority = 1; //优先级默认为1 cfg.deadtime_ns = 1000; //死驱时间,1000ns int mid = mcpwm_init(&cfg); log_info("%s[mcpwm id:%d]", __func__, mid); mcpwm_start(mid); return mid; } int mcpwm_pwm_run(u32 id, u8 en) { log_info("%s[en:%d]", __func__, en); if(en){ pwm_idle_set(0); mcpwm_start(id); }else{ pwm_idle_set(1); mcpwm_pause(id); /* gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */ } return 0; } ``` ### demo 【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm-usb https://kdocs.cn/l/cafBqpI4EdVf ### 相关问题 ![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
评论 (
0
)
JL-小辛
创建了
任务
JL-小辛
添加了
enhancement
标签
JL-小辛
修改了
描述
原值
###
你的分享内容标题?
### PWM个数
AW31最多可以输出6路独立频率、独立占空比的PWM
timer0、timer1、timer2、timer3
mcpwm0、mcpwm1
### 使用例子
```
static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠
void pwm_idle_set(u8 is_idle)
{
pwm_idle = is_idle;
sleep_run
_
check_enalbe(
i
s_idle); // 区别于632, 需多加此调用
}
static
u
8 pwm_idle_query(void)
{
return pwm_idle;
}
REGISTER_LP_TARGET(pwm_lp_target) = {
.name = "pwm_lp",
.is_idle = pwm_idle_query,
};
int
timer_pwm_set(u32 id, u32 freq,
u
32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
gptimer_set_pwm_freq(id,
freq
);
gptimer_set_
p
wm_duty(id, duty);
//
log_info("%s[get:%d -> freq:%d duty:%d]", __func__, id,
// gptimer_get_pwm_freq(id), gptimer_get_pwm_duty(id));
retu
r
n 0;
}
int
timer_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
pwm_idle_se
t
(0);
gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出
const struc
t
gptimer_config
pwm_config = {
.pwm.
freq
=
freq,
//设置
输出频率
.pwm.
duty = duty,
//设置
占空比
.
pwm.port = pin / 16,
//设置
pwm输出IO
.pwm.pin = BIT(pin) % 16, //设置pwm输出IO
.mode
= GPTIMER_MODE_PWM, //设置工作模式
};
u32 tid = g
p
timer_init(id,
&pwm_config);
log_info("%s[gptimer_init:%d]", __func__, tid);
/* gptimer_
p
wm_flip(tid); //pwm翻转反向 */
gp
t
imer_start(tid);
gptimer_dump();
retu
r
n tid;
}
int
timer_pwm_run(u32 id
,
u8 e
n
)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
gptimer_resume(id);
}else{
pwm_idle_set(1);
gptimer_pause(id);
/*
gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */
}
return 0;
}
int
mcpwm_pwm_set(u32 id, u32 freq,
u
32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
if((freq == 0)&&(duty == 0)){
freq = 1; // freq == 0, duty == 0 会输出高
}
mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq);
mcpwm_set_duty(id, duty);
return 0;
}
int
mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty)
{
lo
g
_info("%s[id:%d
pin:0x%x
freq:%d
duty:%d]", __func__, id, pin, freq, duty);
struct mcpwm_config cfg;
cfg.
ch = id;
//
通道号
cfg.
aligned_mode
=
MCPWM_EDGE_ALIGNED;
//
边沿对齐
cfg.
frequency = freq;
//
频率
cfg.
duty = duty;
//
占空比
cfg.
h_pin = pin;
//
任意
引脚
cfg.
l_pin = -1;
//任意引脚,不需要就填-1
cfg.
complementary_en = 0; //两个引脚的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上
cfg.
dete
c
t_port = -1; //任意引脚,不需要就填-1
cfg.
edge = MCPWM_EDGE_FAILL;
cfg.
irq_cb = NULL;
cfg.irq_priority = 1; //优先级默认为1
cf
g
.deadtime_ns = 1000;
//死驱时间,1000ns
int
m
id = mcpwm_init(&cfg);
log_i
n
fo("%s[mcpwm id:%d]", __func__, mid);
mcpwm_start(mid);
return mid;
}
int
mcpwm_pwm_run(u32 id
,
u8 e
n
)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
mcpwm_start(id
);
}else{
pwm_idle_set(1);
mcpwm_pause(id);
/*
gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */
}
return 0;
}
```
### demo
【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm
https://kdocs.cn/l/cjQC6Fc8af20
### 相关问题
![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
新值
###
PWM个数
AW31最多可以输出6路独立频率、独立占空比的PWM
timer0、timer1、timer2、timer3
mcpwm0、mcpwm1
### 使用例子
```
static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠
void pwm_idle_set(u8 is_idle)
{
pwm_idle = is_idle;
sleep_run_check_enalbe(is_idle); // 区别于632, 需多加此调用
}
static u8 pwm
_
idle_query(vo
i
d)
{
ret
u
rn pwm_idle;
}
REGISTER_LP_TARGET(pwm_lp_target) = {
.name = "pwm_lp",
.is_idle = pwm_idle_query,
};
int timer_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d d
u
ty:%d]", __func__, id, freq, duty);
gptimer_set_pwm_freq(id, freq);
gptimer_set_pwm_duty(id, duty);
//
log_info("%s[get:%d ->
freq
:%d duty:%d]", __func__, id,
//
g
p
timer_get_pwm_freq(id), gptimer_get_pwm_duty(id));
return 0;
}
int
time
r
_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
pwm_idle_set(0);
gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出
const struc
t
gptimer_config pwm_config = {
.pwm.freq = freq, //设置输出频率
.pwm.du
t
y = duty,
//设置占空比
.pwm.
port
=
pin /
16,
//设置
pwm输出IO
.pwm.
pin = BIT(pin)
%
16,
//设置
pwm输出IO
.
mode = GPTIMER_MODE_PWM,
//设置
工作模式
};
u32
tid =
gptimer_init(id, &pwm_config);
log_info("%s[gptimer_init:%d]", __func__, tid);
/* gptimer_
p
wm_flip(tid);
//pwm翻转反向 */
gptimer_start(tid);
gptimer_dum
p
();
re
t
urn tid;
}
int
time
r
_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]"
,
__fu
n
c__, en);
if(en){
pwm_idle_set(0);
gptimer_resume(id);
}else{
pwm_idle_set(1);
gptimer_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */
}
return
0;
}
int mcpwm_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d d
u
ty:%d]", __func__, id, freq, duty);
if((freq == 0)&&(duty == 0)){
freq = 1; // freq == 0, duty == 0 会输出高
}
mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq);
mcpwm_set_duty(id, duty);
return 0;
}
int
mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
struct mcpwm_config cfg;
cf
g
.ch = id;
//通道号
cfg.aligned_mode = MCPWM_EDGE_ALIGNED; //边沿对齐
cfg.
frequency
=
freq;
//
频率
cfg.
duty = duty;
//
占空比
cfg.
h_pin = pin;
//
任意引脚
cfg.
l_pin = -1;
//
任意引脚,不需要就填-1
cfg.
complementary_en
=
0;
//
两个
引脚
的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上
cfg.
detect_port
=
-1;
//任意引脚,不需要就填-1
cfg.
edge = MCPWM_EDGE_FAILL;
cfg.
irq_
c
b = NULL;
cfg.
irq_priority = 1; //优先级默认为1
cfg.
deadtime_ns = 1000; //死驱时间,1000ns
int mid = mcpwm_init(&cfg);
lo
g
_info("%s[mcpwm id:%d]",
__func__,
mid);
mcpw
m
_start(mid);
retur
n
mid;
}
int
mcpwm_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]"
,
__fu
n
c__, en);
if(en){
pwm_idle_set(0);
mcpwm_start(id);
}else{
pwm_idle_set(1
);
mcpwm_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */
}
return
0;
}
```
### demo
【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm
https://kdocs.cn/l/cjQC6Fc8af20
### 相关问题
![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
JL-小辛
修改了
描述
原值
### PWM个数
AW31最多可以输出6路独立频率、独立占空比的PWM
timer0、timer1、timer2、timer3
mcpwm0、mcpwm1
### 使用例子
```
static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠
void pwm_idle_set(u8 is_idle)
{
pwm_idle = is_idle;
sleep_run_check_enalbe(is_idle); // 区别于632, 需多加此调用
}
static u8 pwm_idle_query(void)
{
return pwm_idle;
}
REGISTER_LP_TARGET(pwm_lp_target) = {
.name = "pwm_lp",
.is_idle = pwm_idle_query,
};
int timer_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
gptimer_set_pwm_freq(id, freq);
gptimer_set_pwm_duty(id, duty);
// log_info("%s[get:%d -> freq:%d duty:%d]", __func__, id,
// gptimer_get_pwm_freq(id), gptimer_get_pwm_duty(id));
return 0;
}
int timer_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
pwm_idle_set(0);
gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出
const struct gptimer_config pwm_config = {
.pwm.freq = freq, //设置输出频率
.pwm.duty = duty, //设置占空比
.pwm.port = pin / 16, //设置pwm输出IO
.pwm.pin = BIT(pin
) % 16
, //设置pwm输出IO
.mode = GPTIMER_MODE_PWM, //设置工作模式
};
u32 tid = gptimer_init(id, &pwm_config);
log_info("%s[gptimer_init:%d]", __func__, tid);
/* gptimer_pwm_flip(tid); //pwm翻转反向 */
gptimer_start(tid);
gptimer_dump();
return tid;
}
int timer_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
gptimer_resume(id);
}else{
pwm_idle_set(1);
gptimer_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */
}
return 0;
}
int mcpwm_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
if((freq == 0)&&(duty == 0)){
freq = 1; // freq == 0, duty == 0 会输出高
}
mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq);
mcpwm_set_duty(id, duty);
return 0;
}
int mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
struct mcpwm_config cfg;
cfg.ch = id; //通道号
cfg.aligned_mode = MCPWM_EDGE_ALIGNED; //边沿对齐
cfg.frequency = freq; //频率
cfg.duty = duty; //占空比
cfg.h_pin = pin; //任意引脚
cfg.l_pin = -1; //任意引脚,不需要就填-1
cfg.complementary_en = 0; //两个引脚的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上
cfg.detect_port = -1; //任意引脚,不需要就填-1
cfg.edge = MCPWM_EDGE_FAILL;
cfg.irq_cb = NULL;
cfg.irq_priority = 1; //优先级默认为1
cfg.deadtime_ns = 1000; //死驱时间,1000ns
int mid = mcpwm_init(&cfg);
log_info("%s[mcpwm id:%d]", __func__, mid);
mcpwm_start(mid);
return mid;
}
int mcpwm_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
mcpwm_start(id);
}else{
pwm_idle_set(1);
mcpwm_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */
}
return 0;
}
```
### demo
【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm
https://kdocs.cn/l/cjQC6Fc8af20
### 相关问题
![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
新值
### PWM个数
AW31最多可以输出6路独立频率、独立占空比的PWM
timer0、timer1、timer2、timer3
mcpwm0、mcpwm1
### 使用例子
```
static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠
void pwm_idle_set(u8 is_idle)
{
pwm_idle = is_idle;
sleep_run_check_enalbe(is_idle); // 区别于632, 需多加此调用
}
static u8 pwm_idle_query(void)
{
return pwm_idle;
}
REGISTER_LP_TARGET(pwm_lp_target) = {
.name = "pwm_lp",
.is_idle = pwm_idle_query,
};
int timer_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
gptimer_set_pwm_freq(id, freq);
gptimer_set_pwm_duty(id, duty);
// log_info("%s[get:%d -> freq:%d duty:%d]", __func__, id,
// gptimer_get_pwm_freq(id), gptimer_get_pwm_duty(id));
return 0;
}
int timer_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
pwm_idle_set(0);
gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出
const struct gptimer_config pwm_config = {
.pwm.freq = freq, //设置输出频率
.pwm.duty = duty, //设置占空比
.pwm.port = pin / 16, //设置pwm输出IO
.pwm.pin = BIT(pin
% 16)
, //设置pwm输出IO
.mode = GPTIMER_MODE_PWM, //设置工作模式
};
u32 tid = gptimer_init(id, &pwm_config);
log_info("%s[gptimer_init:%d]", __func__, tid);
/* gptimer_pwm_flip(tid); //pwm翻转反向 */
gptimer_start(tid);
gptimer_dump();
return tid;
}
int timer_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
gptimer_resume(id);
}else{
pwm_idle_set(1);
gptimer_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */
}
return 0;
}
int mcpwm_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
if((freq == 0)&&(duty == 0)){
freq = 1; // freq == 0, duty == 0 会输出高
}
mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq);
mcpwm_set_duty(id, duty);
return 0;
}
int mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
struct mcpwm_config cfg;
cfg.ch = id; //通道号
cfg.aligned_mode = MCPWM_EDGE_ALIGNED; //边沿对齐
cfg.frequency = freq; //频率
cfg.duty = duty; //占空比
cfg.h_pin = pin; //任意引脚
cfg.l_pin = -1; //任意引脚,不需要就填-1
cfg.complementary_en = 0; //两个引脚的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上
cfg.detect_port = -1; //任意引脚,不需要就填-1
cfg.edge = MCPWM_EDGE_FAILL;
cfg.irq_cb = NULL;
cfg.irq_priority = 1; //优先级默认为1
cfg.deadtime_ns = 1000; //死驱时间,1000ns
int mid = mcpwm_init(&cfg);
log_info("%s[mcpwm id:%d]", __func__, mid);
mcpwm_start(mid);
return mid;
}
int mcpwm_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
mcpwm_start(id);
}else{
pwm_idle_set(1);
mcpwm_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */
}
return 0;
}
```
### demo
【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm
https://kdocs.cn/l/cjQC6Fc8af20
### 相关问题
![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
JL-小辛
修改了
描述
原值
### PWM个数
AW31最多可以输出6路独立频率、独立占空比的PWM
timer0、timer1、timer2、timer3
mcpwm0、mcpwm1
### 使用例子
```
static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠
void pwm_idle_set(u8 is_idle)
{
pwm_idle = is_idle;
sleep_run_check_enalbe(is_idle); // 区别于632, 需多加此调用
}
static u8 pwm_idle_query(void)
{
return pwm_idle;
}
REGISTER_LP_TARGET(pwm_lp_target) = {
.name = "pwm_lp",
.is_idle = pwm_idle_query,
};
int timer_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
gptimer_set_pwm_freq(id, freq);
gptimer_set_pwm_duty(id, duty);
// log_info("%s[get:%d -> freq:%d duty:%d]", __func__, id,
// gptimer_get_pwm_freq(id), gptimer_get_pwm_duty(id));
return 0;
}
int timer_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
pwm_idle_set(0);
gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出
const struct gptimer_config pwm_config = {
.pwm.freq = freq, //设置输出频率
.pwm.duty = duty, //设置占空比
.pwm.port = pin / 16, //设置pwm输出IO
.pwm.pin = BIT(pin % 16), //设置pwm输出IO
.mode = GPTIMER_MODE_PWM, //设置工作模式
};
u32 tid = gptimer_init(id, &pwm_config);
log_info("%s[gptimer_init:%d]", __func__, tid);
/* gptimer_pwm_flip(tid); //pwm翻转反向 */
gptimer_start(tid);
gptimer_dump();
return tid;
}
int timer_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
gptimer_resume(id);
}else{
pwm_idle_set(1);
gptimer_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */
}
return 0;
}
int mcpwm_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
if((freq == 0)&&(duty == 0)){
freq = 1; // freq == 0, duty == 0 会输出高
}
mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq);
mcpwm_set_duty(id, duty);
return 0;
}
int mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
struct mcpwm_config cfg;
cfg.ch = id; //通道号
cfg.aligned_mode = MCPWM_EDGE_ALIGNED; //边沿对齐
cfg.frequency = freq; //频率
cfg.duty = duty; //占空比
cfg.h_pin = pin; //任意引脚
cfg.l_pin = -1; //任意引脚,不需要就填-1
cfg.complementary_en = 0; //两个引脚的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上
cfg.detect_port = -1; //任意引脚,不需要就填-1
cfg.edge = MCPWM_EDGE_FAILL;
cfg.irq_cb = NULL;
cfg.irq_priority = 1; //优先级默认为1
cfg.deadtime_ns = 1000; //死驱时间,1000ns
int mid = mcpwm_init(&cfg);
log_info("%s[mcpwm id:%d]", __func__, mid);
mcpwm_start(mid);
return mid;
}
int mcpwm_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
mcpwm_start(id);
}else{
pwm_idle_set(1);
mcpwm_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */
}
return 0;
}
```
### demo
【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm
https://kdocs.cn/l/c
jQC6Fc8af20
### 相关问题
![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
新值
### PWM个数
AW31最多可以输出6路独立频率、独立占空比的PWM
timer0、timer1、timer2、timer3
mcpwm0、mcpwm1
### 使用例子
```
static u8 pwm_idle = 1; //置 1 可进睡眠, 置 0 不可进睡眠
void pwm_idle_set(u8 is_idle)
{
pwm_idle = is_idle;
sleep_run_check_enalbe(is_idle); // 区别于632, 需多加此调用
}
static u8 pwm_idle_query(void)
{
return pwm_idle;
}
REGISTER_LP_TARGET(pwm_lp_target) = {
.name = "pwm_lp",
.is_idle = pwm_idle_query,
};
int timer_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
gptimer_set_pwm_freq(id, freq);
gptimer_set_pwm_duty(id, duty);
// log_info("%s[get:%d -> freq:%d duty:%d]", __func__, id,
// gptimer_get_pwm_freq(id), gptimer_get_pwm_duty(id));
return 0;
}
int timer_pwm_init(timer_dev id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
pwm_idle_set(0);
gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出
const struct gptimer_config pwm_config = {
.pwm.freq = freq, //设置输出频率
.pwm.duty = duty, //设置占空比
.pwm.port = pin / 16, //设置pwm输出IO
.pwm.pin = BIT(pin % 16), //设置pwm输出IO
.mode = GPTIMER_MODE_PWM, //设置工作模式
};
u32 tid = gptimer_init(id, &pwm_config);
log_info("%s[gptimer_init:%d]", __func__, tid);
/* gptimer_pwm_flip(tid); //pwm翻转反向 */
gptimer_start(tid);
gptimer_dump();
return tid;
}
int timer_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
gptimer_resume(id);
}else{
pwm_idle_set(1);
gptimer_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(pin), PORT_OUTPUT_LOW); //IO口设为输出0 */
}
return 0;
}
int mcpwm_pwm_set(u32 id, u32 freq, u32 duty)
{
log_info("%s[set:%d -> freq:%d duty:%d]", __func__, id, freq, duty);
if((freq == 0)&&(duty == 0)){
freq = 1; // freq == 0, duty == 0 会输出高
}
mcpwm_set_frequency(id, MCPWM_EDGE_ALIGNED, freq);
mcpwm_set_duty(id, duty);
return 0;
}
int mcpwm_pwm_init(mcpwm_ch_type id, u16 pin, u32 freq, u32 duty)
{
log_info("%s[id:%d pin:0x%x freq:%d duty:%d]", __func__, id, pin, freq, duty);
struct mcpwm_config cfg;
cfg.ch = id; //通道号
cfg.aligned_mode = MCPWM_EDGE_ALIGNED; //边沿对齐
cfg.frequency = freq; //频率
cfg.duty = duty; //占空比
cfg.h_pin = pin; //任意引脚
cfg.l_pin = -1; //任意引脚,不需要就填-1
cfg.complementary_en = 0; //两个引脚的波形, 0: 同步, 1: 互补,互补波形的占空比体现在H引脚上
cfg.detect_port = -1; //任意引脚,不需要就填-1
cfg.edge = MCPWM_EDGE_FAILL;
cfg.irq_cb = NULL;
cfg.irq_priority = 1; //优先级默认为1
cfg.deadtime_ns = 1000; //死驱时间,1000ns
int mid = mcpwm_init(&cfg);
log_info("%s[mcpwm id:%d]", __func__, mid);
mcpwm_start(mid);
return mid;
}
int mcpwm_pwm_run(u32 id, u8 en)
{
log_info("%s[en:%d]", __func__, en);
if(en){
pwm_idle_set(0);
mcpwm_start(id);
}else{
pwm_idle_set(1);
mcpwm_pause(id);
/* gpio_set_mode(IO_PORT_SPILT(IO_PORTA_04), PORT_OUTPUT_LOW);//IO口设为输出0 */
}
return 0;
}
```
### demo
【金山文档 | WPS云文档】 AW31N_sdk_release_v1.1.0--6路pwm
-usb
https://kdocs.cn/l/c
afBqpI4EdVf
### 相关问题
![输入图片说明](https://foruda.gitee.com/images/1722946062144180649/85f46de3_515724.png "屏幕截图")
展开全部操作日志
折叠全部操作日志
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
enhancement
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (1)
标签 (3)
master
aw31n_sdk_release_v1.2.0
aw31n_sdk_release_v1.1.0
aw31n_sdk_release_v1.0.0
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
C
1
https://gitee.com/Jieli-Tech/fw-AW31N_BLE_SDK.git
git@gitee.com:Jieli-Tech/fw-AW31N_BLE_SDK.git
Jieli-Tech
fw-AW31N_BLE_SDK
fw-AW31N_BLE_SDK
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册