Using OM13077 eval board, I want to output a square wave using Timer0 match register 0, toggle pin on match.
Anything missing here?
int loop = 1; /* Prevents unreachable statement warning */
uint32_t timerBaseClock;
SystemCoreClockUpdate();
Board_Init();
/* Initialize Timer 0 */
Chip_TIMER_Init(LPC_TIMER0);
/* Setup prescale value on Timer 0 to PCLK */
Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);
/* Reset timer */
Chip_TIMER_Reset(LPC_TIMER0);
/* Get rate of timer base clock */
timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();
/* Setup Timer 0 for a match every 1s */
Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));
/* Setup timer to restart when match occurs */
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 0);
/* Map P1.16 as MAT0 pin */
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
/* Sets external match control (MATn.matchnum) pin control */
Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);
/* Start timer */
Chip_TIMER_Enable(LPC_TIMER0);
while (loop) {
}
return 0;
Solved! Go to Solution.
Hi Chris ONeill.
The PIO1_16 is assigned to the CT32B0_MAT0 when set up the IOCON_FUN2 option (Fig 1).
Fig 1
Please use the amended code below which can work well (Fig 2)
Fig 2
#define TICKRATE_HZ1 (4)/* 4 ticks per second */
/* main application function (C entry point) */
int main(void)
{
int loop = 1; /* Prevents unreachable statement warning */
uint32_t timerBaseClock;
SystemCoreClockUpdate();
Board_Init();
Board_LED_Set(0, false);
Board_LED_Set(1, false);
/* Initialize Timer 0 and Timer 1 */
Chip_TIMER_Init(LPC_TIMER0);
/* Setup prescale value on Timer 0 to PCLK */
Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);
/* Reset timers */
Chip_TIMER_Reset(LPC_TIMER0);
Chip_TIMER_Reset(LPC_TIMER1);
/* Get rate of timer base clock */
timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();
/* Setup Timer 0 for a match every 1s */
Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));
Chip_TIMER_SetMatch(LPC_TIMER0, 1, (2*(timerBaseClock / TICKRATE_HZ1)));
/* Setup both timers to restart when match occurs */
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
/* Sets external match control (MATn.matchnum) pin control */
Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);
Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 1);
LPC_TIMER0->PWMC |=(1<<0);
/* Map P1.16 as MAT0 pin */
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC2 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
/* Start both timers */
Chip_TIMER_Enable(LPC_TIMER0);
/* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */
while (loop) {
//__WFI();
}
return 0;
}
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Chris ONeill.
Please try the amended code.
int loop = 1; /* Prevents unreachable statement warning */
uint32_t timerBaseClock;
SystemCoreClockUpdate();
Board_Init();
/* Initialize Timer 0 */
Chip_TIMER_Init(LPC_TIMER0);
/* Setup prescale value on Timer 0 to PCLK */
Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);
/* Reset timer */
Chip_TIMER_Reset(LPC_TIMER0);
/* Get rate of timer base clock */
timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();
/* Setup Timer 0 for a match every 1s */
Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));
Chip_TIMER_SetMatch(LPC_TIMER0, 1, 2*(timerBaseClock / TICKRATE_HZ1));
/* Setup timer to restart when match occurs */
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
/* Map P1.16 as MAT0 pin */
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
/* Sets external match control (MATn.matchnum) pin control */
Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);
Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 1);
/* Start timer */
Chip_TIMER_Enable(LPC_TIMER0);
while (loop) {
}
return 0;
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Still don't see any output on OM13077 J2 pin 3, which should be P1.16, CT32B0_MAT0.
Added:
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
but no output on J2 pin 1 either, which should be P0.6, CT32B0_MAT1
Hi Chris ONeill.
The PIO1_16 is assigned to the CT32B0_MAT0 when set up the IOCON_FUN2 option (Fig 1).
Fig 1
Please use the amended code below which can work well (Fig 2)
Fig 2
#define TICKRATE_HZ1 (4)/* 4 ticks per second */
/* main application function (C entry point) */
int main(void)
{
int loop = 1; /* Prevents unreachable statement warning */
uint32_t timerBaseClock;
SystemCoreClockUpdate();
Board_Init();
Board_LED_Set(0, false);
Board_LED_Set(1, false);
/* Initialize Timer 0 and Timer 1 */
Chip_TIMER_Init(LPC_TIMER0);
/* Setup prescale value on Timer 0 to PCLK */
Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);
/* Reset timers */
Chip_TIMER_Reset(LPC_TIMER0);
Chip_TIMER_Reset(LPC_TIMER1);
/* Get rate of timer base clock */
timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();
/* Setup Timer 0 for a match every 1s */
Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));
Chip_TIMER_SetMatch(LPC_TIMER0, 1, (2*(timerBaseClock / TICKRATE_HZ1)));
/* Setup both timers to restart when match occurs */
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
/* Sets external match control (MATn.matchnum) pin control */
Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);
Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 1);
LPC_TIMER0->PWMC |=(1<<0);
/* Map P1.16 as MAT0 pin */
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC2 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
/* Start both timers */
Chip_TIMER_Enable(LPC_TIMER0);
/* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */
while (loop) {
//__WFI();
}
return 0;
}
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Important points were:
use both MAT0 and MAT1
reset timer on MAT1
set PWMC ( = 1 for Timer0)
Hi Chris ONeill.
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
I'd like to run the above code by myself, and to replicate the issue.
I'll reply later after I work it out.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------