Ch3_8. DC모터 구동하기

학습 내용

DC Motor의 회전속도를 조절하고 멈추는 제어를 학습하게됩니다.

배선도 & 회로도

500

배선 사진

/media/uploads/jnesystech/imagescaj4ee77.jpg

Flow Chart

/media/uploads/jnesystech/ch3_8.png

코딩

// test code, this demonstrates working motor drivers. 
// full reverse to full stop, dynamicaly brake and switch off.
#include motordriver.h
Motor A(p22, p6, p5, 1); // pwm, fwd, rev, can brake 
Motor B(p21, p7, p8, 1); // pwm, fwd, rev, can brake
int main() {
    for (float s= -1.0; s < 1.0 ; s += 0.01) {
        A.speed(s); 
        B.speed(s); 
        wait(0.02);
    }
    A.stop();
    B.stop();
    wait(1);
    A.coast();
    B.coast();
}

라이브러리

Import library

Public Member Functions

Motor (PinName pwm, PinName fwd, PinName rev, int brakeable)
Create a motor control interface.
float speed (float speed)
Set the speed of the motor.
void coast (void)
Set the the motor to coast.
float stop (float duty)
Set the motor to dynamicaly brake.
float state (void)
return the current state of the motor

PWMOut API

DigitalIn API

학습 참고

An interface for driving a standard DC motor with PWM and an H-Bridge data sheet for L298


Please log in to post comments.