MC33926 is a H-Bridge from freescale. This driver allow to use it to drive a DC-Motor using 3 different driving methods: - Lock Antiphase - Sign-Magnitude braking - Sign-Magnitude coasting I used this board https://www.sparkfun.com/products/11080 for my tests and find a lot of informations here: http://modularcircuits.tantosonline.com/blog/articles/h-bridge-secrets/h-bridge-control/

Committer:
garfunkheul
Date:
Tue Oct 08 21:09:37 2013 +0000
Revision:
0:217bc3688cff
This is the first commit for MC33926 driver. It brings 3 driving methods: lock-antiphase, sign-magnitude braking and sign-magnitude coasting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garfunkheul 0:217bc3688cff 1 #ifndef __MC33926_H__
garfunkheul 0:217bc3688cff 2 #define __MC33926_H__
garfunkheul 0:217bc3688cff 3
garfunkheul 0:217bc3688cff 4 #include "mbed.h"
garfunkheul 0:217bc3688cff 5
garfunkheul 0:217bc3688cff 6 #define MAX_SPEED 5
garfunkheul 0:217bc3688cff 7
garfunkheul 0:217bc3688cff 8 enum mc33926_mode {
garfunkheul 0:217bc3688cff 9 LOCK_ANTIPHASE,
garfunkheul 0:217bc3688cff 10 SIGN_MAGNITUDE_BRAKING,
garfunkheul 0:217bc3688cff 11 SIGN_MAGNITUDE_COASTING,
garfunkheul 0:217bc3688cff 12 };
garfunkheul 0:217bc3688cff 13
garfunkheul 0:217bc3688cff 14
garfunkheul 0:217bc3688cff 15 /** driver for the MC33926 H-Bridge
garfunkheul 0:217bc3688cff 16 *
garfunkheul 0:217bc3688cff 17 * This driver allow to drive the MC33926 with 3 differents technics:
garfunkheul 0:217bc3688cff 18 * - Lock antiphase: alternate 1 direction with another
garfunkheul 0:217bc3688cff 19 * - Sign-manigtude braking: alternate 1 direction with braking
garfunkheul 0:217bc3688cff 20 * - Sign-magnitude coasting: alternate 1 direction with freewheeling
garfunkheul 0:217bc3688cff 21
garfunkheul 0:217bc3688cff 22 * Speed can be set from -MAX_SPEED to +MAX_SPEED
garfunkheul 0:217bc3688cff 23 */
garfunkheul 0:217bc3688cff 24 class mc33926
garfunkheul 0:217bc3688cff 25 {
garfunkheul 0:217bc3688cff 26 public:
garfunkheul 0:217bc3688cff 27
garfunkheul 0:217bc3688cff 28 /** Create a MC33926 instance
garfunkheul 0:217bc3688cff 29 * @param inv pin connected to inv
garfunkheul 0:217bc3688cff 30 * @param in1 pin connected to in1
garfunkheul 0:217bc3688cff 31 * @param in2 pin connected to in2
garfunkheul 0:217bc3688cff 32 * @param d1 pin connected to d1
garfunkheul 0:217bc3688cff 33 * @param d2 pin connected to d2
garfunkheul 0:217bc3688cff 34 * @param en pin connected to enable (can be unset)
garfunkheul 0:217bc3688cff 35 * @param sf pin connected to sf (can be unset)
garfunkheul 0:217bc3688cff 36 */
garfunkheul 0:217bc3688cff 37 mc33926(PinName inv, PinName in1, PinName in2, PinName d1, PinName d2, PinName en = NC, PinName sf = NC);
garfunkheul 0:217bc3688cff 38
garfunkheul 0:217bc3688cff 39 /** Set driving mode
garfunkheul 0:217bc3688cff 40 * @param _mode mode to set (LOCK_ANTIPHASE, SIGN_MAGNITUDE_BRAKING or SIGN_MAGNITUDE_COASTING)
garfunkheul 0:217bc3688cff 41 */
garfunkheul 0:217bc3688cff 42 void set_mode(int _mode);
garfunkheul 0:217bc3688cff 43
garfunkheul 0:217bc3688cff 44 /** Set speed
garfunkheul 0:217bc3688cff 45 * @param _speed (from -MAX_SPPED to +MAX_SPEED)
garfunkheul 0:217bc3688cff 46 */
garfunkheul 0:217bc3688cff 47 float set_speed(int _speed);
garfunkheul 0:217bc3688cff 48
garfunkheul 0:217bc3688cff 49 /** Set PWM period
garfunkheul 0:217bc3688cff 50 * @param _period pwm period in us. Warning: a low period implies SF set, see MC339276 datasheet
garfunkheul 0:217bc3688cff 51 */
garfunkheul 0:217bc3688cff 52 void set_period(int _period);
garfunkheul 0:217bc3688cff 53
garfunkheul 0:217bc3688cff 54 /** Return driving mode
garfunkheul 0:217bc3688cff 55 */
garfunkheul 0:217bc3688cff 56 int get_mode();
garfunkheul 0:217bc3688cff 57
garfunkheul 0:217bc3688cff 58 /** Return speed
garfunkheul 0:217bc3688cff 59 */
garfunkheul 0:217bc3688cff 60 int get_speed();
garfunkheul 0:217bc3688cff 61
garfunkheul 0:217bc3688cff 62 /** Return PWM period in us
garfunkheul 0:217bc3688cff 63 */
garfunkheul 0:217bc3688cff 64 int get_period();
garfunkheul 0:217bc3688cff 65
garfunkheul 0:217bc3688cff 66 /** Enable H-Bridge. Work only if enable pin is set
garfunkheul 0:217bc3688cff 67 */
garfunkheul 0:217bc3688cff 68 void enable();
garfunkheul 0:217bc3688cff 69
garfunkheul 0:217bc3688cff 70 /* Disable H-Bridge. Work only if enable pin is set
garfunkheul 0:217bc3688cff 71 */
garfunkheul 0:217bc3688cff 72 void disable();
garfunkheul 0:217bc3688cff 73
garfunkheul 0:217bc3688cff 74 private:
garfunkheul 0:217bc3688cff 75 PinName pin_inv;
garfunkheul 0:217bc3688cff 76 PinName pin_in1;
garfunkheul 0:217bc3688cff 77 PinName pin_in2;
garfunkheul 0:217bc3688cff 78 PinName pin_d1;
garfunkheul 0:217bc3688cff 79 PinName pin_d2;
garfunkheul 0:217bc3688cff 80 PinName pin_en;
garfunkheul 0:217bc3688cff 81 PinName pin_sf;
garfunkheul 0:217bc3688cff 82
garfunkheul 0:217bc3688cff 83 PwmOut *pwm;
garfunkheul 0:217bc3688cff 84
garfunkheul 0:217bc3688cff 85 int mode;
garfunkheul 0:217bc3688cff 86 int speed;
garfunkheul 0:217bc3688cff 87 int period;
garfunkheul 0:217bc3688cff 88
garfunkheul 0:217bc3688cff 89 void setup();
garfunkheul 0:217bc3688cff 90 void setup_lock_antiphase();
garfunkheul 0:217bc3688cff 91 void setup_sign_magnitude_braking();
garfunkheul 0:217bc3688cff 92 void setup_sign_magnitude_coasting();
garfunkheul 0:217bc3688cff 93
garfunkheul 0:217bc3688cff 94 float speed_lock_antiphase();
garfunkheul 0:217bc3688cff 95 float speed_sign_magnitude();
garfunkheul 0:217bc3688cff 96
garfunkheul 0:217bc3688cff 97 void period_lock_antiphase();
garfunkheul 0:217bc3688cff 98 void period_sign_magnitude();
garfunkheul 0:217bc3688cff 99 };
garfunkheul 0:217bc3688cff 100
garfunkheul 0:217bc3688cff 101 #endif