SimpleFOClibrary  2.1
BLDCDriver6PWM.cpp
Go to the documentation of this file.
1 #include "BLDCDriver6PWM.h"
2 
3 BLDCDriver6PWM::BLDCDriver6PWM(int phA_h,int phA_l,int phB_h,int phB_l,int phC_h,int phC_l, int en){
4  // Pin initialization
5  pwmA_h = phA_h;
6  pwmB_h = phB_h;
7  pwmC_h = phC_h;
8  pwmA_l = phA_l;
9  pwmB_l = phB_l;
10  pwmC_l = phC_l;
11 
12  // enable_pin pin
13  enable_pin = en;
14 
15  // default power-supply value
18 
19  // dead zone initial - 2%
20  dead_zone = 0.02;
21 
22 }
23 
24 // enable motor driver
26  // enable_pin the driver - if enable_pin pin available
27  if ( _isset(enable_pin) ) digitalWrite(enable_pin, HIGH);
28  // set zero to PWM
29  setPwm(0, 0, 0);
30 }
31 
32 // disable motor driver
34 {
35  // set zero to PWM
36  setPwm(0, 0, 0);
37  // disable the driver - if enable_pin pin available
38  if ( _isset(enable_pin) ) digitalWrite(enable_pin, LOW);
39 
40 }
41 
42 // init hardware pins
44  // a bit of separation
45  _delay(1000);
46 
47  // PWM pins
48  pinMode(pwmA_h, OUTPUT);
49  pinMode(pwmB_h, OUTPUT);
50  pinMode(pwmC_h, OUTPUT);
51  pinMode(pwmA_l, OUTPUT);
52  pinMode(pwmB_l, OUTPUT);
53  pinMode(pwmC_l, OUTPUT);
54  if(_isset(enable_pin)) pinMode(enable_pin, OUTPUT);
55 
56 
57  // sanity check for the voltage limit configuration
59 
60  // configure 6pwm
61  // hardware specific function - depending on driver and mcu
63 }
64 
65 // Set voltage to the pwm pin
66 void BLDCDriver6PWM::setPwm(float Ua, float Ub, float Uc) {
67  // limit the voltage in driver
68  Ua = _constrain(Ua, 0, voltage_limit);
69  Ub = _constrain(Ub, 0, voltage_limit);
70  Uc = _constrain(Uc, 0, voltage_limit);
71  // calculate duty cycle
72  // limited in [0,1]
73  dc_a = _constrain(Ua / voltage_power_supply, 0.0 , 1.0 );
74  dc_b = _constrain(Ub / voltage_power_supply, 0.0 , 1.0 );
75  dc_c = _constrain(Uc / voltage_power_supply, 0.0 , 1.0 );
76  // hardware specific writing
77  // hardware specific function - depending on driver and mcu
79 }
80 
81 
82 // Set voltage to the pwm pin
83 void BLDCDriver6PWM::setPhaseState(int sa, int sb, int sc) {
84  // TODO implement disabling
85 }
NOT_SET
#define NOT_SET
Definition: foc_utils.h:27
BLDCDriver6PWM::pwmC_l
int pwmC_l
phase C pwm pin number
Definition: BLDCDriver6PWM.h:38
BLDCDriver6PWM::pwmA_l
int pwmA_l
phase A pwm pin number
Definition: BLDCDriver6PWM.h:36
_constrain
#define _constrain(amt, low, high)
Definition: foc_utils.h:9
_isset
#define _isset(a)
Definition: foc_utils.h:11
BLDCDriver::voltage_limit
float voltage_limit
limiting voltage set to the motor
Definition: BLDCDriver.h:18
_delay
void _delay(unsigned long ms)
Definition: time_utils.cpp:5
BLDCDriver6PWM::enable_pin
int enable_pin
enable pin number
Definition: BLDCDriver6PWM.h:39
BLDCDriver::dc_c
float dc_c
currently set duty cycle on phaseC
Definition: BLDCDriver.h:23
BLDCDriver::voltage_power_supply
float voltage_power_supply
power supply voltage
Definition: BLDCDriver.h:17
BLDCDriver6PWM::dead_zone
float dead_zone
a percentage of dead-time(zone) (both high and low side in low) for each pwm cycle [0,...
Definition: BLDCDriver6PWM.h:41
BLDCDriver6PWM::setPhaseState
virtual void setPhaseState(int sa, int sb, int sc) override
Definition: BLDCDriver6PWM.cpp:83
BLDCDriver6PWM::init
int init() override
Definition: BLDCDriver6PWM.cpp:43
DEF_POWER_SUPPLY
#define DEF_POWER_SUPPLY
default power supply voltage
Definition: defaults.h:4
BLDCDriver6PWM::pwmC_h
int pwmC_h
Definition: BLDCDriver6PWM.h:38
_writeDutyCycle6PWM
void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, float dead_zone, int pinA_h, int pinA_l, int pinB_h, int pinB_l, int pinC_h, int pinC_l)
Definition: drivers/hardware_specific/generic_mcu.cpp:86
BLDCDriver6PWM::setPwm
void setPwm(float Ua, float Ub, float Uc) override
Definition: BLDCDriver6PWM.cpp:66
BLDCDriver::pwm_frequency
long pwm_frequency
pwm frequency value in hertz
Definition: BLDCDriver.h:16
BLDCDriver6PWM.h
BLDCDriver6PWM::pwmA_h
int pwmA_h
Definition: BLDCDriver6PWM.h:36
BLDCDriver::dc_a
float dc_a
currently set duty cycle on phaseA
Definition: BLDCDriver.h:21
BLDCDriver6PWM::BLDCDriver6PWM
BLDCDriver6PWM(int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en=NOT_SET)
Definition: BLDCDriver6PWM.cpp:3
BLDCDriver6PWM::enable
void enable() override
Definition: BLDCDriver6PWM.cpp:25
_configure6PWM
int _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, const int pinA_l, const int pinB_h, const int pinB_l, const int pinC_h, const int pinC_l)
Definition: drivers/hardware_specific/generic_mcu.cpp:47
BLDCDriver::dc_b
float dc_b
currently set duty cycle on phaseB
Definition: BLDCDriver.h:22
BLDCDriver6PWM::pwmB_h
int pwmB_h
Definition: BLDCDriver6PWM.h:37
BLDCDriver6PWM::pwmB_l
int pwmB_l
phase B pwm pin number
Definition: BLDCDriver6PWM.h:37
BLDCDriver6PWM::disable
void disable() override
Definition: BLDCDriver6PWM.cpp:33