Micom_Electric/마이컴_원칩 2011. 5. 15. 22:53
납축전지 회로 설계중
CLK = 8M --> PWM Hz = 32 KHz
CLK = 10M --> PWM Hz = 39 KHz 


LeadAcidBatCharger_LCDxxx.zip


 
// For ATmega8, FastPWM mode is possible only 8bit timer/counter2 & 16bit T/C
// in 8bit T/C2 mode - Output pin = PB4 OC2 (MISO), duty = OCR2
// the Output Compare (OC2) is cleared on the Compare
// Match between TCNT2 and OCR2, and set at BOTTOM
// DDRB=0x08;
// PORTB=0x08;
// TCCR2=0b01101100 (FastPWM, COM21,COM20=[1 0];
// OCR2 = 0 ; duty = 0%
// in 16bit timer/counter mode - Output pin = PB1 OC1A, duty = OCR1A
// Use this mode in order to use PB1 as PB4 is assigned to SD card
void SetupFastPWM(void){
// PWM Hz = clk/[N*(1+TOP)] = 8000000/[1*(1+255)] = 31,250 Hz
DDRB = 0x02;
PORTB = 0x02;
// (COM1A[10]:out chan=A, WGM1310[0101]:FastPWM 8Bit)
// TCCR1A = COM1A1 COM1A0 COM1B1 COM1B0 FOC1A FOC1B WGM11 WGM10
TCCR1A = 0b10000001;  (COM1A=10 for OCR1A out pin, WGM11.10=01)
// TCCR1B = ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10
TCCR1B = 0b00010001;  (WGM13.12=01, prescale=1)
OCR1A = 0;    duty = 0


posted by 털보네i
: