原创 基于比较匹配输出的脉冲宽度调制PWM

2024-6-7 18:51 469 2 2 分类: MCU/ 嵌入式 文集: AVR
代码:

/*******************************************************
This program was created by the
CodeWizardAVR V3.12 Advanced
Automatic Program Generator
?Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 2024/6/7
Author  : 
Company : 
Comments: 


Chip type               : ATmega16
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*******************************************************/

#include 

// Declare your global variables here
flash unsigned char auc_SinParam[128]={
128,134,140,147,153,159,165,171,177,182,188,
193,199,204,209,213,218,222,226,230,234,237,
240,243,245,248,250,251,253,254,254,255,255,
255,254,254,253,251,250,248,245,243,240,237,
234,230,226,222,218,213,209,204,199,193,188,
182,177,171,165,159,153,147,140,134,128,122,
116,109,103,97,91,85,79,74,68,63,57,52,47,43,
38,34,30,26,22,19,16,13,11,8,6,5,3,2,2,1,1,1,
2,2,3,5,6,8,11,13,16,19,22,26,30,34,38,43,47,
52,57,63,68,74,79,85,91,97,103,109,116,122};
unsigned char x_SW=8,X_LUT=0;
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
    X_LUT+=x_SW;
    if(X_LUT>127) X_LUT-=128;
    OCR0=auc_SinParam[X_LUT];
    
}
void main(void)
{
// Declare your local variables here
     DDRB=0X08;
     TCCR0=0X69;
     OCR0=128;
     TIMSK=0X01;
     #asm("sei");

while (1)
      {
      // Place your code here

      }
}
仿真效果图:

文章评论0条评论)

登录后参与讨论
我要评论
0
2
关闭 站长推荐上一条 /2 下一条