| Welcome to AT91SAM Community Forum http://www.at91.com/samphpbb/ |
|
| my program can't work normal http://www.at91.com/samphpbb/viewtopic.php?f=15&t=18877 |
Page 1 of 1 |
| Author: | cheng_bei [ Thu Jan 14, 2010 11:05 am ] |
| Post subject: | my program can't work normal |
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!!!! |
|
| Author: | mjbcswitzerland [ Thu Jan 14, 2010 1:28 pm ] |
| Post subject: | Re: my program can't work normal |
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 |
|
| Author: | cheng_bei [ Thu Jan 14, 2010 4:25 pm ] |
| Post subject: | Re: my program can't work normal |
Hi,friend: Do you have the similar program (time0 interrupt)which can be compiled by Keil 3? You can post it on the thread. |
|
| Author: | mjbcswitzerland [ Thu Jan 14, 2010 4:35 pm ] |
| Post subject: | Re: my program can't work normal |
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 |
|
| Author: | cheng_bei [ Fri Jan 15, 2010 4:29 am ] |
| Post subject: | Re: my program can't work normal |
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 |
|
| Author: | cheng_bei [ Fri Jan 15, 2010 5:00 am ] |
| Post subject: | Re: my program can't work normal |
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; } |
|
| Author: | cheng_bei [ Fri Jan 15, 2010 5:09 am ] |
| Post subject: | Re: my program can't work normal |
Thank you very much, mibcswitzerland. 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?? |
|
| Author: | mjbcswitzerland [ Fri Jan 15, 2010 10:15 pm ] |
| Post subject: | Re: my program can't work normal |
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 |
|
| Author: | cheng_bei [ Sat Jan 16, 2010 3:06 am ] |
| Post subject: | Re: my program can't work normal |
mjbcswitzerland, I have got it. 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 |
|
| Author: | mjbcswitzerland [ Sat Jan 16, 2010 12:30 pm ] |
| Post subject: | Re: my program can't work normal |
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 |
|
| Author: | mjbcswitzerland [ Mon Jan 18, 2010 4:04 pm ] |
| Post subject: | Re: my program can't work normal |
Check that you have the latest user's manual from the ATMLE web site: http://www.atmel.com/products/at91/default.asp |
|
| Author: | cheng_bei [ Wed Jan 20, 2010 12:26 pm ] |
| Post subject: | Re: my program can't work normal |
Thank you. I have to put more time on reading the user's manual and improve the knowledge of AT91S. |
|
| Page 1 of 1 | All times are UTC + 1 hour [ DST ] |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|



Forum