0:16
everyone welcome to controllers tech
0:20
in this video we will cover how to
0:22
interface rotary angle sensor with stm32
0:27
this here is the rotary angle sensor and
0:31
to digital converter it works like a
0:35
so the resistance changes with rotation
0:38
and we get a variable voltage at the
0:45
it have four pins round vcc
0:49
and signal the third pin is not
0:54
we will use the reading from it and
0:58
angle by which the shaft has been
1:03
let's start by creating the project with
1:07
by the time the id loads let's see the
1:10
details about this rotary angle
1:39
as we can see here the sensor can rotate
1:53
here they have a sample code it is an
1:56
arduino code but it's simple to
2:01
let's go through it here first of all we
2:09
next convert this value to the voltage
2:15
and using this voltage find the angle
2:22
that's all as i said it's pretty simple
2:28
now let's create the project in cube id
2:34
choose your device here
2:37
give some name to this project and click
2:46
first of all i am selecting external
2:49
crystal for the clock
2:54
as this sensor works with adc i am
2:59
we will keep using 12 bits for the adc
3:06
here we will enable the continuous
3:10
that's all for the adc setup now let's
3:20
i have 8 megahertz external crystal and
3:23
i want the system to run at 180
3:33
click save to generate the project
3:40
let's see the connection once
3:47
vcc is connected to 3.3 volts
3:51
ground to ground and the signal pin
3:54
is connected to the pin pa-1 the channel
4:01
let's start our program now
4:09
first of all we will define a variable
4:12
that can store the adc
4:14
value next define the voltage
4:17
and the angle variables
4:22
to read the data from adc we will use
4:25
the pole for conversion method
4:28
so first start the adc
4:31
poll for the conversion to finish
4:34
read the value and store in the variable
4:41
and finally stop the adc
4:48
now we will convert this a-d-c value to
4:51
the respective voltage
4:53
here 4095 is used because i am using 12
4:57
bit resolution in adc
5:00
and 3.3 volts is the reference voltage
5:07
after getting the respective voltage we
5:09
will convert this to the angle
5:12
here 300 is the maximum angle and
5:15
3.3 volts is the supply to the sensor
5:19
let's give a delay of 10 milliseconds in
5:24
change the type here to float let's
5:29
we don't have any errors so let's debug
5:35
i have added all the three variables to
5:40
let's run it as you can see the values
5:51
as i rotate the potentiometer the angle
5:59
the maximum angle is 300 degrees
6:07
now it start reducing
6:16
and we are back to zero
6:22
this working is very simple as the
6:27
this is it for this video i will try to
6:31
where this sensor can be used to control
6:34
the position of the stepper motor
6:37
i hope you understood the video leave
6:40
comments in case of any doubt
6:43
you can download the code from the link
6:47
keep watching and have a nice day ahead