Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Pulse Width Modulator

2005-01-26 by teunvandeberg

Hello,

I'm trying to use PWM 5 on a LPC2292. How can I select which timer is 
used for the PWM. Can someone give some example code? I can't get any 
output on the pin. It is configured as PWM5.

We use FreeRTOS so the following code is used to setup Timer 1:

/*-----------------------------------------------------------*/
/*
 * Setup the timer 0 to generate the tick interrupts at the required 
frequency.
 */
static void prvSetupTimerInterrupt( void )
{
unsigned portLONG ulCompareMatch;

	/* A 1ms tick does not require the use of the timer 
prescale.  This is
	defaulted to zero but can be used if necessary. */
	T0_PC = portPRESCALE_VALUE;

	/* Calculate the match value required for our wanted tick 
rate. */
	ulCompareMatch = portCPU_CLOCK_HZ / portTICK_RATE_HZ;

	/* Protect against divide by zero.  Using an if() statement 
still results
	in a warning - hence the #if. */
	#if portPRESCALE_VALUE != 0
	{
		ulCompareMatch /= portPRESCALE_VALUE;
	}
	#endif
	T0_MR0 = ulCompareMatch;

	/* Generate tick with timer 0 compare match. */
	T0_MCR = portRESET_COUNT_ON_MATCH | portINTERRUPT_ON_MATCH;

	/* Setup the VIC for the timer. */
	VICIntSelect &= ~( portTIMER_VIC_CHANNEL_BIT );
	VICIntEnable |= portTIMER_VIC_CHANNEL_BIT;
	
	/* The ISR installed depends on whether the preemptive or 
cooperative
	scheduler is being used. */
	#if portUSE_PREEMPTION == 1
	{
		extern void ( vPreemptiveTick )( void );
		VICVectAddr0 = ( portLONG ) vPreemptiveTick;
	}
	#else
	{
		extern void ( vNonPreemptiveTick )( void );
		VICVectAddr0 = ( portLONG ) vNonPreemptiveTick;
	}
	#endif

	VICVectCntl0 = portTIMER_VIC_CHANNEL | portTIMER_VIC_ENABLE;

	/* Start the timer - interrupts are disabled when this 
function is called
	so it is okay to do this here. */
	T0_TCR = portENABLE_TIMER;
}
/*-----------------------------------------------------------*/

Could this be causing the problem?

Kind Regards,
Teun

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.