Created
October 20, 2013 00:29
-
-
Save snilard/7063307 to your computer and use it in GitHub Desktop.
Nefungující vypnutí PWM.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tímhle PWM zapínám | |
power_timer1_enable(); | |
PLLCSR |= (1<<PLLE) | (1<<LSM); // PLL start (high speed clock in 32 MHz mode) | |
_delay_us(150); // 100 us in datasheet | |
while(! (PLLCSR & (1<<PLOCK))); | |
PLLCSR |= (1<<PCKE); // setting PCK as clock source | |
//OC1B Connected, clear in Compare Match | |
//Enable PWM based on comparator OCR1B and OCR1D | |
TCCR1A |= (1<<COM1B1); // pwm front | |
TCCR1C |= (1<<COM1D1); //pwm rear | |
TCCR1D &= ~((1<<WGM11) | (1<<WGM10)); // Fast PWM Mode | |
// setting frequency etc. | |
TC1H = 0; // Setting output low to 0 | |
OCR1B = 0; | |
TC1H = 0; // Setting output high to 0 | |
OCR1D = 0; | |
TC1H = PWM_TOP >> 8; // Setting top | |
OCR1C = (uint8_t)PWM_TOP; | |
TIMSK = 0x00; // no timer interrupt | |
TIMSK |= (1 << OCIE0A); | |
TCCR1B |= (1<<CS10); | |
// Tímhle PWM potažmo časovač vypínám | |
PLLCSR &= ~(1<<PLLE); // PLL stop (high speed clock) | |
TCCR1B &= ~(1<<CS10); | |
power_timer1_disable(); | |
// Tímhle se snažím uvést porty do původního stavu a zapnout zadní ledky natvrdo bez PWM | |
TCCR1A &= ~(1<<COM1B1 | 1<<PWM1B); // pwm front | |
TCCR1C &= ~(1<<COM1D1 | 1<<PWM1D); //pwm rear | |
PORTB |= (1<<LED_PWM_REAR); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment