In the below code ,which part describes Timer is fired every 60 second?

41 Views Asked by At
void TCA0_init()
{
    TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV256_gc| TCA_SINGLE_ENABLE_bm; ;  // Set prescaler to 256
    TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_NORMAL_gc;  // Set timer mode to normal
    TCA0.SINGLE.CNT = 0;                              // Initialize the timer count
    TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm;           // Enable TCA overflow interrupt
     uint16_t ticks = 781249;                       //3.33MHZ*60/256
     TCA0.SINGLE.PER = ticks - 1;
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sei();
}

//volatile uint8_t timerCount = 0;

ISR(TCA0_OVF_vect)
{ 
    timerCount++;
    
    if (timerCount == 120)  // Fire the timer every 60 seconds (120 overflows)
    {
        PORTB.OUT &= ~PIN2_bm;
        _delay_ms(125);
        
        PORTB.OUT |= PIN2_bm;
        _delay_ms(125);
        
    
        PORTB.OUT &= ~PIN3_bm;
        
    timerCount = 0;  // Reset the timer count
    
    TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;
}
}
void TCA0_init()
{
    TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV256_gc| TCA_SINGLE_ENABLE_bm; ;  // Set prescaler to 256
    TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_NORMAL_gc;  // Set timer mode to normal
    TCA0.SINGLE.CNT = 0;                              // Initialize the timer count
    TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm;           // Enable TCA overflow interrupt
     uint16_t ticks = 781249;                       //3.33MHZ*60/256
     TCA0.SINGLE.PER = ticks - 1;
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sei();
}

//volatile uint8_t timerCount = 0;

ISR(TCA0_OVF_vect)
{ 
    //timerCount++;
    
    //if (timerCount == 120)  // Fire the timer every 60 seconds (120 overflows)
    //{
        PORTB.OUT &= ~PIN2_bm;
        _delay_ms(125);
        
        PORTB.OUT |= PIN2_bm;
        _delay_ms(125);
        
    
        PORTB.OUT &= ~PIN3_bm;
        
  //  timerCount = 0;  // Reset the timer count
    
    TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;
//}
}
0

There are 0 best solutions below