电机口支持的脚位:
/* MCPWMCH0_H PA5 MCPWMCH0_L PA6 /
/ MCPWMCH1_H PB1 MCPWMCH1_L PB2 /
/ MCPWMCH2_H PB5 MCPWMCH2_L PB6 /
/ MCPWMCH3_H PB7 MCPWMCH3_L PB8 /
/ MCPWMCH4_H PA10 MCPWMCH4_L PA11 /
/ MCPWMCH5_H PC1 MCPWMCH5_L PC2 */
*Description: PWM占空比输出函数
1、选择OUT_CH0或者OUT_CH1的时候所有IO口设置成输
出、开上下拉都可以输出
2、选择IO脚输出的时候只有IO可以输出PWM
*Arguments : out_ch:OUT_CH选择 0-选择OUT_CH0 1-选择OUT_CH1
2-选择IO
prescale:预分频系数(0:预分频1 1:预分频4
2:预分频16 3:预分频64)
duty:占空比(0-USE_DENOMINATOR)/USE_DENOMINATOR
fre:频率
*Returns : 0:成功 其他:出错
*Note :
*By : minzong
led_fade设置:
led_fade设置:
void led_w_pwm_ctrl(u16 duty, tbool fade)
void led_r_pwm_ctrl(u16 duty, tbool fade)
void led_g_pwm_ctrl(u16 duty, tbool fade)
void led_b_pwm_ctrl(u16 duty, tbool fade)
PWM通道选择:
typedef enum OUT_CH_SEL
{
OUT_CH0_SEL = 0,
OUT_CH1_SEL,
OUT_ASSIGN_PORT,
}OUT_CH_SEL;
/----------------------------------------------------------------------------/
/**@brief open mcpwm module
@param pwm_md : 产生pwm方式 1:递增模式 2:递增-递减循环模式
sys_clk : 系统时钟
div : 系统时钟分频,pwm timer的clk为sys_clk/(2^n)
deno : 占空比的分母
@return NULL
@note must init before use mcpwm module
/
/----------------------------------------------------------------------------*/
void mcpwm_module_on(u8 pwm_md , u32 sys_clk , u8 div , u16 deno);
/----------------------------------------------------------------------------/
/**@brief close mcpwm module
@param ch : BIT 0~1 对应 MCPWMCH0_H MCPWMCH0_L
BIT 2~3 对应 MCPWMCH1_H MCPWMCH1_L
BIT 4~5 对应 MCPWMCH2_H MCPWMCH2_L
BIT 6~7 对应 MCPWMCH3_H MCPWMCH3_L
BIT 8~9 对应 MCPWMCH4_H MCPWMCH4_L
BIT 10~11 对应 MCPWMCH5_H MCPWMCH5_L
0xffff : close all mcpwm
@return NULL
@note
/
/----------------------------------------------------------------------------*/
void mcpwm_module_off(u16 ch);
/----------------------------------------------------------------------------/
/**@brief mcpwm0 init
@param opposite_ctl : BIT 0~1 对应 MCPWMCH0_H MCPWMCH0_L反向控制 1:enable 0:disable
ch : BIT 0~1 对应 MCPWMCH0_H MCPWMCH0_L 1:enable 0:disable
@return NULL
@note must init before use mcpwm0
/
/----------------------------------------------------------------------------*/
void mcpwm0_init(u16 opposite_ctl , u16 ch);
/----------------------------------------------------------------------------/
/**@brief mcpwm0 set
@param fre : pwm fre
duty : 占空比设置,实际占空比为duty/deno
@return NULL
@note
/
/----------------------------------------------------------------------------*/
void set_mcpwm0(u32 fre ,u32 duty);
/----------------------------------------------------------------------------/
/**@brief mcpwm1 init
@param opposite_ctl : BIT 2~3 对应 MCPWMCH1_H MCPWMCH1_L反向控制 1:enable 0:disable
ch : BIT 2~3 对应 MCPWMCH1_H MCPWMCH1_L 1:enable 0:disable
@return NULL
@note must init before use mcpwm1
/
/----------------------------------------------------------------------------*/
void mcpwm1_init(u16 opposite_ctl , u16 ch);
/----------------------------------------------------------------------------/
/**@brief mcpwm1 set
@param fre : pwm fre
duty : 占空比设置,实际占空比为duty/deno
@return NULL
@note
/
/----------------------------------------------------------------------------*/
void set_mcpwm1(u32 fre ,u32 duty);
/----------------------------------------------------------------------------/
/**@brief mcpwm2 init
@param opposite_ctl : BIT 4~5 对应 MCPWMCH2_H MCPWMCH2_L反向控制 1:enable 0:disable
ch : BIT 4~5 对应 MCPWMCH2_H MCPWMCH2_L 1:enable 0:disable
@return NULL
@note must init before use mcpwm2
/
/----------------------------------------------------------------------------*/
void mcpwm2_init(u16 opposite_ctl , u16 ch);
/----------------------------------------------------------------------------/
/**@brief mcpwm2 set
@param fre : pwm fre
duty : 占空比设置,实际占空比为duty/deno
@return NULL
@note
/
/----------------------------------------------------------------------------*/
void set_mcpwm2(u32 fre ,u32 duty);
/----------------------------------------------------------------------------/
/**@brief mcpwm3 init
@param opposite_ctl : BIT 6~7 对应 MCPWMCH3_H MCPWMCH3_L反向控制 1:enable 0:disable
ch : BIT 6~7 对应 MCPWMCH3_H MCPWMCH3_L 1:enable 0:disable
@return NULL
@note must init before use mcpwm3
/
/----------------------------------------------------------------------------*/
void mcpwm3_init(u16 opposite_ctl , u16 ch);
/----------------------------------------------------------------------------/
/**@brief mcpwm3 set
@param fre : pwm fre
duty : 占空比设置,实际占空比为duty/deno
@return NULL
@note
/
/----------------------------------------------------------------------------*/
void set_mcpwm3(u32 fre ,u32 duty);
/----------------------------------------------------------------------------/
/**@brief mcpwm4 init
@param opposite_ctl : BIT 8~9 对应 MCPWMCH4_H MCPWMCH4_L反向控制 1:enable 0:disable
ch : BIT 8~9 对应 MCPWMCH4_H MCPWMCH4_L 1:enable 0:disable
@return NULL
@note must init before use mcpwm4
/
/----------------------------------------------------------------------------*/
void mcpwm4_init(u16 opposite_ctl , u16 ch);
/----------------------------------------------------------------------------/
/**@brief mcpwm4 set
@param fre : pwm fre
duty : 占空比设置,实际占空比为duty/deno
@return NULL
@note
/
/----------------------------------------------------------------------------*/
void set_mcpwm4(u32 fre ,u32 duty);
/----------------------------------------------------------------------------/
/**@brief mcpwm5 init
@param opposite_ctl : BIT 10~11 对应 MCPWMCH5_H MCPWMCH5_L反向控制 1:enable 0:disable
ch : BIT 10~11 对应 MCPWMCH5_H MCPWMCH5_L 1:enable 0:disable
@return NULL
@note must init before use mcpwm5
/
/----------------------------------------------------------------------------*/
void mcpwm5_init(u16 opposite_ctl , u16 ch);
/----------------------------------------------------------------------------/
/**@brief mcpwm5 set
@param fre : pwm fre
duty : 占空比设置,实际占空比为duty/deno
@return NULL
@note
/
/----------------------------------------------------------------------------*/
void set_mcpwm5(u32 fre ,u32 duty);
/*
*Description: RGB灯控制函数
*Arguments : status:0 关闭 1 打开
r_duty:红灯占空比 (1-0xFF)/0xFF
g_duty:绿灯占空比 (1-0xFF)/0xFF
b_duty:蓝灯占空比 (1-0xFF)/0xFF
fade:1-淡入淡出,0-立即响应
*Returns : NULL
*Note :
*By :
*/
void rgb_led_control(u8 status,u8 r_duty,u8 g_duty,u8 b_duty, tbool fade)
/*
*Description: RGB灯控制函数
*Arguments : status:0 关闭 1 打开
r_duty:红灯占空比 (1-0xFF)/0xFF
g_duty:绿灯占空比 (1-0xFF)/0xFF
b_duty:蓝灯占空比 (1-0xFF)/0xFF
fade:1-淡入淡出,0-立即响应
*Returns : NULL
*Note :
*By :
*/
void rgb_led_control(u8 status,u8 r_duty,u8 g_duty,u8 b_duty, tbool fade)
/*
*Description: 彩灯闪烁扫描函数
*Arguments : flag–on/off
*Returns : NULL
*Note :
*By :
*/
static u8 led_flicker_flag = 0;//闪烁标记
void check_ficker_scan(volatile u8 flag)
/*
*Description: 音乐闪烁扫描处理函数
*Arguments : NULL
*Returns : NULL
*Note :
*By :
*/