LPC804 - PWM pulse generation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC804 - PWM pulse generation

Jump to solution
1,008 Views
Dhaya
Contributor III

HI, 

  We need to generate the PWM with clock period of 500ms with duty cycle of 50%. Here we configured the register as per the datasheet, which are as follows

 

SYSCON->SYSAHBCLKCTRL0 |=  1 << 25 ;
SYSCON->PRESETCTRL0 |= 1 << 25; SYSCON->SYSAHBCLKCTRL0 |= 1<<7; SWM0->PINASSIGN.PINASSIGN4 = 0X00000000; SWM0->PINASSIGN.PINASSIGN4 = (0X18) << 24 ;//0X18;// P0_24 PIN SELECTED SYSCON->SYSAHBCLKCTRL0 &= ~(1<<7); //DISABLE clock for switch matrix. CTIMER->TCR |= 1 << 1; CTIMER->PR = 0X00; CTIMER->MCR |= 1 << 9 | 1 << 10 | 1 << 27 | 1 << 0 | 1 << 1; CTIMER->MR[3] =10000; CTIMER->MSR[3]=10000; CTIMER->MR[0] =5000; CTIMER->MSR[0]=5000; CTIMER->PWMC |= 1<<3; CTIMER->TCR |= 1<<0 ; while(1);

This is the code which we developed. But there is no difference in pin status. We use
P0_24 for this PWM generation.
We not get the point of exact usage of EMR, Match shadow register.
Kindly navigate us to move further

0 Kudos
Reply
1 Solution
983 Views
giraffe508
Contributor IV

Hi @Dhaya 

Based on the code you provided, it seems you are trying to generate a PWM signal with a 50% duty cycle and a 500ms period using the LPC804's CTIMER. I noticed a few issues in the code that might be causing the problem:

  1. First, make sure to enable the clock for the CTIMER block by setting the corresponding bit in the SYSAHBCLKCTRL0 register:
 SYSCON->SYSAHBCLKCTRL0 |= (1 << 25); 
  1. Next, you need to configure the CTIMER's PWM channel 3 to generate the PWM signal. You can do this by setting the appropriate bits in the PWM Control Register (PWMC):
 CTIMER->PWMC |= (1 << 3); 
  1. Lastly, you should configure the Match Control Register (MCR) to reset the timer on match with MR3 and set the PWM output on match with MR0:
 CTIMER->MCR |= (1 << 10) | (1 << 0); 

With these changes, your code should look like this:

 SYSCON->SYSAHBCLKCTRL0 |= (1 << 25); SYSCON->PRESETCTRL0 |= (1 << 25);
SYSCON->SYSAHBCLKCTRL0 |= (1 << 7); SWM0->PINASSIGN.PINASSIGN4 = 0X00000000; SWM0->PINASSIGN.PINASSIGN4 = (0X18) << 24; SYSCON->SYSAHBCLKCTRL0 &= ~(1 << 7);
CTIMER->TCR |= (1 << 1); CTIMER->PR = 0X00; CTIMER->MCR |= (1 << 10) | (1 << 0);
CTIMER->MR[3] = 10000; CTIMER->MR[0] = 5000;
CTIMER->PWMC |= (1 << 3); CTIMER->TCR |= (1 << 0);
while (1);

However, this code will generate a PWM signal with a 20ms

Kind Regards,
 

View solution in original post

2 Replies
959 Views
RaRo
NXP TechSupport
NXP TechSupport

Hello @Dhaya,

Could you please take a look at LPC804 SDK's CTIMER PWM examples? It might be useful to develop your code.

We not get the point of exact usage of EMR, Match shadow register.

LPC804 User Manual. Chapter 16: LPC804 Standard counter/timer (CTIMER) explains both registers:

RaulRomero_0-1687536575265.png

[LPC804 User Manual. Chapter 16. LPC804 Standard counter/timer (CTIMER). Section 16.5. Pin description]

As User Manual mentions the EMR controls whether the P0_24 is going to toggle, go low, high or do nothing when a match occurs between the TC and MR[3:0]. Section 16.6.10 of the User Manual explains how to configure the EMR.

About the MSR, User Manual's Section 16.6.13. Match Shadow Registers mentions: "The Match Shadow registers contain the values that the corresponding Match Registers are (optionally) reloaded with at the start of each new counter cycle."

The MSR could be used when you have to monitor the value of the CTIMER, for example, if you want to use it to generate a periodic event. The value of the timer could be read at any time by reading the value of the Match Shadow Register. In the example recommended it is not used to generate a PWM signal.

Best regards, Raul.

984 Views
giraffe508
Contributor IV

Hi @Dhaya 

Based on the code you provided, it seems you are trying to generate a PWM signal with a 50% duty cycle and a 500ms period using the LPC804's CTIMER. I noticed a few issues in the code that might be causing the problem:

  1. First, make sure to enable the clock for the CTIMER block by setting the corresponding bit in the SYSAHBCLKCTRL0 register:
 SYSCON->SYSAHBCLKCTRL0 |= (1 << 25); 
  1. Next, you need to configure the CTIMER's PWM channel 3 to generate the PWM signal. You can do this by setting the appropriate bits in the PWM Control Register (PWMC):
 CTIMER->PWMC |= (1 << 3); 
  1. Lastly, you should configure the Match Control Register (MCR) to reset the timer on match with MR3 and set the PWM output on match with MR0:
 CTIMER->MCR |= (1 << 10) | (1 << 0); 

With these changes, your code should look like this:

 SYSCON->SYSAHBCLKCTRL0 |= (1 << 25); SYSCON->PRESETCTRL0 |= (1 << 25);
SYSCON->SYSAHBCLKCTRL0 |= (1 << 7); SWM0->PINASSIGN.PINASSIGN4 = 0X00000000; SWM0->PINASSIGN.PINASSIGN4 = (0X18) << 24; SYSCON->SYSAHBCLKCTRL0 &= ~(1 << 7);
CTIMER->TCR |= (1 << 1); CTIMER->PR = 0X00; CTIMER->MCR |= (1 << 10) | (1 << 0);
CTIMER->MR[3] = 10000; CTIMER->MR[0] = 5000;
CTIMER->PWMC |= (1 << 3); CTIMER->TCR |= (1 << 0);
while (1);

However, this code will generate a PWM signal with a 20ms

Kind Regards,