TImer's update

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

TImer's update

504 Views
rudomanenko
Contributor II

Hi everyone! I want to implemet simillar to WDT behavior on Timer. The idea is: on timer's interrupt timer is stop, but on the other MR0 is update and timer is go on. The problem that it is doesnt work(
Here is my code:

//-------------------------UART_SECTION------------------------------------
void UART_IRQHandler(void) {
     uint32_t IIR_value = LPC_USART->IIR;
     IIR_value >>= 1;
     
     if (IIR_value & IIR_RDA) {
          USART_Buff[USART_byte_count++] = LPC_USART->RBR;
     }

     timer0_update(WT);
}
//-------------------------------------------------------------------------


//----------------------TIMER_SECTION--------------------------------------
void timer0_init_sub(uint32_t pr, uint32_t tc, uint32_t mcr, uint32_t tcr) {
     if( iInit_T0 )
          return;
     iInit_T0 = 1;
     // Enable TIMER clock to the GPIO domain.
     LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);

     NVIC_DisableIRQ(TIMER_32_0_IRQn);     
     //NVIC_SetPriority( TIMER_32_0_IRQn, 0 );     
     
     LPC_TMR32B0->PR  = pr;
     LPC_TMR32B0->TC  = tc;
     LPC_TMR32B0->MCR = mcr;
     LPC_TMR32B0->TCR = tcr;

     NVIC_SetPriority(TIMER_32_0_IRQn, 3);
     NVIC_EnableIRQ(TIMER_32_0_IRQn);
}


void timer0_init(void) {
     timer0_init_sub(0, 0, 0, 0);
     LPC_TMR32B0->MCR |= 0x01;
     LPC_TMR32B0->IR &= 0x5f;
     LPC_TMR32B0->TCR |= (1 << 1);
     //LPC_TIM32B0->TCR |= 0x01;     
}


void timer0_start(uint32_t time) {
     LPC_TMR32B0->MR0 = time * 4800;  // 0.0001 * time (sec)
     LPC_TMR32B0->TCR = 0x01;
}


void timer0_stop(void) {
     LPC_TMR32B0->TCR = 0;
}


void timer0_reset(void) {
     LPC_TMR32B0->TCR = (1 << 1);
}


uint8_t timer0_performance_check(void) {
     return (LPC_TMR32B0->TCR & 0x01) ? 1 : 0;
}


void timer0_update(uint32_t time) {
     timer0_reset();
     timer0_start(time);
}


void timer0_wait_icc_message(uint32_t waiting_time) {
     timer0_start(waiting_time);
     while(timer0_performance_check());
}


void TIMER32_0_IRQHandler(void) {
     if (LPC_TMR32B0->IR & 0x01) {
          
          timer0_stop();
          timer0_reset();
          LPC_TMR32B0->IR = 1;
     }
}
//-----------------------------------------------------------------

//--------------------MAIN_SECTION---------------------------------

void foo(void) {
      pbDataIn = USART_Buff;
     *pwLngIn = USART_byte_count;
}

//-----------------------------------------------------------------
Labels (4)
1 Reply

387 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Anton Rudomanenko,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
It needs to release the CRST bit in the TCR register, otherwise, the counters remain reset.
So I'd like to use the reset function below instead of the original one.

void TIM_ResetCounter(LPC_TIM_TypeDef *TIMx)
{
    TIMx->TCR |= TIM_RESET;
    TIMx->TCR &= ~TIM_RESET;
}‍‍‍‍‍

Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------