04-06 SoftwarePWM
From Manuals
(Difference between revisions)
| (One intermediate revision not shown) | |||
| Line 1: | Line 1: | ||
This example controls the Servo using a software PWM. The servo motor is a HiTEC HS0422. | This example controls the Servo using a software PWM. The servo motor is a HiTEC HS0422. | ||
| + | The signals used for this example are listed below: | ||
| + | {| border="1" cellpadding="5" cellspacing="2" align="center" style="text-align: center;" | ||
| + | |+ align="bottom"|'''Signals Used and Connector Locations for Example 04-06''' | ||
| + | |'''Signal''' | ||
| + | |'''LPC4330 PIN NAME''' | ||
| + | |'''BAM210E''' | ||
| + | |'''BAM210''' | ||
| + | |'''BAM200E''' | ||
| + | |'''BAM200''' | ||
| + | |'''Used for''' | ||
| + | |- | ||
| + | |p21 | ||
| + | |P6_5 | ||
| + | |J9-1 | ||
| + | |J9-1 | ||
| + | |S2-5 | ||
| + | |S2-5 | ||
| + | |Servo Control Signal | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | The following schematic can be used to build the circuit with a BAM210E or BAM210. | ||
| + | [[Image:BAM210_04_06_SCH.png|center|alt=BAM210|frame|<div align="center">'''Schematic for example 04-06''']] | ||
| + | |||
| + | <div style="text-align: left;"> | ||
/*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison. | /*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison. | ||
*/ | */ | ||
| Line 29: | Line 54: | ||
} | } | ||
| + | The following image shows the built circuit on a BAM210E. | ||
[[Image:BAM210_SoftwarePWM.jpeg|center|]] | [[Image:BAM210_SoftwarePWM.jpeg|center|]] | ||
| - | |||
| - | |||
| - | |||
| - | |||
Current revision as of 19:10, 17 September 2014
This example controls the Servo using a software PWM. The servo motor is a HiTEC HS0422.
The signals used for this example are listed below:
| Signal | LPC4330 PIN NAME | BAM210E | BAM210 | BAM200E | BAM200 | Used for |
| p21 | P6_5 | J9-1 | J9-1 | S2-5 | S2-5 | Servo Control Signal |
The following schematic can be used to build the circuit with a BAM210E or BAM210.
/*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison.
*/
#include "mbed.h"
DigitalOut motor(p21);
int i;
int main()
{
while(1) {
motor = 0; //motor switched off for 5 secs
wait (5);
for (i=0; i<5000; i=i+1) { //5000 PWM cycles, low duty cycle
motor = 1;
wait_us(400); //output high for 400us
motor = 0;
wait_us(600); //output low for 600us
}
for (i=0; i<5000; i=i+1) { //5000 PWM cycles, high duty cycle
motor = 1;
wait_us(800); //output high for 800us
motor = 0;
wait_us(200); //output low for 200us
}
motor = 1; //motor switched fully on for 5 secs
wait (5);
}
}
The following image shows the built circuit on a BAM210E.


