標題:
快速PWM模式
[打印本頁]
作者:
liuqq
時間:
2015-5-21 23:50
標題:
快速PWM模式
#include <iom128v.h>
void main(void)
{
// Port B initialization, PB.5-PB.7輸出PWM
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
PORTB=0xFF;
DDRB=0xFF;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: 相位修正PWM, top=ICR1, PWM頻率50Hz,外部晶振16M
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// OC1C output: Non-Inv.
// 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
// Compare C Match Interrupt: OFF
TCCR1A=0xAA; //普通PWM
TCCR1B=0x10;
//TOP1=FOSC/FPWM/2/64; //64分頻
//ICR1H=TOP1>>8; ICR1L=TOP1&0xFF;
ICR1H=0x09; ICR1L=0xf6; //TOP,64分頻 49Hz PWM, TOP=2550
OCR1AH=0x09;OCR1AL=0xC4; //100%
OCR1BH=0x04;OCR1BL=0xE2; //50%
OCR1CH=0x00;OCR1CL=0xFA; //10%
TCCR1B|=0x03; //啟動T1,64分頻
while(1);
}
復制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1