65536μs。最高40MHz的16位PWM(PulseWidthModulation脉宽调制)定时器,可实现高度精确的变频控制及LED调光控制。16位定时器pwm输出脉宽是65536μs,脉宽是脉冲宽度的缩写,不同的领域,脉冲宽度有不同的含义。
#include <avr/ioh>
void main(void)
{
PORTB=0x00;
DDRB=0x0E;
// T/C1 初始化
TCCR1A=0xA1;
TCCR1B=0x09; //匹配时清零,TOP:255,频率:8M/256=3125K
OCR1A=85; //占空比:1/3
OCR1B=128; //占空比:1/2
// T/C2 初始化
TCCR2=0x69; //匹配时清零,TOP:255,频率:3125K
OCR2=170; //占空比:2/3
while (1);
}
使用M16产生三路PWM的程序,参考一下基本OK
还有个是可调节的PWM程序,我做过仿真了,需要全部留下邮箱传给你;
/
#define KEY PINC0
#define PWMA PORTB3 //17号脚
#define PWMB PORTB4 //18号脚
#include <mega8h>
#include <delayh>
#include <mathh>
unsigned int m=0;
unsigned char xiangxian=0;
bit INIT2=0; //判断是否象限2已经初始化;
bit INIT3=0;
bit INIT4=0;
/下面为四个象限中处理函数,参数为45度平分为255段角度/
inline panduan()
{
if(m<=255)
{
xiangxian=1;
}
else if((m>255)&&(m<511))
{
xiangxian=2;
if(m==256)
{
INIT2=1;
PWMA=0;
OCR1A=0x00;
OCR1B=0xff;
PWMB=1;
}
}
else if((m>=511)&&(m<767))
{
xiangxian=3;
}
else if((m>=767)&&(m<1024))
{
xiangxian=4;
}
else if(m>1024)
{
m=0;
}
}
void xiangxian1(unsigned char degree)
{
PWMA=0;
PWMB=0;
OCR1BL=m;
OCR1AL=255-m;
}
void xiangxian2(unsigned char degree)
{ unsigned char temp;
temp=m-255;
OCR1AL=temp;
OCR1BL=temp;
}
void xiangxian3(unsigned char degree)
{
unsigned char temp;
temp=m-511;
PWMA=1;
PWMB=1;
OCR1BL=255-temp;
OCR1AL=temp;
}
void xiangxian4(unsigned char degree)
{unsigned char temp=0;
temp=m-767;
PWMA=1;
PWMB=0;
OCR1BL=255-temp;
OCR1AL=255-temp;
}
/角度计算函数,负责计算在各个象限中角度对应的PWM输出/
void SET_ANGLE( unsigned char degree)
{
switch (xiangxian)
{
case 1: xiangxian1(degree);break;
case 2: xiangxian2(degree);break;
case 3: xiangxian3(degree);break;
case 4: xiangxian4(degree);break;
default:break;
}
}
void main(void)
{
unsigned char temp;
unsigned char xiangxian=0;
// Declare your local variables here
PORTB=0x187;
DDRB=0x1e;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=P
PORTC=0x01;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=0 State1=T State0=T
PORTD=0x00;
DDRD=0x04;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1000000 kHz
// Mode: Fast PWM top=01FFh
// OC1A output: Inverted
// OC1B output: Inverted
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0xF1;
TCCR1B=0x01;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
PWMA=0;
PWMB=0;
OCR1AL=0xff;
OCR1BL=0x00;
while (1)
{
if(KEY==0)
{
delay_ms(20);
if(KEY==0)
{
m=m+1;
panduan();
SET_ANGLE(m);
PORTD2=!PORTD2;
}
}
};
}
以上就是关于16位定时器pwm输出脉宽多少全部的内容,包括:16位定时器pwm输出脉宽多少、用AVR单片机Atmega16产生两路互补的PWM波去控制全桥逆变电路的程序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)