This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Generating variable frequency in LPC11xx

Hi all!!

How to generate variable frequency in lpc11xx controller, currently i'm getting
fixed frequency on pin 27[CT16B0_MAT0] of 96.2hz, but I need to generate freq from
6hz to 20hz.

Below is the part of the code which I have compared:

void init_timer16(uint8_t timer_num, uint32_t TimerInterval)
{
  if ( timer_num == 0 )
  {

    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);
    LPC_IOCON->PIO0_2           &= ~0x07;        /*  Timer0_16 I/O config */
    LPC_IOCON->PIO0_2           |= 0x02;             /* Timer0_16 CAP0 */
    LPC_IOCON->PIO0_8           &= ~0x07;
    LPC_IOCON->PIO0_8           |= 0x02;             /* Timer0_16 MAT0 */
    LPC_IOCON->PIO0_9           &= ~0x07;
    LPC_IOCON->PIO0_9           |= 0x02;             /* Timer0_16 MAT1 */
#ifdef __JTAG_DISABLED
    LPC_IOCON->JTAG_TCK_PIO0_10 &= ~0x07;
    LPC_IOCON->JTAG_TCK_PIO0_10 |= 0x03;             /* Timer0_16 MAT2 */
#endif

    timer16_0_counter = 0;
    LPC_TMR16B0->MR0 = TimerInterval;

    LPC_TMR16B0->MCR = 3;                            /* Interrupt and Reset on MR0 */

    /* Enable the TIMER0 Interrupt */
    NVIC_EnableIRQ(TIMER_16_0_IRQn);
  }
  else if ( timer_num == 1 )
  {

    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);
    LPC_IOCON->PIO1_8           &= ~0x07;        /*  Timer1_16 I/O config */
    LPC_IOCON->PIO1_8           |= 0x01;             /* Timer1_16 CAP0 */
    LPC_IOCON->PIO1_9           &= ~0x07;
    LPC_IOCON->PIO1_9           |= 0x01;             /* Timer1_16 MAT0 */
    LPC_IOCON->PIO1_10          &= ~0x07;
    LPC_IOCON->PIO1_10          |= 0x02;             /* Timer1_16 MAT1 */

    timer16_1_counter = 0;
    LPC_TMR16B1->MR0 = TimerInterval;
    LPC_TMR16B1->MCR = 3;                            /* Interrupt and Reset on MR1 */

    /* Enable the TIMER1 Interrupt */
    NVIC_EnableIRQ(TIMER_16_1_IRQn);
  }
  return;
}

Kindly suggest how to process further.

Thank you.

Parents Reply Children
  • I have changed the value of parameter timer interval & checked the output of
    Timer16B0 of MAT0 pin no 27[PIO0_8] to check the o/p connected an led across
    this pin but led goes high but it not returns to low & high state.
    Please check the first part of code[since the msg txt is too long] below. Help me how to attach the complete code.

    #include <stdio.h>
     #include "LPC11xx.h"
    
    unsigned char msTicks;
    volatile uint32_t timer16_0_counter[4] = {0,0,0,0};
    volatile uint32_t timer16_1_counter[4] = {0,0,0,0};
    volatile uint32_t timer16_0_capture[4] = {0,0,0,0};
    volatile uint32_t timer16_1_capture[4] = {0,0,0,0};
    volatile uint32_t timer16_0_period = 0;
    volatile uint32_t timer16_1_period = 0;
    
    /*****************************************************************************
    ** Function name:               delayMs
    **
    ** Descriptions:                Start the timer delay in milo seconds
    **                                              until elapsed
    **
    ** parameters:                  timer number, Delay value in milo second
    **
    ** Returned value:              None
    **
    *****************************************************************************/
    void delayMs(uint8_t timer_num, uint32_t delayInMs)
    {
      if (timer_num == 0)
      {
        /*
        * setup timer #0 for delay
        */
        LPC_TMR16B0->TCR = 0x02;         /* reset timer */
        LPC_TMR16B0->PR  = 0x00;         /* set prescaler to zero */
        LPC_TMR16B0->MR0 = delayInMs * (SystemCoreClock / 1000);
        LPC_TMR16B0->IR  = 0xff;         /* reset all interrrupts */
        LPC_TMR16B0->MCR = 0x04;         /* stop timer on match */
        LPC_TMR16B0->TCR = 0x01;         /* start timer */
        /* wait until delay time has elapsed */
        while (LPC_TMR16B0->TCR & 0x01);
      }
      else if (timer_num == 1)
      {
        /*
        * setup timer #1 for delay
        */
        LPC_TMR16B1->TCR = 0x02;         /* reset timer */
        LPC_TMR16B1->PR  = 0x00;         /* set prescaler to zero */
        LPC_TMR16B1->MR0 = delayInMs * (SystemCoreClock / 1000);
        LPC_TMR16B1->IR  = 0xff;         /* reset all interrrupts */
        LPC_TMR16B1->MCR = 0x04;         /* stop timer on match */
        LPC_TMR16B1->TCR = 0x01;         /* start timer */
        /* wait until delay time has elapsed */
        while (LPC_TMR16B1->TCR & 0x01);
      }
      return;
    }