Quiero calcular el tiempo de actividad de LPC 1768 desde que comienza a funcionar. por ejemplo una función como millis(); en arduino
Le sugiero que configure un temporizador de hardware que incremente un contador cada milisegundo. Al leer este valor, sabrá su tiempo de actividad.
Uso el siguiente código que usa el periférico RIT (Temporizador de interrupción repetitiva). Este es un periférico temporizador muy simple. Esto le permitirá utilizar los temporizadores completos y el temporizador de marcación del sistema ARM para otros usos:
volatile uint32_t rit_high = 0;
static void rit_irq_handler()
/////////////////////////////
{
// Clear interrupt pending flag:
LPC_RIT->RICTRL = (1<<0) | // clear interrupt flag
(1<<1) | // clear counter on overflow
(1<<3); // timer enable
// increase high counter:
rit_high++;
// memory barrier. Makes sure that the interrupt pending flag
// gets written before we exit the ISR
__DMB();
}
void stopwatch_start (void)
///////////////////////////
{
NVIC_DisableIRQ(RIT_IRQn);
rit_high = 0;
// configure and set handler to highestpriority:
NVIC_SetVector(RIT_IRQn, (uint32_t)rit_irq_handler);
NVIC_SetPriority(RIT_IRQn, 0);
// power on the Repeative Interrupt Timer:
LPC_SC->PCONP |= (1<<16);
// init timer with defaults:
LPC_RIT->RICOUNTER = 0;
LPC_RIT->RICOMPVAL = ~0;
LPC_RIT->RIMASK = 0;
LPC_RIT->RICTRL = (1<<0) | // clear interrupt flag
(1<<1) | // clear counter on overflow
(1<<3); // timer enable
NVIC_EnableIRQ(RIT_IRQn);
}
void stopwatch_stop (void)
//////////////////////////
{
NVIC_DisableIRQ(RIT_IRQn);
LPC_RIT->RICTRL = (1<<0) | // clear interrupt flag
(1<<1) | // clear counter on overflow
(0<<3); // timer disable
}
static uint64_t stopwatch_getval (void)
//////////////////////////////////////
{
return (uint64_t(rit_high)<<32) | LPC_RIT->RICOUNTER;
}
uint64_t stopwatch_getclk (void)
////////////////////////////////
{
uint64_t a,b;
a = stopwatch_getval();
while (1)
{
b = stopwatch_getval();
if (b>=a) return b;
a = b;
}
}
uint32_t stopwatch_getms (void)
///////////////////////////////
{
return stopwatch_getclk() / (CORE_FREQ/1000);
}
uint64_t stopwatch_getus (void)
///////////////////////////////
{
return stopwatch_getclk() / (CORE_FREQ/1000000);
}
Configure CORE_FREQ
la velocidad del periférico RIT, de forma predeterminada, esa es la frecuencia de su CPU dividida por 4. Si desea que el temporizador se ejecute a la máxima velocidad de la CPU, puede hacerlo reprogramando el registro de esta manera PCLKSEL1
:
// RIT: Set perpheral clock divider to 1:
LPC_SC->PCLKSEL1 = (LPC_SC->PCLKSEL1 & ~(3<<26)) | (1<<26);
Desea hacer esto antes de activar el PLL0 (la razón de esto se encuentra en el documento de errata LPC1768), por lo que este código debe colocarse en el inicio de su sistema. Este es probablemente el archivo system_LPC17xx.c
.
usuario_1818839
Blup1980