]> git.droids-corp.org - protos/rc_servos.git/blobdiff - main.c
transmit 6 servos instead of 3
[protos/rc_servos.git] / main.c
diff --git a/main.c b/main.c
index e434690b0d80b115296eb201e27d4621fd1a0e4b..f06bc44b4f92191d8be816fe52afd4c7a8d0ccb0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -120,7 +120,7 @@ static void poll_spi(void)
                SPDR = byte1_tx.u8;
        }
        spi_out_idx ++;
-       if (spi_out_idx >= NB_SERVO)
+       if (spi_out_idx >= NB_SERVO * 2)
                spi_out_idx = 0;
 
        /* RX */
@@ -173,16 +173,16 @@ static void poll_input_capture(void)
        if ((TIFR1 & _BV(ICF1)) == 0)
                return;
 
-       sei();
-       icp = ICR1;
        cli();
+       icp = ICR1;
+       sei();
 
-       rising = TCCR1B & _BV(ICES1);
+       rising = !!(TCCR1B & _BV(ICES1));
 
        /* change the edge type */
        TCCR1B ^= _BV(ICES1);
 
-       /* clear the flag */
+       /* clear the flag by writing a one */
        TIFR1 = TIFR1 | _BV(ICF1);
 
        diff = icp - icp_prev;