lpc1114fn28 timers
lpc1114fn28 timers
LPC1114 Datasheet
7.6 IOCONFIG block
The IOCONFIG block allows selected pins of the microcontroller to have more than one
function. Configuration registers control the multiplexers to allow connection between the
pin and the on-chip peripherals.
Peripherals should be connected to the appropriate pins prior to being activated and prior
to any related interrupt(s) being enabled. Activity of any enabled peripheral function that is
not mapped to a related pin should be considered undefined.
7.12 General purpose external event counter/timers
The LPC1110/11/12/13/14/15 include two 32-bit counter/timers and two 16-bit
counter/timers. The counter/timer is designed to count cycles of the system derived clock.
It can optionally generate interrupts or perform other actions at specified timer values,
based on four match registers. Each counter/timer also includes up to two capture inputs
to trap the timer value when an input signal transitions, optionally generating an interrupt.
7.12.1 Features
• A 32-bit/16-bit timer/counter with a programmable 32-bit/16-bit prescaler.
• Counter or timer operation.
• Up to two capture channels per timer, that can take a snapshot of the timer value
when an input signal transitions. A capture event may also generate an interrupt.
• The timer and prescaler may be configured to be cleared on a designated capture
event. This feature permits easy pulse width measurement by clearing the timer on
the leading edge of an input pulse and capturing the timer value on the trailing edge.
• Four match registers per timer that allow:
– Continuous operation with optional interrupt generation on match.
– Stop timer on match with optional interrupt generation.
– Reset timer on match with optional interrupt generation.
• Up to four external outputs corresponding to match registers, with the following
capabilities:
– Set LOW on match.
– Set HIGH on match.
– Toggle on match.
– Do nothing on match.
7.13 System tick timer
The ARM Cortex-M0 includes a system tick timer (SYSTICK) that is intended to generate
a dedicated SYSTICK exception at a fixed time interval (typically 10 ms).
7.14 Watchdog timer
The purpose of the watchdog is to reset the microcontroller within a selectable time
period.
7.14.1 Features
• Internally resets chip if not periodically reloaded.
• Enabled by software but requires a hardware reset or a watchdog reset/interrupt to be
disabled.
• Incorrect/Incomplete feed sequence causes reset/interrupt if enabled.
• Flag to indicate watchdog reset.
• Programmable 24-bit timer with internal prescaler.
• Selectable time period from (Tcy(WDCLK) 256 4) to (Tcy(WDCLK)
2 24 4) in multiples of Tcy(WDCLK) 4.
...
Cortex-M3 SysTick peripheral — kunilkuda August 10, 2009
http://embeddedfreak.wordpress.com/2009/08/10/cortex-m3-systick-peripheral/
The interesting part of Cortex-M3 is SysTick, an additional timer, provided by ARM, to switch the process context on RTOS. ARM was hoping that by using SysTick, most of RTOS will be portable from vendor to vendors.
...
Hence, here’s the simple demo on how to use SysTick on Cortex-M3.main.c
...
/*
* Override the standard SysTick_Handler() on startup_LPC1766
*/
static unsigned int u32_current_time;
void SysTick_Handler(void)
{
u32_current_time++;
}
int main(void)
{
setup_SysTick();
setup_LEDs();
while (1) {
/* Wait for interrupt..a.k.a sleep until interrupt */
asm volatile ("wfi");
display_current_time();
}
}
*** Blinky ***
http://feng06.blog.163.com/blog/static/13501502013030104542641/7
#include <LPC11xx.h>
static volatile uint32_t TimeTick = 0;
void SysTick_Handler(void)
{
TimeTick++;
}
void delay_ms(uint32_t ms)
{
SysTick->LOAD = (((24000)*ms)-1);
SysTick->VAL = 0;
SysTick->CTRL |= ((1<<1)|(1<<0));
while(!TimeTick);
TimeTick = 0;
SysTick->CTRL =0;
}
int main(void)
{
LPC_GPIO2->DIR = 0xFFF;
while(1)
{
LPC_GPIO2->DATA = 0xAAA;
delay_ms(500);
LPC_GPIO2->DATA = 0x555;
delay_ms(500);
}
}
.END
*** Blinky example by vilaca
http://vilaca.eu/lpc1114/vilaca.eu.lpc1114_102_led_blink.zip
#define LED (1<<9) /* LED D1 connect to PIO1_9 */
int main(void)
{
LPC_SYSCON ->SYSAHBCLKCTRL |= (1 << 8); // Enable Clock for TMR1
LPC_IOCON ->PIO1_9 |= (1 << 0); // PIN1_9 = CT16B1_MAT0
LPC_TMR16B1 ->MR0 = 2000; // 50% Duty Cycle
LPC_TMR16B1 ->PR = 12000;
LPC_TMR16B1 ->MR3 = 4000; // Cycle Length
LPC_TMR16B1 ->MCR |= (1 << 10); // TC Reset on MR3 Match
LPC_TMR16B1 ->PWMC |= (1 << 0); // PWM Mode
LPC_TMR16B1 ->TCR |= (1 << 0); // GO
while (1);
// unreachable
return 0;
*** Blinky example by uMich
http://web.eecs.umich.edu/~prabal/teaching/eecs373-f10/slides/lec21.pdf
// Set a 10ms timer
void TIMER32_0_IRQHandler(void)
{
LPC_TMR32B0->IR = 1;/* clear interrupt flag */
timer32_0_counter++;
return;
}
// And loop forever:
while (1) {
/* Each time we wake up... */
/* Check TimeTick to see whether to set or
clear the LED I/O pin */
if ( (timer32_0_counter%LED_TOGGLE_TICKS) <
(LED_TOGGLE_TICKS/2) )
{
GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
} else {
GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
}
/* Go to sleep to save power between timer
interrupts */
__WFI();
}
.END
No comments:
Post a Comment