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  [ 12 posts ] 
Author Message
 Post subject: my program can't work normal
PostPosted: Thu Jan 14, 2010 11:05 am 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
The code as below:
Code:

#include <AT91SAM7S64.H>                    /* AT91SAM7S64 definitions */
#include <board.h>

#ifdef ERAM                                 /* Fast IRQ functions Run in RAM */
#define __atr __ram
#else
#define __atr
#endif

void time0_int(void) __irq __atr{


 

if(num1==0)
{
*AT91C_PIOA_CODR=LED2;
  num1=1;
}
else
{
  *AT91C_PIOA_SODR=LED2;
  num1=0;
  }
 
AT91C_BASE_TC0->TC_CCR=AT91C_TC_CLKEN|AT91C_TC_SWTRG;
   *AT91C_AIC_EOICR = 0;

}

void init_time0(void)
{
AT91S_AIC * pAIC = AT91C_BASE_AIC;
AT91C_BASE_TC0->TC_CCR=AT91C_TC_CLKDIS;
AT91C_BASE_TC0->TC_IDR=0xffffffff;
AT91C_BASE_TC0->TC_CMR=AT91C_TC_CLKS_TIMER_DIV5_CLOCK|
                                  AT91C_TC_CPCTRG;

AT91C_BASE_TC0->TC_RC=0x00ff;
AT91C_BASE_TC0->TC_IER=AT91C_TC_CPCS;


pAIC->AIC_SMR[AT91C_ID_TC0] = AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED| 0;
  pAIC->AIC_SVR[AT91C_ID_TC0] = (unsigned long) time0_int;
  pAIC->AIC_IECR = (1 << AT91C_ID_TC0);
AT91C_BASE_TC0->TC_CCR=AT91C_TC_CLKEN|AT91C_TC_SWTRG;


}




I used the Keil 3 to compile the program,but the situation was that the LED2 only changed once. What was wrong with it??? I couldn't find out the reason for a week??? Help me please,friend!!!!


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Thu Jan 14, 2010 1:28 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

I think that you need to clear the timer interrupt in your interrupt routine by reading the timer status register.

Probably the interrupt is firing all the time and so the LED is blinking very fast - looking like it changes only once.

Regards

Mark

www.uTasker.com


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Thu Jan 14, 2010 4:25 pm 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
Hi,friend:
Do you have the similar program (time0 interrupt)which can be compiled by Keil 3? You can post it on the thread. :) :) :)


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Thu Jan 14, 2010 4:35 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

Code:
static __interrupt void timer0_Interrupt(void)
{
    volatile unsigned int dummy;
    dummy = TC_SR_0;                                                     // read the status to reset interrupt
    ....
}


You just need to use the SR define according to your headers.

Regards

Mark


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Fri Jan 15, 2010 4:29 am 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
You are right. I have add a sentence as below:
Code:

unsigned int dat;
  dat=AT91C_BASE_TC0->TC_SR;


But the datasheet didn't tell us to read the TC_SR register in the interrupt


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Fri Jan 15, 2010 5:00 am 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
I have changed my program as below:
Code:

void time0_int(void) __irq __atr{
unsigned int dat;

  dat=AT91C_BASE_TC0->TC_SR;
//  putchar(dat);
//   putchar(dat>>8);
  //dat=AT91C_BASE_TC0->TC_RC;
//    putchar(dat);
//   putchar(dat>>8);
     dat=AT91C_BASE_TC0->TC_CV;
    putchar(dat);
   putchar(dat>>8);

if(num1==0)
{
*AT91C_PIOA_CODR=LED2;
  num1=1;
}
else
{
  *AT91C_PIOA_SODR=LED2;
  num1=0;
  }
 
AT91C_BASE_TC0->TC_CCR=AT91C_TC_CLKEN|AT91C_TC_SWTRG;
   *AT91C_AIC_EOICR =0;

}

void init_time0(void)
{
AT91S_AIC * pAIC = AT91C_BASE_AIC;
AT91C_BASE_TC0->TC_CCR=AT91C_TC_CLKDIS;
AT91C_BASE_TC0->TC_IDR=0xffffffff;
AT91C_BASE_TC0->TC_CMR=AT91C_TC_CLKS_TIMER_DIV5_CLOCK|
                                AT91C_TC_CPCTRG;
                                 

AT91C_BASE_TC0->TC_RC=0x1f0f;
AT91C_BASE_TC0->TC_IER=AT91C_TC_CPCS;


pAIC->AIC_SMR[AT91C_ID_TC0] = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE |0;
  pAIC->AIC_SVR[AT91C_ID_TC0] = (unsigned long) time0_int;
  pAIC->AIC_IECR = (1 << AT91C_ID_TC0);
AT91C_BASE_TC0->TC_CCR=AT91C_TC_CLKEN|AT91C_TC_SWTRG;


}


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Fri Jan 15, 2010 5:09 am 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
Thank you very much, mibcswitzerland. :D :D

My program work success. I found that wether I added the sentences(AT91C_BASE_TC0->TC_CCR=AT91C_TC_CLKEN|AT91C_TC_SWTRG;) in the interrupt routine, the program can work success. Do I have to reserve or delete the sentence??

second was that the data from the USART was 0x0000. I think it was right.

Do I have to add or delete some sentences in the program to improve the program??


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Fri Jan 15, 2010 10:15 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

I think that the timer configuration that you are using is periodic and so the timer doesn't need to be restarted in the in the interrupt routine.

If you want a single-shot timer the bits CPCDIS and/or CPCSTOP can be set in TC_CMR. These disabled or stop the counter on match.

Regards

Mark


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Sat Jan 16, 2010 3:06 am 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
mjbcswitzerland, I have got it. :D :D :D

I found that you are good at the AT91S. Can you give me some advances in my new post "ADC conversion program".

anther question is that I knew EXT_OC 18432000
but why the MCK is 2.6 times than the EXT_OC. Is there any formula or it is just a regular value??

cheng_bei


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Sat Jan 16, 2010 12:30 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

The master clock is 2.6x the oscillator if the PLL is programmed to generate 48MHz.

Typically ((Oscillator / 14) * 73 ) 2)

See chapter 25 in the user's manual.

Regards

Mark


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Mon Jan 18, 2010 4:04 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Check that you have the latest user's manual from the ATMLE web site: http://www.atmel.com/products/at91/default.asp


Top
 Profile  
 
 Post subject: Re: my program can't work normal
PostPosted: Wed Jan 20, 2010 12:26 pm 
Offline

Joined: Sun Dec 27, 2009 1:40 pm
Posts: 10
Thank you. I have to put more time on reading the user's manual and improve the knowledge of AT91S.


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

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 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: