Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Reg: Timer Interrupt Problems

2005-04-01 by rockraj_2003

Hello Friends,

I am a silent member of this groups.
Now i am doing a project.
In my project, i want to use 2 Timers.

The TIMER1 is setting in the main function it's working perfectly.
But when i call the same in the function Check,it's not responding.

After the function Check i put the arm in the idle mode.
But its not repeating the loop.

I am using IAR Embedded WorkBench only.

The code is as follows:




#include "timer.h"
#include "lpc210x.h"
#include <inarm.h>  
#include <iolpc210x.h>
#include <arm_interrupt.h>


#define BAUDRATE 38400
#define BAUDRATEDIVISOR (PCLKFREQ/(BAUDRATE*16))

#define VIC_TIMER0_bit (1 << VIC_TIMER0) 
#define VIC_TIMER1_bit (1 << VIC_TIMER1) 

static void (*timer_function)();
static void (*timer_function_ONE)();
static short Refr_Rate1 = 990

S8 MA_Stop_TIMER( U8 Channel );

static void TimerInterruptONE()
{
   (*timer_function_ONE)(); 
MA_PutString_UART1("ERROR");
   T1IR = 0xff; 
}

static void TimerInterrupt()
{
  (*timer_function)(); 
	 MA_PutString_UART1("OK");
T0IR = 0xff; 
}

__irq __nested __arm void irq_handler(void)
{
  void (*interrupt_function)();
  unsigned int vector;
  vector = VICVectAddr; 
  interrupt_function = (void(*)())vector;
  (*interrupt_function)();  
  VICVectAddr = 0;        
}

void LPC210xSystemInit()
{
  MEMMAP = 2;
}

void LPC210xInitVIC()
{
  VICProtection = 0;
  VICIntEnClear = 0xffffffbf;
  VICDefVectAddr = (unsigned int)&DefDummyInterrupt;
}

void LPC210xInitTimerInterruptONE(void(*timer_func_ONE)())
{
  timer_function_ONE = timer_func_ONE;

  VICIntSelect &= ~VIC_TIMER1_bit; 
  VICVectAddr6 = (unsigned int)&TimerInterruptONE;
  VICVectCntl6 = 0x20 | VIC_TIMER1; 
  VICIntEnable = VIC_TIMER1_bit;   
}

void LPC210xInitTimerInterrupt(void(*timer_func)())
{
  // Setup timer callback function.
  timer_function = timer_func;

  VICIntSelect &= ~VIC_TIMER0_bit; // IRQ on timer 0 line.
  VICVectAddr1 = (unsigned int)&TimerInterrupt;
  VICVectCntl1 = 0x20 | VIC_TIMER0; // Enable vector interrupt for 
timer 0.
  VICIntEnable = VIC_TIMER0_bit;    // Enable timer 0 interrupt.
}



void Set_Timer()
{
   __disable_interrupt();
   LPC210xSystemInit();
   LPC210xInitTimer();
   __disable_interrupt();
   LPC210xInitVIC();
   LPC210xInitTimerInterrupt(TimerBeat);
   __enable_interrupt();
   LPC210xStartTimer();
  }  
  
  
void Set_Timer_ONE()
{
   __disable_interrupt();
   LPC210xSystemInit();
   LPC210xInitTimerONE();
   __disable_interrupt();
   LPC210xInitVIC();
   LPC210xInitTimerInterruptONE(TimerBeat);
   __enable_interrupt();
   LPC210xStartTimerONE();
  }  
  
void LPC210xInitTimerONE()
{
  T1TCR = 0;
  T1PC = 0;
  T1MR0 = Refr_Rate1;
  T1MCR = 3; 
  T1CCR = 0; 
  T1EMR = 0;
}

void LPC210xInitTimer()
{
  T0TCR = 0; 
T0PC = 0;
  T0MR0 = Refresh_Rate;
  T0MCR = 3; 
  T0CCR = 0; 
  T0EMR = 0; 
}

void LPC210xStartTimerONE()
{
  T1TCR = 1; // Enable timer 1.
}

void LPC210xStartTimer()
{
  T0TCR = 1; // Enable timer 0.
}

 
void check()
{

        Refr_Rate1 = 45 * Refr_Rate1;
        Set_Timer_ONE();
        PCONP = 0X004;
        PCON = 0x01;
        PCONP = 0x01E;
        MA_Stop_TIMER(1);
        Refr_Rate1 = 900;
	MA_PutString_UART1("PROGRAMMED CHECKED");	
 
}



S8 MA_Stop_TIMER( U8 Channel ) 
{
    ENTER_MA_STOP_TIMER;
    switch( Channel )
    {
    case 0:
      {
        T0TCR_bit.CE = 0;        
        break;
      }
      
    case 1:
      {
        T1TCR_bit.CE = 0;        
        break;
      }
        
    default:
      {
        EXIT_MA_STOP_TIMER;
        return MA_ERROR;
      }
    }   
    EXIT_MA_STOP_TIMER;
   return MA_OK;
} /* MA_Stop_TIMER */



void main(void)
{
        short ON=1;
        short FLAG_SETN;
        short i;
        
START:  MA_Reset_SCB();
	MA_Reset_PCB();      
        T0MCR = 0; 
        T1MCR = 0;
      	MA_Init_GPIO();
        IOCLR = 0x00000010;
        Sleep(400000);        
                       
        Refr_Rate1 = 45 * Refr_Rate1;
        Set_Timer_ONE();
        PCONP = 0X004;
        PCON = 0x01;
        PCONP = 0x01E;
        MA_Stop_TIMER(1);
        Refr_Rate1 = 900;
        
        MA_Init_UART1();
	MA_Reset_UART1();
        MA_Init_UART0();
        MA_Reset_UART0();
        
 	IOCLR = 0x00000010;
        Sleep(400000);        
	IOSET = ((unsigned long)1) << 4;
	IOSET = ((unsigned long)1) << 2;
	check();
	PCON = 0x01;		
        else goto START; 
}








Kindly clarify my doubt.

with regards,
Rajendra R

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.