lpcware

Generating variable frequency in LPC11xx

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by angiey on Mon Aug 17 00:03:15 MST 2015
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 a from frequency 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.

Outcomes