2016-07-16 114 views
1

我試圖讓atxmega16e5上的TCC4工作。我的問題是比較通道中斷只觸發一次。 Interrupt標誌甚至被設置爲beeing,但ISR從未被執行。我啓用了溢出中斷,這一直很好。我已經在模擬器和我的實際芯片上進行了測試,結果相同。我正在使用Atmel軟件框架。我真的感覺到我缺少一些有趣的東西,而我只是無法弄清楚。AVR Xmega16E5定時器只創建一個cc中斷

下面是代碼:

#define TIMER_TC    TCC4 
#define TIMER_INT_LVL   TC45_INT_LVL_LO 

int main (void) { 
    sysclk_init(); 
    eeprom_enable_mapping(); 
    board_init(); 
    pmic_init(); 

    timer_init(); 
    timer_set_top(100); 

    cpu_irq_enable(); 

    timer_start(); 

    while(1) {} 
} 

void timer_cca(void) { //Breakpoint here - reached just once 
} 

void timer_ccb(void) { //Breakpoint here - reached just once 
} 

void timer_ccc(void) { //Breakpoint here - reached just once 
} 

void timer_ccd(void) { //Breakpoint here - reached just once 
} 

void timer_overflow(void) { //Breakpoint here - reached multiple times 
} 

void timer_init() { 
    tc45_enable(&TIMER_TC); 
    tc45_set_wgm(&TIMER_TC, TC45_WG_NORMAL); 
    tc45_enable_cc_channels(&TIMER_TC, TC45_CCACOMP | TC45_CCBCOMP | TC45_CCCCOMP | TC45_CCDCOMP); 
    tc45_set_cca_interrupt_callback(&TIMER_TC, &timer_cca); 
    tc45_set_cca_interrupt_level(&TIMER_TC, TIMER_INT_LVL); 
    tc45_set_ccb_interrupt_callback(&TIMER_TC, &timer_ccb); 
    tc45_set_ccb_interrupt_level(&TIMER_TC, TIMER_INT_LVL); 
    tc45_set_ccc_interrupt_callback(&TIMER_TC, &timer_ccc); 
    tc45_set_ccc_interrupt_level(&TIMER_TC, TIMER_INT_LVL); 
    tc45_set_ccd_interrupt_callback(&TIMER_TC, &timer_ccd); 
    tc45_set_ccd_interrupt_level(&TIMER_TC, TIMER_INT_LVL); 

    tc45_write_cc(&TIMER_TC, TC45_CCA, 1); 
    tc45_write_cc(&TIMER_TC, TC45_CCB, 1); 
    tc45_write_cc(&TIMER_TC, TC45_CCC, 1); 
    tc45_write_cc(&TIMER_TC, TC45_CCD, 1); 

    tc45_set_overflow_interrupt_level(&TIMER_TC, TC45_INT_LVL_LO); 
    tc45_set_overflow_interrupt_callback(&TIMER_TC, &timer_overflow); 
} 

void timer_start() { 
    tc45_write_clock_source(&TIMER_TC, TC45_CLKSEL_DIV64_gc); 
} 

void timer_set_top(uint16_t top) { 
    tc45_write_period(&TIMER_TC, top); 
} 

回答

2

這裏的鏈接,以處理通道ASF快速入門文檔比較使用TC45中斷: http://asf.atmel.com/docs/3.11.0/xmegae/html/xmega_tc45_quickstart.html#xmega_tc45_qs_cc

看起來你靠近。唯一真正的區別我看到的是他們宣稱的集成多業務路由器靜態無效的,並直接傳遞他們到set_callback功能,而不是傳遞指針:
tc45_set_cca_interrupt_callback(&TIMER_TC, timer_cca);

代替:
tc45_set_cca_interrupt_callback(&TIMER_TC, &timer_cca);

我還要補充CC通道周圍的圓括號使您能夠放心:
tc45_enable_cc_channels(&TIMER_TC, (TC45_CCACOMP | TC45_CCBCOMP | TC45_CCCCOMP | TC45_CCDCOMP));

嘗試增加比較值。在復位計數器併爲溢出中斷提供服務後,調試器的速度可能不足以捕獲比較值1。

如果仍然遇到問題,請嘗試手動清除ISR中的CCxIF。也許它不會像它應該的那樣自動進行。