Difference between revisions of "PWM Motor Controller Interface"

From Embedded Systems Learning Academy
Jump to: navigation, search
(PWM for LPC17xx)
(PWM for LPC17xx)
 
(One intermediate revision by the same user not shown)
Line 20: Line 20:
 
== PWM for LPC17xx ==
 
== PWM for LPC17xx ==
 
Steps to use a pin for a PWM :
 
Steps to use a pin for a PWM :
*  Please grab the PWM code from my [https://sourceforge.net/projects/cmpe146freertos/files SourceForge] repository.
 
*: Direct link is here: [https://sourceforge.net/projects/cmpe146freertos/files/lpc_pwm.hpp/download SourceForge Direct Link]
 
 
*  Locate a "PWM" pin on your board.  
 
*  Locate a "PWM" pin on your board.  
*:  On SJ-One Board, you should see PWM1-2, PWM1-4, and PWM1-5.
+
*:  On SJ-One Board, you should see PWM1-2, PWM1-4, and PWM1-5 etc. on PORT2
 
*:  PWM1-2 is '''PWM2''', PWM1-4 is '''PWM4''', and PWM1-5 is '''PWM5'''
 
*:  PWM1-2 is '''PWM2''', PWM1-4 is '''PWM4''', and PWM1-5 is '''PWM5'''
 
*  Use the sample code below.
 
*  Use the sample code below.
Line 29: Line 27:
 
<BR/>
 
<BR/>
 
<syntaxhighlight>
 
<syntaxhighlight>
 +
#include "lpc_pwm.hpp"
 +
 +
 
int main(void)
 
int main(void)
 
{
 
{

Latest revision as of 17:03, 6 November 2013

What is PWM

PWM stands for Pulse Width Modulation. A signal duty cycle is controlled to produce the pulse width.

Application

The application of a PWM is usually in motor controls. If a motor is attached to your PWM signal, you could control the motor's speed using the PWM. Imagine that the PWM you produce lasts for one second (1 Hz). Now, imagine that the PWM is high 10% of the time and LOW 90% of the time. What you will end up doing is turning on the motor only 1/10th of a second, hence controlling the motor speed.

   Example PWM that is ~ 25% HIGH, 75% LOW
       __          __          __
      |  |        |  |        |  |
   ___|  |________|  |________|  |_________
   Example PWM that is ~ 90% HIGH, 10% LOW
       _________   _________   _________
      |         | |         | |
   ___|         |_|         |_|


Now imagine that this 1Hz signal is changed to 1000 Hz. You will no longer hear the motor turn on just for 1/10th of a second. The motor will instead produce a high frequency noise as it is being switched on and off at a very fast rate. This will yield very smooth operation of the motor and hence you can control digitally.

PWM for LPC17xx

Steps to use a pin for a PWM :

  • Locate a "PWM" pin on your board.
    On SJ-One Board, you should see PWM1-2, PWM1-4, and PWM1-5 etc. on PORT2
    PWM1-2 is PWM2, PWM1-4 is PWM4, and PWM1-5 is PWM5
  • Use the sample code below.


#include "lpc_pwm.hpp"


int main(void)
{
    // Let's initialize the PWM signal on PWM1-2
    PWM pwm(PWM::pwm2, 1000);

    // Set PWM to 50%
    pwm.set(50);

    return 0;
}

Motor Wiring Example

TO DO