Using Timer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using Timer

1,361 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by volter on Fri Nov 05 09:02:51 MST 2010
Can some on give an example of how to use Timers in LPCXpresso PLC1343 ?:confused:

I know how to do them in microcontrollers type 80C52  but this microcontroller more powerful.
0 Kudos
Reply
4 Replies

1,333 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fpg on Fri Mar 18 11:18:53 MST 2011
I'm also in trouble with using timer in my LPC1769. I use timer0, I manage to start it, but I cannot make it stop, I've tried with a couple of methods (I only need one delayed interrupt):

- I set MR0S bit in Match Control Register during configuring timer with CMSIS function TIM_ConfigMatch.
- I tried the CMSIS function TIM_Cmd(LPC_TIM0, DISABLE), which resets enable bit in TCR register.
- I tried to disable interrupt on match by resetting MR0I bit in Match Control Register.
(- During debugging I noticed, that Counter Enable register does not remain one after enabling. At least, it seems so during from the debugger. Why is that... ? )
- It is written in lpc17xx datasheet, that during TCR[1] is set, TC and PC is 0. I tried that and they are 0, but the interrupt yet happens.
- I even tried disabling power supply, by resetting the appropriate bit in PCONP register in debug mode.

I really do not understand why interrupt is happening over and over again...
0 Kudos
Reply

1,333 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Fri Nov 05 15:14:45 MST 2010

Quote: volter
Can you give me a short explanation of what is: DDRB,TCCR1B,PORTB and how it work in lpc1343?



DDRB is for setting input or outpin of the pin, like GPIOnDIR on the 1343(pg 119 of the user manual).

TCCR1B is a configuration register, it includes things such as a prescaler for the clock, how the timer operates ( different modes like CTC- whether you want a configurable match compare or normal mode).  The 1343 has these modes and a prescaler for the clock( pg. 262).  I've also got a lot to learn about the timer, but you can get started with the basic timer example that everyone has access to.

PORTB is for setting the bit on a pin, it is done through GPIOnDATA.


for DDRB and PORTB, gpio.h that is included in the examples has two handy functions that sets the direction and level of the pin like so:

/*****************************************************************************
** Function name:GPIOSetValue
**
** Descriptions:Set/clear a bitvalue in a specific bit position
**in GPIO portX(X is the port number.)
**
** parameters:port num, bit position, bit value
** Returned value:None
**
*****************************************************************************/
static __INLINE void GPIOSetValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal )
{
LPC_GPIO[portNum]->MASKED_ACCESS[(1<<bitPosi)] = (bitVal<<bitPosi);
}

/*****************************************************************************
** Function name:GPIOSetDir
**
** Descriptions:Set the direction in GPIO port
**
** parameters:port num, bit position, direction (1 out, 0 input)
** Returned value:None
**
*****************************************************************************/
static __INLINE void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir )
{
if(dir)
LPC_GPIO[portNum]->DIR |= 1<<bitPosi;
else
LPC_GPIO[portNum]->DIR &= ~(1<<bitPosi);
}
0 Kudos
Reply

1,333 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by volter on Fri Nov 05 13:35:52 MST 2010

Quote: Mike45
i learned timers on avrs using this tutorial - http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=50106

most of everything i learned from that tutorial can be applied to the 1343.  for timing calculations, this equation has served me well :


"Target Timer Count = (1 / Target Frequency) / (1 / Timer Clock Frequency) - 1"

hope it might help you,



Can you give me a short explanation of what is: DDRB,TCCR1B,PORTB and how it work in lpc1343?
0 Kudos
Reply

1,333 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Fri Nov 05 10:14:23 MST 2010
i learned timers on avrs using this tutorial - http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=50106

most of everything i learned from that tutorial can be applied to the 1343.  for timing calculations, this equation has served me well :


"Target Timer Count = (1 / Target Frequency) / (1 / Timer Clock Frequency) - 1"

hope it might help you,
0 Kudos
Reply