-
-
Erfahrener Benutzer
Roboter Experte
Ich habe keine Probleme mit dem attiny25. Sowohl mit timer0 als auch mit timer1.
Welchen Sinn hat eine CTC mode mit OCR0A als top und PWM? Genau, keinen.
void initTimer1(void){
//cs13:cs10 = 0010 for 125kHz
//cs13:cs10 = 0001 for 250kHz
//TCCR1 |= (1<<CTC1); // Clear timer/counter on compare match
TCCR1 |= (1<<PWM1A); // Pulse width modulator A enable
TCCR1 |= (1<<COM1A1); // comparator A mode select, 01 here
//TCCR1 |= (1<<COM1A0);
//TCCR1 |= (1<<CS13); // clock select, prescaler
//TCCR1 |= (1<<CS12); // 125kHz
TCCR1 |= (1<<CS11);
//TCCR1 |= (1<<CS10);
GTCCR = 0;
GTCCR |= (1<<PWM1B); // enable PWM B
GTCCR |= (1<<COM1B1); // comparator B mode select
//GTTCR |= (1<<COM1B0); // 10 = clear on compare match
//GTTCR |= (1<<FOC1B); // force output compare match
//GTTCR |= (1<<FOC1A); // force output compare match
//GTTCR |= (1<<PSR1); // Reset the prescaler
OCR1A = 0;
OCR1B = 0;
OCR1C = 255; // maximum value for pwm
//TIMSK |= (1<<OCIE1A); // Output compare match a interrupt enable
PLLCSR |= (1<<PLLE); // enable PLL before enabling it as source for timer1
_delay_us(1); // wait 100us for pll to stabilize
PLLCSR |= (1<<LSM); // low speed mode
// lock detection
// Blocks until lock is detected, i.e. PLOCK = 1
while(!(PLLCSR & (1<<PLOCK)))
;
PLLCSR |= (1<<PCKE); // enable PLL as timer1 clock source
// init dead times
//DTPS1 |= (1<<DTPS11); // dead time prescaler
//DTPS1 |= (1<<DTPS10); // 00 = 1, 11 = 8
/*
// amount of dead cycles coded in binary
DT1A |= (1<<DT1AH3);
DT1A |= (1<<DT1AH2);
DT1A |= (1<<DT1AH1);
DT1A |= (1<<DT1AH0);
DT1A |= (1<<DT1AL3);
DT1A |= (1<<DT1AL2);
DT1A |= (1<<DT1AL1);
DT1A |= (1<<DT1AL0);
*/
}
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- Anhänge hochladen: Nein
- Beiträge bearbeiten: Nein
-
Foren-Regeln
Lesezeichen