]> www.fi.muni.cz Git - bike-lights.git/commitdiff
pwm clock highspeed mode
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 28 Aug 2012 22:26:52 +0000 (00:26 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 28 Aug 2012 22:27:14 +0000 (00:27 +0200)
pwm.c
pwmled.c

diff --git a/pwm.c b/pwm.c
index af4e4fab2d55391f368d344b3a06f489bceb73a3..0c4f3d081a5b78ddbc9f2493255a17b0da6496bf 100644 (file)
--- a/pwm.c
+++ b/pwm.c
@@ -7,7 +7,7 @@
 void init_pwm()
 {
        /* Async clock */
-       PLLCSR = _BV(LSM) | _BV(PLLE);
+       PLLCSR = _BV(PLLE);
 
        /* Synchronize to the phase lock */
        _delay_ms(1);
@@ -20,8 +20,10 @@ void init_pwm()
        TCCR1B = _BV(7)                         // PWM1X: PWM inversion mode
                | _BV(CS10)                     // no clock prescaling
                ;
+       TC1H = 0x01;
        OCR1C = 0xFF;                           // TOP value
 
+       TC1H = 0x00;
        OCR1D = OCR1B = OCR1A = 0;              // initial stride is 0
 
        DDRB  &= ~(_BV( PB1 ) | _BV( PB3 ) | _BV( PB5 )); // tristate it
@@ -48,6 +50,7 @@ void pwm_off(unsigned char n)
 
 void pwm_set(unsigned char n, unsigned char stride)
 {
+       TC1H = 0x00;
        switch (n) {
        case 0: OCR1A = stride; break;
        case 1: OCR1B = stride; break;
index 4861793ff0fbd0e625df98830bf77e816279bd23..ac0e4445cd803eb1f8b9fc0416ae87915e693b66 100644 (file)
--- a/pwmled.c
+++ b/pwmled.c
@@ -59,8 +59,8 @@ static void inline probing_adc(unsigned char n, uint16_t adcval)
        unsigned char pwm = pwm_probes[n];
 
 #if 0
-       log_byte(n);
        log_byte(0xF4);
+       log_byte(n);
        log_word(adcval);
 #endif
 
@@ -95,17 +95,17 @@ static void inline probing_adc(unsigned char n, uint16_t adcval)
                pwm_off(n);
                // pwm_set(n, 0);
                pwmled_state[n] = ST_OFF;
-               log_byte(n);
                log_byte(0xF1);
+               log_byte(n);
 
                return;
        }
 
-       if (pwm >= 0x60) { // over the maximum!
+       if (pwm >= 0x70) { // over the maximum!
+               pwm_off(n);
                pwmled_state[n] = ST_DISABLED;
-               log_byte(n);
                log_byte(0xF2);
-               pwm_off(n);
+               log_byte(n);
                // pwm_set(n, 0);
                return;
        }