TIM1 PWM问题求助 请高手一定看看

2025-04-07 20:59:54
推荐回答(1个)
回答1:

我举个例子,设置定时器3的3个通道都输出PWM,即PE3、PE4、PE5,单片机频率7.3728MHz,分频的工作频率是7.2KHz,PWM周期是7200/72=100Hz,输出的3路PWM都是47.2%:

PORTE=0x00;
DDRE=0x38;
 
// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: 7.200 kHz
// Mode: Fast PWM top=ICR3
// OC3A output: Non-Inv.
// OC3B output: Non-Inv.
// OC3C output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0xAA;
TCCR3B=0x1D;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x47;
OCR3AH=0x00;
OCR3AL=0x22;
OCR3BH=0x00;
OCR3BL=0x22;
OCR3CH=0x00;
OCR3CL=0x22;