ctc mode on atmega 328 I'm trying to use CTC mode on Arduino 1 but I have the following problem.
I need to generate an interrupt on threshold B and A and I have set the prescaler to 1 since I want to generate interrupt A at 15999 (correspond to 1ms) and interupt B at 15( ie a number small enough from the start of counting).
I'have write a println function in ISR(A and B) to proof the calling of the latter but the program does not print all the characters in the println function and furthermore the counter does not reset at treshold A but stop his work.
How I can resolve the problem?

Here is the program I wrote:  

void setup() {  
    TCCR1A = 0x00;                // No outputs on compare math, no PWM mode    
    TCCR1B = 1 | (1 &lt;&lt; WGM12);    // Enable CTC mode up to OCR1A and prescaler /1 -&gt; Start
    //TCCR1B = 0b00001001;  
    TCCR1C = 0x00;                // Nothing to set into C register  


    OCR1A = 15999;                // Set Threshold A  
    OCR1B = 15;                // Set Threshold B  
    TCNT1 = 0;                    // Clear Counter  

    TIFR1 = (1 &lt;&lt; OCIE1A) | (1 &lt;&lt; OCIE1B);    // Clear Interrupt flag Match A and B

    TIMSK1 = (1 &lt;&lt; OCIE1A) | (1 &lt;&lt; OCIE1B);   // Enable Interrapt flag Match A and B

    analogRead(A0);            // Dummy Read to make Arduino setting the AD  
    ADCSRA |= (1 &lt;&lt; ADIE);     // Enable AD Interrupt on conversion completed  
    ADCSRB = 5;                // Select Timer 1 Match B as trigger  
    ADCSRA |= 1 &lt;&lt; ADATE;      // Enable Auto trigger  


    Serial.begin(115200);      // Initialize the USART  
    Serial.println("Start");   // Write the welcome message  



}  

void loop() {  
    // Nothing to do    
}  


ISR(ADC_vect)  
{ 
    Serial.print(TCNT1);  
    Serial.print(" - ADC Conversion Completed (");   
    Serial.print(ADC);  
    Serial.println(")");  
}

ISR(TIMER1_COMPA_vect)  
{  
    TCNT1=0;  
    Serial.print(TCNT1);  
    Serial.println(" - Interrupt A");  
}  

ISR(TIMER1_COMPB_vect)  
{  
    Serial.print(TCNT1);  
    Serial.println(" - Interrupt B");  
}
I don't know about configuring the timers on an AVR off hand, but one thing I will point out:


Never ever use Serial in an ISR.


Serial is interrupt driven - when there are characters in the outgoing serial buffer an interrupt routine sends them out through the serial port.  That can't happen when you're in an interrupt routine yourself, so when the buffer fills up the next Serial.write() (print, etc) blocks until there is room in the buffer for the next character.  As the ISR can't run, that space never appears, so the print(), write(), etc never finish and the program locks up.

Instead you should store any incoming values in your ISRs into volatile variables, and set flags to indicate to your main program what has happened in the ISR - then your main loop() reads (and resets) those flags and prints out the statuses you want.