Control an H-Bridge using a PwmOut (enable) and two DigitalOuts (direction select)

Fork of Motor by Simon Ford

Committer:
miczyg
Date:
Tue May 19 16:39:03 2015 +0000
Revision:
17:26edc972222e
Parent:
13:d67ecfc6cd7f
Wzmocnienie, period itd ok, wersja P dzia?aj?ca.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:a470311addc4 1 #ifndef MBED_MOTOR_H
simon 0:a470311addc4 2 #define MBED_MOTOR_H
simon 0:a470311addc4 3
simon 0:a470311addc4 4 #include "mbed.h"
miczyg 3:9572ea41a1b4 5 #include "PID.h"
miczyg 4:5370aae8ee3b 6 #include "QEI.h"
simon 0:a470311addc4 7
miczyg 13:d67ecfc6cd7f 8 /*nastawy regulatora PID
miczyg 4:5370aae8ee3b 9 const float K = 1;
miczyg 4:5370aae8ee3b 10 const float Ti = 0;
miczyg 4:5370aae8ee3b 11 const float Td = 0;
miczyg 4:5370aae8ee3b 12 const float itv = 0.001;
miczyg 5:71d7e9c17980 13 #define AUTO 1
miczyg 13:d67ecfc6cd7f 14 */
miczyg 4:5370aae8ee3b 15 /*QEI pins*/
michal0074 6:a321d28cce9a 16 /*
miczyg 4:5370aae8ee3b 17 #define CH_A PTA2
miczyg 4:5370aae8ee3b 18 #define CH_B PTA3
miczyg 4:5370aae8ee3b 19 const int pPerRev = 10;
miczyg 5:71d7e9c17980 20 const int max_pulse_rate = 300; //do policzenia!!!!!!!!!!!!!!!!!!!
michal0074 6:a321d28cce9a 21 */
miczyg 4:5370aae8ee3b 22 /** Interface to control a standard DC motor
miczyg 4:5370aae8ee3b 23 *
miczyg 4:5370aae8ee3b 24 * with an H-bridge using a PwmOut and 2 DigitalOuts
miczyg 4:5370aae8ee3b 25 */
simon 0:a470311addc4 26 class Motor {
simon 0:a470311addc4 27 public:
simon 1:e341f695742a 28
miczyg 4:5370aae8ee3b 29 /** Create a motor control interface
miczyg 4:5370aae8ee3b 30 *
miczyg 4:5370aae8ee3b 31 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
miczyg 4:5370aae8ee3b 32 * @param fwd A DigitalOut, set high when the motor should go forward
miczyg 4:5370aae8ee3b 33 * @param rev A DigitalOut, set high when the motor should go backwards
miczyg 4:5370aae8ee3b 34 */
miczyg 7:d25073d59616 35 Motor(PinName pwm, PinName fwd, PinName rev, PinName stby);
miczyg 4:5370aae8ee3b 36
simon 1:e341f695742a 37 /** Set the speed of the motor
miczyg 4:5370aae8ee3b 38 *
miczyg 4:5370aae8ee3b 39 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
miczyg 4:5370aae8ee3b 40 */
simon 1:e341f695742a 41 void speed(float speed);
miczyg 7:d25073d59616 42
miczyg 7:d25073d59616 43 /**Change the stand by status of H-bridge
miczyg 7:d25073d59616 44 *
miczyg 7:d25073d59616 45 * @param status 0 - bridge disabled, 1 - bridge enabled
miczyg 7:d25073d59616 46 */
miczyg 7:d25073d59616 47 void setStandby(bool status)
miczyg 7:d25073d59616 48 {
miczyg 7:d25073d59616 49 _stdby = status;
miczyg 7:d25073d59616 50 }
simon 0:a470311addc4 51
simon 0:a470311addc4 52 protected:
simon 0:a470311addc4 53 PwmOut _pwm;
simon 0:a470311addc4 54 DigitalOut _fwd;
simon 0:a470311addc4 55 DigitalOut _rev;
miczyg 7:d25073d59616 56 DigitalOut _stdby;
miczyg 4:5370aae8ee3b 57 private:
miczyg 8:d192b38e0d5c 58 //PID speedControl;
michal0074 6:a321d28cce9a 59 //QEI encoder;
miczyg 4:5370aae8ee3b 60 float set_speed;
miczyg 4:5370aae8ee3b 61 int pulses;
miczyg 4:5370aae8ee3b 62 float curr_speed;
miczyg 4:5370aae8ee3b 63 float prev_pulses;
michal0074 6:a321d28cce9a 64
simon 0:a470311addc4 65 };
simon 0:a470311addc4 66
simon 0:a470311addc4 67 #endif