XMEGA E5 timer problems

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I must be doing something obviously wrong here, but can't see it. I have timer 5 (though the same thing happens with timer 4) in normal mode. The ISR simply pulses a GPIO so I can monitor it on my scope. I am getting pulses 28.4us apart, regardless of changing the prescaler or period value.
I am using an xmega 8E5 with the default internal 2MHz clock.
Thanks.
/mike

#include 
#include 
#include 
#include 
#include 
#include 
#include  

#define RTC_COMPARE_VALUE 20  

int main( void )
{
    uint8_t reset_status;		// Why were we reset?
  
  // Save and clear reset status
    reset_status = RST_STATUS;
    RST_STATUS = 0xFF; 
    
  // Set up PMIC
    PMIC.CTRL = PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm;
  // Set up RTC
    CLK.RTCCTRL = CLK_RTCSRC_ULP_gc | CLK_RTCEN_bm; // Run off ULP 32kHz oscillator 
    RTC.PER = RTC_COMPARE_VALUE-1;
    RTC.INTCTRL = RTC_OVFINTLVL_LO_gc; 
    RTC.INTFLAGS = RTC_OVFIF_bm;
    RTC.CTRL = 0x01; // RTC prescaler = RTC clock/1 
  // Set up timer
    TCC5.CTRLA = TC45_CLKSEL_DIV64_gc; // Prescaler = 2 
    TCC5.CTRLB = TC45_WGMODE_NORMAL_gc;
    TCC5.INTCTRLA = TC45_OVFINTLVL_LO_gc;
    TCC5.PER = 100;
    TCC5.CNT = 0;

    PORTA.DIR = 0xFE; // All out except PA0 (analog in)
    PORTA.OUT = 0xFE;
    __enable_interrupt();    
    while(1)
    {
    }
}

#pragma vector = RTC_OVF_vect
__interrupt void RTC_OVF_ISR(void)
{
 ;
}

#pragma vector= TCC5_OVF_vect    
__interrupt void TCC5_OVF_ISR(void) 
{
    PORTA.OUTTGL = 0xFF;
    PORTA.OUTTGL = 0xFF;
}
Last Edited: Tue. May 6, 2014 - 05:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this may have something to do with your problem, but you need to clear overflow in ISR.
could be it is automatically re-setting ?

don't forget the RTC ovf aswell

I'm get pulses @ ~310Hz which works out correct I think

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I said that I was missing something obvious. The timer overflow interrupt flag (unlike many others, like the RTC overflow) does not get automatically cleared by entering the ISR. Adding a line to the ISR to reset OVFIF fixed things.
/mike