0:12
today in this video we will see how to
0:14
interface a bldc motor with sdm-32
0:18
this video will only cover the
0:20
interfacing of those motors which are
0:22
connected with the electronic speed
0:27
if you don't have the ESC and directly
0:30
want to control the motor this video is
0:33
not for you the LDC Motors can be
0:36
controlled via the very similar
0:38
processors we used to control the servo
0:41
I am going to use a potentiometer
0:44
connected via the ADC to control the
0:48
we will see that but first let's see the
0:54
I have the 30 ampere ESC which is
0:58
powered by a 12 volts adapter
1:00
the ESC is connected to the 1400 KV
1:06
the two side pins can be connected to
1:08
either side of the motor as it controls
1:11
the direction of rotation
1:12
the center pin from the ESC should be
1:15
connected to the center pin of the motor
1:18
here the yellow wire is the center wire
1:20
and the other two you can connect
1:24
three pin header cable from the ESC is
1:27
responsible for controlling the speed of
1:30
this is just like the three pin wire we
1:32
see in a Servo motor with red being the
1:35
VCC Brown being the ground and yellow is
1:40
the VCC and ground have the potential
1:43
difference of 5 volts so you can use
1:45
this to power the controller
1:47
I have connected them to the 5 volt pin
1:50
on my f103 controller the signal pin is
1:54
connected to the pin pa8 which I will
1:57
set as the pwm output pin later
2:00
I have connected one potentiometer to
2:03
the pin pa0 and this will be used to
2:06
control the speed of the motor
2:08
this is it for the connection let's
2:10
understand how this is going to work
2:13
as I mentioned the bldc can be
2:16
controlled in the same way as the servo
2:19
I have already written a tutorial about
2:21
the servo motor so we will follow the
2:25
as I mentioned here we need a pwn signal
2:28
of time period 20 milliseconds or a 50
2:31
hertz frequency then the speed can be
2:34
controlled by varying the pulse width
2:37
between 1 millisecond to two
2:40
that is all we need to do
2:42
let's see how we can do this with the
2:47
stop the IDE and create a new project
2:54
stm32f103c8 controller
2:57
give some name to the project and click
3:03
first of all I am selecting an external
3:06
Crystal to provide the clock
3:08
the board has 8 megahertz Crystal on it
3:10
and I want to run the system at maximum
3:15
I am also using an ADC for the
3:17
potentiometer and I want to keep the ADC
3:20
clock to minimum this is because I don't
3:23
want the ADC to trigger the interrupts
3:27
I have already explained the ADC
3:29
conversion time in another video you can
3:33
anyway this is the minimum I can set so
3:38
note that the apb2 timer clock is at 9
3:43
I am going to use the timer 1 for the
3:46
pwm which is connected to the apb2 bus
3:50
so the apb2 timer clock is going to be
3:53
the base clock for a timer
3:55
select the debug as serial wire and time
3:58
bases systick let's configure the ADC
4:02
first I am using Channel 0 and remember
4:06
that the potentiometer is connected to
4:08
pin PA 0. I want the conversion to
4:11
happen continuously so enable it
4:14
as I mentioned I don't want the
4:16
interrupt to trigger at a very high rate
4:18
so I am selecting the maximum sampling
4:22
we will let the dma handle these
4:25
make sure to enable the circular mode
4:29
f103 has a 12-bit ADC so half word is
4:34
the dma interrupt is enabled so we are
4:39
now let's configure the timer 1. I am
4:42
using Channel 1 as the pwm generation
4:46
note here the pin pa8 is selected as the
4:49
pwm pin and this is where I have
4:51
connected the signal pin of the ESC
4:54
timer 1 is connected to the apb2 clock
4:57
which is at 9 megahertz right now
5:00
let's understand the calculations before
5:03
we configure the timer
5:05
we know the timer's output frequency can
5:08
be calculated using this formula now if
5:11
I want the output frequency of 50 hertz
5:13
I can use the prescaler of 180 and the
5:17
auto reload of 1000. using Auto reload
5:21
of 1000 is better instead of 100 because
5:24
our pulse width is small and so does the
5:29
with the reload value of 1000 we can
5:32
accumulate more values for the duty
5:34
cycle as compared to the value of 100.
5:37
you will understand this in a while
5:40
so we know the minimum pulse width is
5:43
going to be one millisecond which is
5:45
five percent of the 20 milliseconds
5:47
but our Auto reload is at 1000 so a five
5:51
percent duty means we have the value 50.
5:58
so one millisecond is equivalent to the
6:03
similarly two milliseconds will be
6:05
equivalent to the value 100. now since
6:08
we have the auto reload of 1000 we could
6:11
use the values from 50 to 100 but if we
6:14
had 100 here we could only use the
6:19
this is why I kept the auto reload at
6:25
all right let's set the values
6:30
180 and auto reload is 1000.
6:34
we will leave the rest of the setup to
6:38
this pulse value will be changed during
6:41
the runtime itself based on the input we
6:43
get from the potentiometer this is it
6:46
for the setup click save to generate the
6:50
let's write the code now
6:52
first we will start the timer in pwm
6:56
I am using timer 1 channel 1.
7:02
now start the ADC in the dma mode
7:06
we will Define the ADC data variable in
7:09
a while and there is only one conversion
7:15
Define the variable to store the ADC
7:21
we need to convert the raw ADC value to
7:24
our range of pwm values so we will store
7:27
the converted values in this variable
7:33
now when the dma will finish the
7:35
conversion the conversion completed
7:37
callback will be called
7:40
let's copy this definition
7:42
I am using the map function from the
7:44
Arduino source code to map the ADC
7:51
the values will be stored in the
7:55
we want to map the ADC data variable
7:58
value the minimum value of this variable
8:00
can be zero and the maximum can be
8:03
4095 since it's a 12-bit ADC value
8:08
the minimum output value can be 50 and
8:11
the maximum can be 100.
8:13
this is as per the duty cycle we
8:18
so basically when the potentiometer
8:20
reads 0 this function will output 50 and
8:24
when the potentiometer is at maximum
8:27
4095 this function will output 100.
8:31
now we need to send these values to our
8:34
timer so that the duty cycle can be
8:37
I am using timer 1 channel 1 so the CCR
8:41
one that is capture compare register 1.
8:44
you can use another capture compare
8:46
register if you are using another
8:49
channel of your timer
8:51
if you are familiar with bldc motors you
8:54
might know that we also need to
8:58
this code will do that for you
9:01
basically we set the maximum Duty that
9:04
is the pulse of 2 milliseconds and wait
9:08
the es c will sound the beep indicating
9:11
it has been calibrated for the high
9:14
now send the lowest Duty that is the
9:17
pulse of one millisecond and again wait
9:21
the e s c will again sound the beep
9:24
indicating it has been calibrated for
9:28
I have defined this at the top of the
9:30
file so that you can enable this only if
9:32
you want to calibrate
9:37
all right let's build the code
9:47
the start dma function takes a 32-bit
9:51
variable so let me Typecast this
9:59
all right everything is set now let's
10:04
I will use the motor later first we will
10:06
see the results in the debugger and the
10:10
we will monitor the ADC converted
10:15
here the potentiometer is at zero so the
10:20
and if I move the potentiometer to
10:22
maximum the value has been increased to
10:26
let's see the pulse timing on in the
10:33
I have connected the PIN pa8 to the
10:36
channel 0 of the analyzer
10:43
here you can see the pulse remains high
10:46
for one millisecond out of 20
10:49
and now I am rotating the potentiometer
10:53
to the maximum position
10:55
now we have the pulse with the width of
10:59
here the value of the variable is one
11:02
so the pulse timing is correct let's
11:07
I will disconnect the controller so that
11:09
it will directly get the power from the
11:21
you can hear the set of beeps produced
11:24
by the ESC it means the calibration is
11:28
let's rotate the motor
11:30
you can judge the speed by listening to
11:32
the sound it is making
12:08
so the motor is rotating fine and we
12:11
were able to control it using the
12:14
if you don't want to do the calibration
12:16
just set this definition to zero and
12:19
this particular code will be excluded
12:22
this is it for the video
12:24
I hope you understood how we can control
12:26
the bldc motor using the sdm-32
12:30
you can download the code from the link
12:34
leave comments in case of any doubt
12:37
keep watching and have a nice day ahead