151
1841
2166
金牌会员
wnag*** 发表于 2024-8-17 10:54 软件PWM和硬件PWM的区别: 软件PWM:IO口推挽要程序设置 定时器中断需要自己写
使用道具 举报 送花
86
5979
1万
超级版主
vb2*** 发表于 2024-8-17 12:23 打错字了..黑色的条纹.
网*** 发表于 2024-8-17 11:20 任何PWM转模拟信号都会有纹波,只是纹波大小跟后面滤波器特性和负载有关, 要看下实际电路和"嘿嘿的纹波"样子 ...
vb2*** 发表于 2024-8-17 12:24 就是一条条的波纹 我贴到后面
wnag*** 发表于 2024-8-17 12:27 快上图!!!!!!!!!!!!!!!!!
#include <STC8H.H> #include "intrins.h" #include "stdio.h" #define MAIN_Fosc 11059200UL //#define IAP_OFFSET 0x2000 //STC8G1K08 sbit LED=P1^1; unsigned char Counter,Compare; unsigned char KeyNum,Speed; unsigned char dat; void Timer2_Init(void); unsigned char Key(); void Delay(unsigned int xms) //@11.0592MHz { unsigned char data i, j; while(xms) { i = 15; j = 90; do { while (--j); } while (--i); xms--; }} void main() { P1M0 = 0x00; P1M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; EA=1; Timer2_Init(); while(1) { KeyNum=Key(); if(KeyNum==1) { Speed++; Speed%=4; if(Speed==0){Compare=0;} Delay(20); if(Speed==1){Compare=15;} Delay(20); if(Speed==2){Compare=35;} Delay(20); if(Speed==3){Compare=66;} Delay(20); // if(Speed==4){Compare=20;} // if(Speed==5){Compare=1;} } } } void Timer2_Init(void) //10微秒@11.0592MHz { AUXR |= 0x04; //定时器时钟1T模式 T2L = 0x91; //设置定时初始值 T2H = 0xFF; //设置定时初始值 AUXR |= 0x10; //定时器2开始计时 IE2 |= 0x04; //使能定时器2中断 } unsigned char Key() { unsigned char KeyNumber=0; if(P32==0){Delay(20);while(P32==0);Delay(20);KeyNumber=1;} return KeyNumber; } void Timer2_Isr(void) interrupt 12 { Counter++; Counter%=150; if(Counter<Compare) { LED=0; } else { LED=1; } } 复制代码
DebugLab 发表于 2024-8-17 12:27 是示波器显示的图像?
晓*** 发表于 2024-8-17 11:25 “嘿嘿的纹波”是偶发的还是一直有,大概的频率和峰峰值分别有多少,看看是从代码消除还是后级加滤波 ...
vb2*** 发表于 2024-8-17 12:31 手机拍的. 用 stc15 那个实例里面的16位定时器pwm没有
Debu*** 发表于 2024-8-17 12:33 哦LED呀,这是和相机帧率之间存在某种关系导致的
本版积分规则 发表回复 回帖后跳转到最后一页
|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )
GMT+8, 2025-8-24 06:41 , Processed in 0.143492 second(s), 105 queries .
Powered by Discuz! X3.5
© 2001-2025 Discuz! Team.