Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: TC Waveform problem
PostPosted: Wed May 25, 2011 9:17 am 
Offline

Joined: Wed May 25, 2011 8:45 am
Posts: 3
Hi everyone,

I am working with the AT91SAM7X256 evaluation board and I would like to create a timer using the waveform mode (I am using TC1).
I tried the Atmel example for the AT917S64 and I adapted it to my board, but it is not working. Indeed, the timer does not start (I used LEDs to check it).
I have checked topics about TC in this forum, but none of them seemed to deal with my problem, so some help would be appreciated.


Here is my code:

Main.c

int main( void )
{

/* Setup any hardware that has not already been configured by the low
level init routines. */
prvSetupHardware();

AT91F_TC1_CfgPIO(); //configure PIO to drive TC1 signal

timer_init();//initialization of the timer

vParTestSetLED(1, 0); //LED DS2 is switched on
//* Start timer1
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG |AT91C_TC_CLKEN ;
vParTestSetLED(0, 0);// LED DS1 should be switched on but it is not the case

}

Timer.c :

void AT91F_TC_Open ( AT91PS_TC TC_pt, unsigned int Mode, unsigned int TimerId)
//* Begin
{
unsigned int dummy;

//* First, enable the clock of the TIMER
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<< TimerId ) ;

//* Disable the clock and the interrupts
TC_pt->TC_CCR = AT91C_TC_CLKDIS ;
TC_pt->TC_IDR = 0xFFFFFFFF ;

//* Clear status bit
dummy = TC_pt->TC_SR;
//* Suppress warning variable "dummy" was set but never used
dummy = dummy;
//* Set the Mode of the Timer Counter
TC_pt->TC_CMR = Mode ;
//* End
}

void timer1_c_irq_handler(void)
{
AT91PS_TC TC_pt = AT91C_BASE_TC1;
unsigned int dummy;

//* Acknowledge interrupt status
dummy = TC_pt->TC_SR;
//* Suppress warning variable "dummy" was set but never used
dummy = dummy;
count_timer1_interrupt++;
numCycleRead++;
}

void timer_init ( void )
//* Begin
{
unsigned int oldHandler;
unsigned int mask ;


count_timer1_interrupt=0;

//* Open timer1
AT91F_TC_Open(AT91C_BASE_TC1,AT91C_TC_WAVESEL_UP_AUTO ,AT91C_ID_TC1);

//* Open Timer 1 interrupt

oldHandler = AT91C_BASE_AIC->AIC_SVR[TIMER1_INTERRUPT_LEVEL];

mask = 0x1 << TIMER1_INTERRUPT_LEVEL ;
//* Disable the interrupt on the interrupt controller
AT91C_BASE_AIC->AIC_IDCR = mask ;
//* Save the interrupt handler routine pointer and the interrupt priority
AT91C_BASE_AIC->AIC_SVR[TIMER1_INTERRUPT_LEVEL] = (unsigned int) timer1_c_irq_handler ;
//* Store the Source Mode Register
AT91C_BASE_AIC->AIC_SMR[TIMER1_INTERRUPT_LEVEL] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | AT91C_ID_TC1 ;
//* Clear the interrupt on the interrupt controller
AT91C_BASE_AIC->AIC_ICCR = mask ;

AT91C_BASE_TC1->TC_IER = AT91C_TC_CPCS; // IRQ enable CPC
AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC1);

//* End
}


Sorry for the long post ; thanks for answering.


Top
 Profile  
 
 Post subject: Re: TC Waveform problem
PostPosted: Wed May 25, 2011 12:25 pm 
Offline

Joined: Thu Dec 02, 2004 2:28 pm
Posts: 454
hello,
you are using TIMER1_INTERRUPT_LEVEL as id for the timer. how is this value defined?

regards
gerhard


Top
 Profile  
 
 Post subject: Re: TC Waveform problem
PostPosted: Wed May 25, 2011 1:40 pm 
Offline

Joined: Wed May 25, 2011 8:45 am
Posts: 3
Actually, this is an interrupt id which is defined nowhere in the Atmel files (this value is 4). In their example, this value is a #define at the beginning of their code.
I contacted Atmel to know if there was an interrupt vector table in the software package (I am pretty new to AT91SAM7X), and they answered that I had to see the Cstartup.s file, but there is nothing defined in it.
I spent some time working on my problem just after sending my previous post, and in fact, there is a problem in the interrupt (the interrupt does not work). I do not know why because I almost exactly did what Atmel told me to do.


Top
 Profile  
 
 Post subject: Re: TC Waveform problem
PostPosted: Wed May 25, 2011 5:23 pm 
Offline

Joined: Thu Dec 02, 2004 2:28 pm
Posts: 454
hello,
i would stronmgly recommend to take a look at the "getting-started-project-at91sam7x-ek". at this project you can learn how to initialize the aic and write the irq handler.

regards
gerhard


Top
 Profile  
 
 Post subject: Re: TC Waveform problem
PostPosted: Thu May 26, 2011 9:15 am 
Offline

Joined: Wed May 25, 2011 8:45 am
Posts: 3
Hi,

Thank you for your answer, I tried it, but unfortunately, it did not work (the program does not come in the interrupt). I do not know what to do, is there a value to change to activate interrupts?
It seems there is something that disables them.

Regards.


Top
 Profile  
 
 Post subject: Re: TC Waveform problem
PostPosted: Sun Jun 05, 2011 2:33 pm 
Offline

Joined: Fri Nov 19, 2010 8:46 pm
Posts: 9
[quote="Laurie"]I tried it, but unfortunately, it did not work.[/quote]

If you get it to work, could you send me a copy of the code ?
I've been trying for a long time to get myself a working timer-interrupt for the Olimex SAM7P256, but I gave up on it.

If I could get the Olimex board working, I'd gladly put the code up, so others could benefit from it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: