05-02 PWMPulse
From Manuals
(Difference between revisions)
(Created page with 'This example uses an analog input to control the duty cycle of a PWM in a fixed period. /*Program Example 5.2: Uses analog input to control PWM duty cycle, fixed period …') |
|||
| Line 1: | Line 1: | ||
This example uses an analog input to control the duty cycle of a PWM in a fixed period. | This example uses an analog input to control the duty cycle of a PWM in a fixed period. | ||
| + | |||
| + | 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 05-01''' | ||
| + | |'''Signal''' | ||
| + | |'''LPC4330 PIN NAME''' | ||
| + | |'''BAM210E''' | ||
| + | |'''BAM210''' | ||
| + | |'''BAM200E''' | ||
| + | |'''BAM200''' | ||
| + | |'''Used for''' | ||
| + | |- | ||
| + | |A0 | ||
| + | |P7_4 | ||
| + | |J8-1 | ||
| + | |J8-1 | ||
| + | |S4-3 | ||
| + | |S4-3 | ||
| + | |Potentiometer | ||
| + | |- | ||
| + | |PWM1 | ||
| + | |P1_7 | ||
| + | |J9-3 | ||
| + | |J9-3 | ||
| + | |S2-3 | ||
| + | |S2-3 | ||
| + | |Oscilloscope | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | The following schematic can be used to build the circuit with a BAM210E or BAM210. | ||
| + | [[Image:BAM210_05_02_SCH.png|center|alt=BAM210|frame|<div align="center">'''Schematic for example 05-02''']] | ||
| + | |||
| + | <div style="text-align: left;"> | ||
/*Program Example 5.2: Uses analog input to control PWM duty cycle, fixed period | /*Program Example 5.2: Uses analog input to control PWM duty cycle, fixed period | ||
| Line 14: | Line 48: | ||
} | } | ||
} | } | ||
| + | PWM1 was captured on the oscilloscope in the image below. | ||
| + | [[Image:BAM210_05_02.png|center|]] | ||
| + | The following image shows the built circuit on a BAM210E. | ||
[[Image:BAM210_PWMPulse.jpeg|center|]] | [[Image:BAM210_PWMPulse.jpeg|center|]] | ||
| - | |||
| - | |||
| - | |||
Revision as of 19:34, 17 September 2014
This example uses an analog input to control the duty cycle of a PWM in a fixed period.
The signals used for this example are listed below:
| Signal | LPC4330 PIN NAME | BAM210E | BAM210 | BAM200E | BAM200 | Used for |
| A0 | P7_4 | J8-1 | J8-1 | S4-3 | S4-3 | Potentiometer |
| PWM1 | P1_7 | J9-3 | J9-3 | S2-3 | S2-3 | Oscilloscope |
The following schematic can be used to build the circuit with a BAM210E or BAM210.
File:BAM210 05 02 SCH.png
Schematic for example 05-02
/*Program Example 5.2: Uses analog input to control PWM duty cycle, fixed period
*/
#include "mbed.h"
PwmOut pwm(PWM1);
AnalogIn Ain(A0); //defines analog input on A0
int main() {
while(1){
pwm.period(0.010); // set PWM period to 10 ms
pwm=Ain; //Analog in value becomes PWM duty, both are type float
wait(0.1);
}
}
PWM1 was captured on the oscilloscope in the image below.
The following image shows the built circuit on a BAM210E.


