rezaf
Advanced Member level 4
- Joined
- Apr 11, 2009
- Messages
- 106
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,298
- Location
- Montagram
- Activity points
- 2,147
Hi,
I'm trying to make 1ms interrupt with RC register value compare interrupt in AT91SAM7X with a 18.432MHz crystal.
my calculations are :
Definitions: MUL=25, DIV=5, CSS(clock source selection)=PLL Clock, Prescaler=clock/2
PLLCK = Main OSC*(MUL+1)/DIV
PLLCK = 18432000*(25+1)/5 = 95846400
MCK = 95846400/2(prescaler) = 47923200 MCK = 47923200
Timer clock frequency = MCK/timer clock DIV = 47923200/2 = 23961600 Hz
and according to one of atmel's guides :
RC = t*FTC = 0.001*23961600 = 23961
now with the below code that I written, there is a problem. after powering on the board, only one interrupt occurs and the LED for interrupt function indication blinks once after blinking the LED, the chip don't execute other codes and hangs up even with reading status register of timer and acknowledging the interrupt.
what is the problem ? Please help me to solve the problem.
Thanks,
Regards.
I'm trying to make 1ms interrupt with RC register value compare interrupt in AT91SAM7X with a 18.432MHz crystal.
my calculations are :
Definitions: MUL=25, DIV=5, CSS(clock source selection)=PLL Clock, Prescaler=clock/2
PLLCK = Main OSC*(MUL+1)/DIV
PLLCK = 18432000*(25+1)/5 = 95846400
MCK = 95846400/2(prescaler) = 47923200 MCK = 47923200
Timer clock frequency = MCK/timer clock DIV = 47923200/2 = 23961600 Hz
and according to one of atmel's guides :
RC = t*FTC = 0.001*23961600 = 23961
now with the below code that I written, there is a problem. after powering on the board, only one interrupt occurs and the LED for interrupt function indication blinks once after blinking the LED, the chip don't execute other codes and hangs up even with reading status register of timer and acknowledging the interrupt.
Code:
void timer1_c_irq_handler (void)
{
unsigned int dummy;
dummy = AT91C_BASE_TC1->TC_SR;
dummy = dummy;
T_Counter++;
AT91C_BASE_TC1->TC_CCR |= AT91C_TC_CLKEN | AT91C_TC_SWTRG;
AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, AT91C_PIO_PA2); //Normal work LED notification
delay_ms(500);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, AT91C_PIO_PA2);
}
int main (void)
{
unsigned int dummy ;
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA2); //LED 1
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA3); //LED 2
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC1; // Enable peripheral clock
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; // Disable TC clock
AT91C_BASE_TC1->TC_IDR = 0xFFFFFFFF; // Disable interrupts
dummy = AT91C_BASE_TC1->TC_SR; // Clear status register
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_CPCTRG; // Set mode
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN ; // Enable the Clock counter
AT91C_BASE_TC1->TC_IER = AT91C_TC_CPCS;
AT91C_BASE_AIC->AIC_IDCR = 0x1 << AT91C_ID_TC1;
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC1] = (unsigned int) timer1_c_irq_handler;
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC1] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 4 ;
AT91C_BASE_AIC->AIC_ICCR = 0x1 << AT91C_ID_TC1;
AT91C_BASE_AIC->AIC_IECR = 0x1 << AT91C_ID_TC1;
AT91C_BASE_TC1->TC_RC = 23961;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
while(1)
{
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, AT91C_PIO_PA3); //Normal work LED notification
delay_ms(100);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, AT91C_PIO_PA3);
Func1(); /*first function */
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, AT91C_PIO_PA4); //Normal work LED notification
delay_ms(100);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, AT91C_PIO_PA4);
Func2(); /*second function */
}
}
what is the problem ? Please help me to solve the problem.
Thanks,
Regards.
Last edited: