Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are 6 PWM outputs on mbed board. An engineer is asked by his manager to us

ID: 2266588 • Letter: T

Question

There are 6 PWM outputs on mbed board. An engineer is asked by his manager to use mbed to control a motor to do the following sequence: the motor should initially be switched full on for 3 seconds, then it needs to be powered by PWM signal with period of 50ms and duty cycle of 60% for duration of 2 minute, after which the motor needs to be turned off for 5 seconds, and then be controlled by a PWM signal with period of 25ms and pulse width of 15ms for duration of 3 minutes. The motor is then off for 5 seconds. This sequence continues indefinitely. Please help this engineering first make a decision on whether to use PWM outputs of the mbed or the Digital I/O for this assignment, and then complete the coding for him based on your choice.

Explanation / Answer

A DC motor is conected to PWM6 = pin21

Code:

#include "mbed.h"

PwmOut MOT(p21); //PWM6 as ouput to motor

int main() {

while(1)

{ // specify period first

MOT.period_ms(50); // 50 milli second period

MOT.write(1.00); // 100% duty cycle(Full on)

wait(3); //let it run for 3seconds

MOT.write(0.60); //set duty ratio to 60%(period is already set)

wait(120); //wait for 2 minutes

MOT.write(0.00); //make duty ratio 0%(Full off)

wait(5); //wait for 5 seconds

MOT.period_ms(25); //set the duty ratio to 25ms

MOT.pulsewidth_ms(15); //since 15 is already 60% of 25 there is no need to write this line

wait(180); //let it run for 3 minutes

MOT.pulsewidth_ms(0); //make duty ratio 0%(Full off)

wait(5); //wait for 5 seconds and Repeat

}

}