]> www.fi.muni.cz Git - tinyboard.git/commitdiff
Merge branch 'master' of ssh://anxur.fi.muni.cz/~kas/html/git/tinyboard
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 10 May 2013 20:14:12 +0000 (22:14 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 10 May 2013 20:14:12 +0000 (22:14 +0200)
 especially if it merges an updated upstream into a topic branch.

projects/step-up/control.c
projects/step-up/pwm.c

index c8c38cd0b41ae075ce5e7a95a95f3199f6b6499c..97a23cbb7d3e8b2033098cc5081690b42d11e6a9 100644 (file)
@@ -20,7 +20,7 @@ static pattern_t blink_pattern[] = {
 
 static pattern_t slow_pattern[] = {
        { 1, 0x1 },
-       { 0, 0x1F },
+       { 0, 0x10 },
        PATTERN_END
 };
 
index e3b477c26b34345e4316c5e846796fbd8f11b313..42ed777357eba68b6d8853e28c92891bd5298e06 100644 (file)
  * Counts from 0 to 0xFF, without OCR1C compare.
  */
 
+static unsigned char pwm_enabled;
+
 static void inline enable_pll()
 {
        /* Async clock */
-       PLLCSR = _BV(PLLE);
+       PLLCSR = _BV(PLLE) | _BV(LSM);
 
        /* Synchronize to the phase lock */
        _delay_us(100);
@@ -25,17 +27,16 @@ static void inline enable_pll()
 
 void init_pwm()
 {
+       pwm_enabled = 0;
        power_timer1_enable();
 
-       enable_pll();
-
-       TCCR1 = _BV(CTC1) | _BV(CS10);  // no clock prescaling
+       TCCR1 = _BV(CTC1) | _BV(CS11);  // pll_clk/2
        GTCCR = _BV(COM1B1) | _BV(PWM1B);
 
        OCR1C = PWM_MAX;
        OCR1B = 0;              // initial stride is 0
 
-       DDRB  &= ~_BV(PB4); // tristate it
+       DDRB &= ~(_BV( PB4 ));
        PORTB &= ~_BV(PB4); // set to zero
 }
 
@@ -54,10 +55,18 @@ void pwm_off()
 {
        OCR1B = 0;
        DDRB &= ~_BV(PB4);
+
+       PLLCSR &= ~(_BV(PLLE) | _BV(PCKE));
+       pwm_enabled = 0;
 }
 
 void pwm_set(uint8_t stride)
 {
        OCR1B = stride;
-       DDRB |= _BV(PB4);
+
+       if (!pwm_enabled) {
+               enable_pll();
+               DDRB |= _BV(PB4);
+               pwm_enabled = 1;
+       }
 }