This tutorial is about configuring the timer interrupt to generate a square wave whose frequency can be selected by GPIO select pins. In this tutorial we are using LPC 1769 as the controller. If you are new to ARM programming you can refer other tutorials.
LPC176x/5x General Purpose Input/Output (GPIO) Programming
LPC176x/5x Timer Programming
LPC176x/5x Analog-to-Digital Converter (ADC)
Sine Wave Generator using DAC with LPC17xx (LPC175x/LPC176x/LPC1769)
We are not going to explain each and every step but to give a brief idea about the basic configuration of registers. The frequency of the square wave can be selected based on three select lines. The first step is to select three GPIO pins as input to accept the select input. Also we need to use one of the pins as the output pin to give pulse waveform.
Next step is the configuration of timer registers. Different steps involved are.
1. Reset the timer by configuring TCR.
2. Set Prescale value in PR
3. Set the count value in Match register(MR)
4. Set appropriate value in MCR.
5. Enable the timer by configuring TCR.
6. Enable timer interrupt if needed.
LPC_TIM0->PR = 0x00; /* set prescaler to zero */
LPC_TIM0->MR0 = 2400; /* set the match register value */
LPC_TIM0->IR = 0xff; /* reset all interrrupts */
LPC_TIM0->MCR = 3; /* configure MCR register based on our requirement */
LPC_TIM0->TCR = 0x01; /* start timer */
Don’t forget to enable the timer interrupt.
LPC_TIM0->IR = 0xff; /* reset all interrrupts */
LPC_GPIO1->FIOPIN=~(LPC_GPIO1->FIOPIN); /*Toggle the output pin */
The frequency can be selected by setting the select line inputs. In this tutorial we are using the pins 4,5 and 6 of port0.