Skip to content

Instantly share code, notes, and snippets.

@snilard
Created October 20, 2013 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save snilard/7063307 to your computer and use it in GitHub Desktop.
Save snilard/7063307 to your computer and use it in GitHub Desktop.
Nefungující vypnutí PWM.
// 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