Timer set-up problem LPC 1769

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Fabienvg on Wed Oct 09 08:06:14 MST 2013

I'm really new to microcontrollers. I tried to set up a timer for the LPC 1769 with interrupt, but I think I'm doing something wrong. For example the prescaler. I set it to 1000-1 AND it looks like, when I test my program,  it is set to 1 ms, but I can't imagine it works on only 1 Mhz. I think I'm doing things wrong in the basic configuration. Anyone who can help me out setting up a basic configuration for the timer and interrupt would help me a ton.

User manual: http://www.nxp.com/documents/user_manual/UM10360.pdf

Basic timer configuration starts at page 490.

#define TMR16B0TC  0x40004008
#define PCLKSEL0                  0x400FC1A8
#define TMR16B0IR 0x40004000
#define TMR16B0TCR 0x40004004
#define TMR16B0PR 0x4000400C
#define TMR16B0MR0 0x40004018
#define TMR16B0MCR          0x40004014
#define TMR16B0CTCR         0x40004070
#define PCONP 0x400FC0C4
#define ISER0 0xE000E100

int* pCLKSEL0        = (int*) PCLKSEL0;
int* tMR16B0TCR = (int*) TMR16B0TCR;
int* tMR16B0PR = (int*) TMR16B0PR;
int* tMR16B0MR0 = (int*) TMR16B0MR0;
int* tMR16B0MCR = (int*) TMR16B0MCR;
int* tMR16B0CTCR = (int*) TMR16B0CTCR;
int* tMR16B0IR = (int*) TMR16B0IR;
int* iSER0 = (int*) ISER1;
int* tMR16B0TC = (int*) TMR16B0TC;
int* pCONP = (int*) PCONP;

void (*timer_tmr_callback)();

void init()
*pCONP = 0x2;
*pCLKSEL0    = 0xC;
*tMR16B0TC   = 0x0;
*tMR16B0PR     = 1000 - 1;
*tMR16B0CTCR    = 0;
*tMR16B0MR0 = 1000;
*tMR16B0MCR     = 0x05;

void timer_async_usec( unsigned int msec, void (*callback)())
timer_tmr_callback     = callback;
*tMR16B0MR0    = msec;
*tMR16B0MCR           = 0x07;
*iSER0    = (1 << 1);
*tMR16B0TCR    = 0x2;
*tMR16B0TCR    = 0x1;

void (TIMER0_IRQHandler(void))
*tMR16B0IR = 0x1F;