STC15W408AS单片机3路PWM输出波形实测
Posted perseverance52
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STC15W408AS单片机3路PWM输出波形实测相关的知识,希望对你有一定的参考价值。
STC15W408AS单片机3路PWM输出波形实测
分析工具
某宝25就的工具,速度最高是24M的,完全够用了。
- Logic 2.3.41(软件官网即可下载到,不过只支持英文的)
- STC15W408AS在主频11.0592MHZ下逻辑分析仪实时采集的数据
- P35引脚采集的波形数据
- P36引脚采集的波形数据
- P37引脚采集的波形数据
细节放到
- STC15W408AS在主频24MHZ下逻辑分析仪实时采集的数据
- P37引脚采集的波形数据参数显示
- 细节放大
- 局部细节
- 局部细节下,具体数据参数
- P36引脚采集的波形数据参数显示
- P35引脚采集的波形数据参数显示
测试程序(库函数版本)
#include "config.h"
#include "PCA.h"
#include "delay.h"
/************* 功能说明 **************
输出3路9~16位变化的PWM信号。类似"呼吸灯"的驱动.
PWM频率 = MAIN_Fosc / PWM_DUTY, 假设 MAIN_Fosc = 24MHZ, PWM_DUTY = 6000, 则输出PWM频率为4000HZ.
******************************************/
/************* 本地常量声明 **************/
/************* 本地变量声明 **************/
u16 pwm0,pwm1,pwm2;
/************* 本地函数声明 **************/
/************* 外部函数和变量声明 *****************/
void PCA_config(void)
PCA_InitTypeDef PCA_InitStructure;
PCA_InitStructure.PCA_Clock = PCA_Clock_1T; //PCA_Clock_1T, PCA_Clock_2T, PCA_Clock_4T, PCA_Clock_6T, PCA_Clock_8T, PCA_Clock_12T, PCA_Clock_Timer0_OF, PCA_Clock_ECI
PCA_InitStructure.PCA_IoUse = PCA_P34_P35_P36_P37; //PCA_P12_P11_P10_P37, PCA_P34_P35_P36_P37, PCA_P24_P25_P26_P27
PCA_InitStructure.PCA_Interrupt_Mode = DISABLE; //ENABLE, DISABLE
PCA_InitStructure.PCA_Polity = PolityHigh; //优先级设置 PolityHigh,PolityLow
PCA_InitStructure.PCA_RUN = DISABLE; //ENABLE, DISABLE
PCA_Init(PCA_Counter,&PCA_InitStructure);
PCA_InitStructure.PCA_Mode = PCA_Mode_HighPulseOutput; //PCA_Mode_PWM, PCA_Mode_Capture, PCA_Mode_SoftTimer, PCA_Mode_HighPulseOutput
PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit
PCA_InitStructure.PCA_Interrupt_Mode = ENABLE; //PCA_Rise_Active, PCA_Fall_Active, ENABLE, DISABLE
PCA_InitStructure.PCA_Value = 65535; //对于软件定时, 为匹配比较值
PCA_Init(PCA0,&PCA_InitStructure);
PCA_InitStructure.PCA_Mode = PCA_Mode_HighPulseOutput; //PCA_Mode_PWM, PCA_Mode_Capture, PCA_Mode_SoftTimer, PCA_Mode_HighPulseOutput
PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit
PCA_InitStructure.PCA_Interrupt_Mode = ENABLE; //PCA_Rise_Active, PCA_Fall_Active, ENABLE, DISABLE
PCA_InitStructure.PCA_Value = 65535; //对于软件定时, 为匹配比较值
PCA_Init(PCA1,&PCA_InitStructure);
PCA_InitStructure.PCA_Mode = PCA_Mode_HighPulseOutput; //PCA_Mode_PWM, PCA_Mode_Capture, PCA_Mode_SoftTimer, PCA_Mode_HighPulseOutput
PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit
PCA_InitStructure.PCA_Interrupt_Mode = ENABLE; //PCA_Rise_Active, PCA_Fall_Active, ENABLE, DISABLE
PCA_InitStructure.PCA_Value = 65535; //对于软件定时, 为匹配比较值
PCA_Init(PCA2,&PCA_InitStructure);
/******************** task A **************************/
void main(void)
P2M1 &= ~(0xe0); //P2.7 P2.6 P2.5 设置为推挽输出
P2M0 |= (0xe0);
PCA_config();
pwm0 = (PWM_DUTY / 4 * 1); //给PWM一个初值
pwm1 = (PWM_DUTY / 4 * 2);
pwm2 = (PWM_DUTY / 4 * 3);
PWMn_Update(PCA0,pwm0);
PWMn_Update(PCA1,pwm1);
PWMn_Update(PCA2,pwm2);
EA = 1;
while (1)
delay_ms(2);
//if(++pwm0 >= PWM_HIGH_MAX)
pwm0 = PWM_HIGH_MAX;
PWMn_Update(PCA0,pwm0);
//if(++pwm1 >= PWM_HIGH_MAX)
pwm1 = PWM_HIGH_MIN;
PWMn_Update(PCA1,pwm1);
//if(++pwm2 >= PWM_HIGH_MAX)
pwm2 = PWM_HIGH_MIN;
PWMn_Update(PCA2,pwm2);
测试程序资源
链接:https://pan.baidu.com/s/1VNtaWd59ja0mPIW-hEg4eg
提取码:yqux
以上是关于STC15W408AS单片机3路PWM输出波形实测的主要内容,如果未能解决你的问题,请参考以下文章
STC单片机通过ADC外部输入调节PWM占空比输出并串口打印当前脉冲值