LPC43xx: Generating PWM with timer 0/1/2/3

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

LPC43xx: Generating PWM with timer 0/1/2/3

Jump to solution
2,964 Views
andreasklockner
Contributor II

Hi there,

due to the fact, that on many microcontrollers one can use timers to generate PWM signals, I tried to generate a PWM signal (Duty 0% - 100%) with the Timer module of the LPC4337.

Unfortunately, I ran into problems. At the moment, it seems, that this is not possible without using interrupts (and thus jitter).

 

What I did:

- init timer 3

- set match register to 20% duty

- set pin LOW on match  (or HIGH on match).

 

Result: Pin was always LOW (or HIGH).

 

Reason: it seems, that there is NO possibility to reset the PIN, when timer overflows (or reset by an other match). Thus it's not possible to generate a PWM with a variable duty cycle.

 

Or have I misunderstood the timer module? Is there a way to configure it to output PWM signals (without interrupt activity)

Labels (5)
Tags (4)
1 Solution
1,843 Views
rolfmeeser
NXP Employee
NXP Employee

Your conclusion is correct: The standard timers of the LPC43xx cannot generate a PWM signal by themselves. They require software to initialize the pin at the beginning of each cycle, causing jitter and limiting the achievable minimum and/or maximum duty cycle.

Extended versions of the standard timer IP block provide a basic PWM mode, but they only exist in other LPC device families (e.g. LPC11U3x), not in the LPC18xx/LPC43xx.

For LPC43xx the preferred method of generating PWM signals is the SCT module.

View solution in original post

0 Kudos
4 Replies
1,843 Views
tyler_drazich
Contributor III

I agree with the accepted answer, that the best method is to have no software interrupts. If there is a reason the standard timer must be used, there should be no jitter. Granted the minimum pulse width and maximum frequency would be limited to the rate the interrupts could keep up, but jitter would only occur if the timer counter is reset or if the software directly sets the pin state. If the interrupt handler keeps the timer counter running, a PWM could be generated with no jitter using the following pseudo code.

// 'PulseWidth' is the number of timer ticks the pin stays HIGH
// 'Period' is the number of timer ticks for a PWM cycle (frequency)
void TimerInterrupt(void) 
{      
   if (Pin == High) {           
      SetPinToGoLowOnMatch();           
      MatchReg = MatchReg + PulseWidth;      
   } else {          
       SetPinToGoHighOnMatch();           
      MatchReg = MatchReg + (Period – PulseWidth);      
   }       

   ClearInterrupt(); 
}

-Tyler

1,844 Views
rolfmeeser
NXP Employee
NXP Employee

Your conclusion is correct: The standard timers of the LPC43xx cannot generate a PWM signal by themselves. They require software to initialize the pin at the beginning of each cycle, causing jitter and limiting the achievable minimum and/or maximum duty cycle.

Extended versions of the standard timer IP block provide a basic PWM mode, but they only exist in other LPC device families (e.g. LPC11U3x), not in the LPC18xx/LPC43xx.

For LPC43xx the preferred method of generating PWM signals is the SCT module.

0 Kudos
1,843 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

I was wondering if you can share the codes, then I can run the demo and replicate the issue.

I'm looking forward to your reply.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,843 Views
andreasklockner
Contributor II

Hi Ping, sorry I just read your reply. I could send you my code, but - as I have seen - Rolf Meeser already stated, that it's really not possible to generate PWM signals with the standard timer IP block on LPC43xx.

0 Kudos