<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.robolabo.etsit.upm.es/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Blancal</id>
		<title>RobolaboWiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.robolabo.etsit.upm.es/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Blancal"/>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php/Special:Contributions/Blancal"/>
		<updated>2026-04-23T07:10:19Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.25.3</generator>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=LaTeX&amp;diff=2075</id>
		<title>LaTeX</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=LaTeX&amp;diff=2075"/>
				<updated>2026-03-26T10:57:06Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--__NOTOC__--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Installation &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install texlive-full&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Latex Manuals &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.robolabo.etsit.upm.es/publications/courses/2020-Latex_Manual1.pdf Manual 1 ]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.robolabo.etsit.upm.es/publications/courses/2020-Latex_Manual2.pdf Manual 2 ]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.robolabo.etsit.upm.es/publications/courses/2020-Latex_Manual3.pdf Manual 3 ]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Templates &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Trabajos Fin de Titulación (Pure Latex with Makefile) : [[http://www.robolabo.etsit.upm.es/wikiFiles/templateTFT_v2023.tgz templateTFT_v2023.tgz ]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Trabajos Fin de Titulación (Overleaf): [[http://www.robolabo.etsit.upm.es/wikiFiles/2023-LatexOverleafTemplate.zip 2023-LatexOverleafTemplate.zip]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Presentaciones: [[http://www.robolabo.etsit.upm.es/wikiFiles/tfg_presentation.tgz pres_template.tgz]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; [http://www.robolabo.etsit.upm.es/publications/courses/2020-Latex_OverleafTemplate.zip Overleaf template ]&amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; Trabajos Fin de Grado: [[media:tfg_export.tgz | tfg_template.tgz]]&amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some considerations you need to define in src/tft.tex:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If you want a double-side printing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\documentclass[twoside,a4paper,11pt]{book} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or a single-side printing&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\documentclass[oneside,a4paper,11pt]{book} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; The template has two colors to be implemented for titles and headers: orange&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\usepackage[orange]{tft} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or  black&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\usepackage[black]{tft} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; If compiling with latex (as with makefile provided), this line should be uncommented:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
\usepackage[dvipdfm]{hyperref} % Use it if compiling with latex (default on makefile)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the contrary, if using pdflatex (as for example overleaf), this line should be uncommented:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\usepackage{hyperref} % Use it if compiling with with pdflatex (default on overleaf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Bibtex &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Bibliography style for the different elements to cite inside the document.&lt;br /&gt;
ALIAS is referred to the name of the bibtex element that you are going to cite it. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Article &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@ARTICLE{ALIAS,&lt;br /&gt;
 author  = {{AUTHOR}},&lt;br /&gt;
 title   = {{TITLE}},&lt;br /&gt;
 journal = {{JOURNAL}},&lt;br /&gt;
 volume  = {{VOLUME}},&lt;br /&gt;
 number  = {{NUMBER}},&lt;br /&gt;
 pages   = {{PAGES}},&lt;br /&gt;
 year    = {{YEAR}},&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Collection of books &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@INCOLLECTION{ExIncollec01,&lt;br /&gt;
 author    = {{AUTHOR}},&lt;br /&gt;
 title 	   = {{TITLE}},&lt;br /&gt;
 booktitle = {{BOOKTITLE}},&lt;br /&gt;
 editor    = {{EDITOR}},&lt;br /&gt;
 publisher = {{PUBLISHER}},&lt;br /&gt;
 address   = {{ADRESS}},&lt;br /&gt;
 pages     = {{PAGES}},&lt;br /&gt;
 year      = {{YEAR}},&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Conference proceedings &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@INPROCEEDINGS{ExInpro01, &lt;br /&gt;
 author    = {{AUTHOR}},&lt;br /&gt;
 title 	   = {{TITLE}},&lt;br /&gt;
 booktitle = {{BOOKTITLE}},&lt;br /&gt;
 publisher = {{PUBLISHER}},&lt;br /&gt;
 address   = {{ADRESS}},&lt;br /&gt;
 pages     = {{PAGES}},&lt;br /&gt;
 year      = {{YEAR}},&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Technical Report &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@TECHREPORT{ALIAS,&lt;br /&gt;
 author      = {{AUTHOR}},&lt;br /&gt;
 title 	     = {{TITLE}},&lt;br /&gt;
 institution = {{INSTITUTION}},&lt;br /&gt;
 number      = {{NUMBER}},&lt;br /&gt;
 year        = {{YEAR}},&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Books &amp;lt;/h2&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@BOOK{ALIAS,      &lt;br /&gt;
 author    = {{AUTHOR}},&lt;br /&gt;
 title 	   = {{TITLE}},&lt;br /&gt;
 publisher = {{PUBLISHER}},&lt;br /&gt;
 address   = {{ADRESS}},&lt;br /&gt;
 year      = {{YEAR}},&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; PHD Thesis &amp;lt;/h2&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@PHDTHESIS{ALIAS,&lt;br /&gt;
 author = {{AUTHOR}},&lt;br /&gt;
 title  = {{TITLE}},&lt;br /&gt;
 school = {{SCHOOL}},	&lt;br /&gt;
 year   = {{YEAR}},&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Web Links &amp;lt;/h2&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@MISC{ALIAS,&lt;br /&gt;
 author       = {{AUTHOR}},&lt;br /&gt;
 title        = {{TITLE}},&lt;br /&gt;
 howpublished = {\url{LINK}},&lt;br /&gt;
 year         = {{YEAR}},&lt;br /&gt;
 note         = {[Online; accessed DATE]}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; TikZ &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some problems have been reported when compiling  TikZ with TexLive 2009.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Compilation Problems &amp;lt;/h2&amp;gt;&lt;br /&gt;
Whether compiling you get: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
I can't  find file tikzlibrary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, it is possible you have problems with TexLive and  need to install  new TexLive version.&lt;br /&gt;
&lt;br /&gt;
Download TexLive 2011 image:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://ftp.oleane.net/pub/CTAN/systems/texlive/Images/texlive2011.iso&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount the .iso image as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -o loop -t iso9660 texlive2011.iso /media/cdrom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install TexLive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./install-tl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose the following options:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Options -&amp;gt; Create SymLinks -&amp;gt; [Chose Standar Dirs]&lt;br /&gt;
Install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Compilation works, but not pictures shown &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Get last pgf package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://downloads.sourceforge.net/project/pgf/pgf/version%202.10/ \&lt;br /&gt;
  pgf_2.10.tds.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpgf%2F&amp;amp;ts= \&lt;br /&gt;
  1338847489&amp;amp;use_mirror=netcologne&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file.&lt;br /&gt;
Substitute the old pgp package by the new downloaded one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mv tex/generic/pgf/* /usr/share/texmf/tex/generic/pgf/*&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Execute as superuser:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
texhash&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; DVI problems &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
dvipdfm does not completelly supports tikz options.&lt;br /&gt;
Modify it by dvipdfmx&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Videos on Beamer &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In [[media:videoLatexTemplate.tgz | videoLatexTemplate.tgz]] there is an example with two different options to include videos on beamer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The first one inserts the video on the pdf.&lt;br /&gt;
There is a &amp;lt;i&amp;gt;video2image.sh&amp;lt;/i&amp;gt; script that converts a video into different frames (.EPS).&lt;br /&gt;
It requires ffmpeg and sam2p.&lt;br /&gt;
&lt;br /&gt;
Later on &amp;lt;i&amp;gt; animategraphics &amp;lt;/i&amp;gt; is in charge of moving the frames:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\animategraphics[autoplay,loop,width=6cm]{&amp;lt;NUM_FRAME&amp;gt;{mov/&amp;lt;VIDEO_FOLDER&amp;gt;}{&amp;lt;FIRST_FRAME&amp;gt;}{&amp;lt;LAST_FRAME&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The second one inserts an image that one pressed launches a player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\movie[externalviewer]{\includegraphics[width=0.5cm]{figs/&amp;lt;FIG_ICON&amp;gt;}}{mov/&amp;lt;VIDEO_FILE&amp;gt;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To compile you need to run:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make videos&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Memory size limit &amp;lt;/h1&amp;gt;&lt;br /&gt;
If you get something like this: TeX capacity exceeded, sorry [main memory size=5000000].&lt;br /&gt;
&lt;br /&gt;
Run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kpsewhich texmf.cnf &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit, the file that it outputs regardless it says not to touch&lt;br /&gt;
&lt;br /&gt;
Add the follwing line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
main_memory = 8000000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you need to update the system:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
fmtutil-sys --all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that, it should work&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=694</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=694"/>
				<updated>2023-02-06T11:11:22Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The encoder used in the laboratory is a position sensor that uses a two-channels hall effect sensor. It is a quadrature encoder that is attached to the motor shaft and which provides a resolution of &amp;lt;b&amp;gt;48 counts per revolution&amp;lt;/b&amp;gt;. This means that, for a complete turn of the motor shaft, the encoder provides a value of 48 counts. The hall sensor requires an input voltage, Vcc. Additionally, the output of the encoder comes from reading the output of the two channels, channel A and channel B, of the hall sensor. These two channels are square waves which are 90º out of phase.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
One method that is often used to control the speed of a DC motor is the Pulse Width Modulation (PWM) method. The speed of the electric motor depends on the modulator voltage. The greater the voltage, the faster the rotation of an electric motor. The use of this PWM can be used to control motor rotation through changes in PWM duty cycle or PWM pulse width. When the duty cycle is 0%, the motor will stop completely. When the duty cycle is 50%, the motor will rotate at half the speed of the maximum speed and when the PWM is 100%, the motor rotates with maximum speed. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=693</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=693"/>
				<updated>2023-02-06T11:10:43Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The encoder used in the laboratory is a position sensor that uses a two-channels hall effect sensor. It is a quadrature encoder that is attached to the motor shaft and which provides a resolution of &amp;lt;b&amp;gt;48 counts per revolution&amp;lt;/b&amp;gt;. This means that, for a complete turn of the motor shaft, the encoder provides a value of 48 counts. The hall sensor requires an input voltage, Vcc. Additionally, the output of the encoder comes from reading the output of the two channels, channel A and channel B, of the hall sensor. These two channels are square waves which are 90ª out of phase.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
One method that is often used to control the speed of a DC motor is the Pulse Width Modulation (PWM) method. The speed of the electric motor depends on the modulator voltage. The greater the voltage, the faster the rotation of an electric motor. The use of this PWM can be used to control motor rotation through changes in PWM duty cycle or PWM pulse width. When the duty cycle is 0%, the motor will stop completely. When the duty cycle is 50%, the motor will rotate at half the speed of the maximum speed and when the PWM is 100%, the motor rotates with maximum speed. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=692</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=692"/>
				<updated>2023-02-06T10:41:50Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The encoder used in the laboratory is a position sensor that uses a two-channels hall effect sensor. It is a quadrature encoder that is attached to the motor shaft and which provides a resolution of &amp;lt;b&amp;gt;48 counts per revolution&amp;lt;/b&amp;gt;. This means that, for a complete turn of the motor shaft, the encoder provides a value of 48 counts. The hall sensor requires an input voltage, Vcc. Additionally, the output of the encoder comes from reading the output of the two channels, channel A and channel B, of the hall sensor. These two channels are square waves which are 90ª out of phase.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=691</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=691"/>
				<updated>2023-02-06T10:41:13Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The encoder used in the laboratory is a position sensor that uses a two-channels hall effect sensor. It is a quadrature encoder that is attached to the motor shaft and which provides a resolution of &amp;lt;b&amp;gt;48 counts per revolution:&amp;lt;/b&amp;gt;. This means that, for a complete turn of the motor shaft, the encoder provides a value of 48 counts. The hall sensor requires an input voltage, Vcc. Additionally, the output of the encoder comes from reading the output of the two channels, channel A and channel B, of the hall sensor. These two channels are square waves which are 90ª out of phase.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=690</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=690"/>
				<updated>2023-02-06T10:40:26Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The encoder used in the laboratory is a position sensor that uses a two-channels hall effect sensor. It is a quadrature encoder that is attached to the motor shaft and which provides a resolution of &amp;lt;b&amp;gt;48 counts per revolution:&amp;lt;/b&amp;gt;. This means that, for a complete turn of the motor shaft, the encoder provides a value of 48 counts. The hall sensor requires an input voltage and the output of the encoder comes from reading the output of the two channels, channel A and channel B. These two channels are square waves which are 90ª out of phase.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=689</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=689"/>
				<updated>2023-02-06T10:38:26Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The encoder used in the laboratory is a position sensor that uses a two-channel hall effect sensor. It is a quadrature encoder that is attached to the motor shaft and which provides a resolution of 48 counts per revolution. This means that for a complete turn of the motor shaft, the encoder provides a value of 48 counts. The hall sensor requires an input voltage and the output of the encoder comes from reading the output of the two channels, channel A and channel B. These two channels are square waves which are 90ª out of phase.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=688</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=688"/>
				<updated>2023-02-06T10:38:03Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The encoder used is a position sensor that uses a two-channel hall effect sensor. It is a quadrature encoder that is attached to the motor shaft and which provides a resolution of 48 counts per revolution. This means that for a complete turn of the motor shaft, the encoder provides a value of 48 counts. The hall sensor requires an input voltage and the output of the encoder comes from reading the output of the two channels, channel A and channel B. These two channels are square waves which are 90ª out of phase.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=687</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=687"/>
				<updated>2023-02-06T10:29:49Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=686</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=686"/>
				<updated>2023-02-06T10:29:36Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
To install STM32CubeIDE and to run a Hello World example, please check it here: http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=685</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=685"/>
				<updated>2023-02-06T10:21:47Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; Clock of the timer. The Internal clock option must be selected. Moreover, it must be checked that the frequency of the clock that is being used is the one desired. This could be checked within the clock configuration tab of the STM32CubeIDE. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; Configuration for the channel x of the timer. The option “PWM Generation CHx” must be selected, in which x will be the number of the channel to configure.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parameter to introduce the value of the PSC register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parameter to set the value of the ARR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; Parameter to mofidy the CCR register.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; The PWM mode 1 must be selected.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, within the code, the timer to use must be initialized following the structure below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CCR value can be modified by introducing the following instruction: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in which CCR1 indicates that we are accessing to the channel 1 register, new_ccr is the new to set and htimx refers to the timer x (for example, htim2 or htim3).&lt;br /&gt;
&lt;br /&gt;
In the same way, to modify the register of the channel 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=684</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=684"/>
				<updated>2023-02-06T10:12:24Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; GPIO read and write &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Read from a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Write to a GPIO&amp;lt;/h2&amp;gt;&lt;br /&gt;
- High level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Low level:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Encoder Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Theory &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Main registers &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prescaler is a register that divides the timer clock frequency to obtain a specific frequency.&lt;br /&gt;
Specifically, the frequency reduction is applied using the following formula:  &lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Therefore, if the frequency to set is the same as the frequency of the clock, the PSC register must be set at PSC=0.&lt;br /&gt;
The STM32 timers allow a prescaler value up to 65535, through 16 bits registers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) and Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
The ARR register storages the maximum value that the counter can reach before going back to zero. &lt;br /&gt;
Moreover, the CCR registers the value of the corresponding timer counter after which the output PWM signal goes from high to low level. &lt;br /&gt;
Every channel of the timer used to generate the PWM will have a different CCR register (for example, CCR1 and CCR2 for channels 1 and 2).&lt;br /&gt;
In this way, the value of the CCR together with the value of the ARR define the width of the pulses and, therefore, the duty cycle of the PWM signal:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
This is the register that storages the value of the counter used to generate the PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;PWM Configuration in STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure a timer as PWM, the first thing to do is to select one of the timers that could be configured as a PWM generator. &lt;br /&gt;
Additionally, also the channels that will be used as PWM output must be decided. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; As different PWM outputs are needed, it is recommended to use different channels of the same timer to the extent possible.&lt;br /&gt;
&lt;br /&gt;
The main timers that can be set as PWM are: TIM2, TIM3, TIM4 and TIM5, with 4 different channels each of them. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advice:&amp;lt;/b&amp;gt; It is recommended to use the timer and the corresponding channels that match directly with the pins that feed the H-bridge to modulate the speed of the motor. Otherwise, the PWM output signals must be bridged with the H-bridge input signals. &lt;br /&gt;
&lt;br /&gt;
Therefore, the pins that the channels of the timer are using need to be checked in the &amp;quot;Pinout&amp;quot; section of the STM32CubeIDE.&lt;br /&gt;
&lt;br /&gt;
Once the channels of the timer have been activated, some parameters and the configuration of the timer must be changed. &lt;br /&gt;
&lt;br /&gt;
Main parameters:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; reloj a tomar como referencia por el timer. Debemos seleccionar la opción Internal clock. Además, debemos asegurarnos que la frecuencia del reloj usada es la deseada, en la pestaña de clock configuration.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; configuración deseada para el canal x del timer. Debemos seleccionar la opción “PWM Generation CHx”, donde x será el número del canal en cuestión.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parámetro para configurar el registro de PSC.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parámetro para configurar el valor del registro ARR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; parámetro para modificar el registro de CCR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; Debemos seleccionar PWM mode 1.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Además, en nuestro código debemos activar el timer ya configurado e inicializado de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Podemos modificar el valor de CCR (aceder al registro) mediante código de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
donde CCR1 indica que estamos accediendo al registro del canal 1, new_ccr es el nuevo valor entero que queremos establecer y htimx es la instancia correspondiente al timer x (por ejemplo, htim2 o htim3).&lt;br /&gt;
&lt;br /&gt;
De igual manera, para modificar el registro del canal 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=683</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=683"/>
				<updated>2023-02-06T09:22:47Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Lectura y escritura de pines &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Lectura&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Escritura&amp;lt;/h2&amp;gt;&lt;br /&gt;
- A nivel alto:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- A nivel bajo:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de encoder en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Principales registros &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El preescalado es un registro que especifica entre cuánto se debe dividir la frecuencia de referencia del reloj usado por el timer.&lt;br /&gt;
En concreto, la reducción  de frecuencia se aplica de la siguiente manera:&lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, hay que tener en cuenta que si queremos mantener la misma frecuencia que la del reloj de referencia debemos fijar PSC=0.&lt;br /&gt;
Los timers del STM32 admiten valores de preescalado de hasta 65535, mediante registros de 16 bits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) y Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El registro ARR almacena el valor máximo que debe alcanzar el contador antes de volver a cero. &lt;br /&gt;
Por otra parte, CCR registra valor del contador del timer asociado a partir del cual la señal PWM de salida pasa de nivel alto a nivel bajo. &lt;br /&gt;
Cada canal del timer usado para la generación de señal PWM tendrá un registro CCR diferente (por ejemplo CCR1 y CCR para canales 1 y 2). &lt;br /&gt;
De esta manera, el valor de CCR junto con el valor de ARR definen la anchura de los pulsos y con ello el ciclo de trabajo de la señal PWM:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
Es el registro que almacena el valor actual del contador usado para la generación PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de PWM en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Para configurar el timer como PWM primero debemos seleccionar uno de los posibles timers configurables como generador PWM. &lt;br /&gt;
También debemos decidir los canles que queremos usar como salidas PWM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt; Al usar varias salidas PWM es recomendable usar diferentes canales del mismo timer en la medida de lo posible.&lt;br /&gt;
&lt;br /&gt;
Los principales timers configurables como PWM son el TIM2, TIM3, TIM4 y TIM5, con 4 canales independientes cada uno. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt;  Es recomendable usar el timer y los canales que se correspondan directamente con los pines que alimentan las entradas del Puente H para modular la velocidad del motor. En caso contrario deberemos puentear las salidas del timer PWM con las entradas del puente H.&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, deberemos buscar los pines asociados a los canales del timer a usar en la vista “Pinout” del entorno de desarrollo.&lt;br /&gt;
&lt;br /&gt;
Una vez hemos activado los canales del timer necesarios, debemos modificar la configuración y parámetros del timer.&lt;br /&gt;
Los principales parámetros&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; reloj a tomar como referencia por el timer. Debemos seleccionar la opción Internal clock. Además, debemos asegurarnos que la frecuencia del reloj usada es la deseada, en la pestaña de clock configuration.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; configuración deseada para el canal x del timer. Debemos seleccionar la opción “PWM Generation CHx”, donde x será el número del canal en cuestión.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parámetro para configurar el registro de PSC.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parámetro para configurar el valor del registro ARR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; parámetro para modificar el registro de CCR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; Debemos seleccionar PWM mode 1.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Además, en nuestro código debemos activar el timer ya configurado e inicializado de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Podemos modificar el valor de CCR (aceder al registro) mediante código de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
donde CCR1 indica que estamos accediendo al registro del canal 1, new_ccr es el nuevo valor entero que queremos establecer y htimx es la instancia correspondiente al timer x (por ejemplo, htim2 o htim3).&lt;br /&gt;
&lt;br /&gt;
De igual manera, para modificar el registro del canal 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Serial Port &amp;lt;/h1&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=682</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=682"/>
				<updated>2023-02-06T09:18:37Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Lectura y escritura de pines &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Lectura&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Escritura&amp;lt;/h2&amp;gt;&lt;br /&gt;
- A nivel alto:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- A nivel bajo:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;img src=&amp;quot;robolabo.png&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de encoder en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Principales registros &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El preescalado es un registro que especifica entre cuánto se debe dividir la frecuencia de referencia del reloj usado por el timer.&lt;br /&gt;
En concreto, la reducción  de frecuencia se aplica de la siguiente manera:&lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, hay que tener en cuenta que si queremos mantener la misma frecuencia que la del reloj de referencia debemos fijar PSC=0.&lt;br /&gt;
Los timers del STM32 admiten valores de preescalado de hasta 65535, mediante registros de 16 bits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) y Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El registro ARR almacena el valor máximo que debe alcanzar el contador antes de volver a cero. &lt;br /&gt;
Por otra parte, CCR registra valor del contador del timer asociado a partir del cual la señal PWM de salida pasa de nivel alto a nivel bajo. &lt;br /&gt;
Cada canal del timer usado para la generación de señal PWM tendrá un registro CCR diferente (por ejemplo CCR1 y CCR para canales 1 y 2). &lt;br /&gt;
De esta manera, el valor de CCR junto con el valor de ARR definen la anchura de los pulsos y con ello el ciclo de trabajo de la señal PWM:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
Es el registro que almacena el valor actual del contador usado para la generación PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de PWM en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Para configurar el timer como PWM primero debemos seleccionar uno de los posibles timers configurables como generador PWM. &lt;br /&gt;
También debemos decidir los canles que queremos usar como salidas PWM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt; Al usar varias salidas PWM es recomendable usar diferentes canales del mismo timer en la medida de lo posible.&lt;br /&gt;
&lt;br /&gt;
Los principales timers configurables como PWM son el TIM2, TIM3, TIM4 y TIM5, con 4 canales independientes cada uno. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt;  Es recomendable usar el timer y los canales que se correspondan directamente con los pines que alimentan las entradas del Puente H para modular la velocidad del motor. En caso contrario deberemos puentear las salidas del timer PWM con las entradas del puente H.&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, deberemos buscar los pines asociados a los canales del timer a usar en la vista “Pinout” del entorno de desarrollo.&lt;br /&gt;
&lt;br /&gt;
Una vez hemos activado los canales del timer necesarios, debemos modificar la configuración y parámetros del timer.&lt;br /&gt;
Los principales parámetros&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; reloj a tomar como referencia por el timer. Debemos seleccionar la opción Internal clock. Además, debemos asegurarnos que la frecuencia del reloj usada es la deseada, en la pestaña de clock configuration.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; configuración deseada para el canal x del timer. Debemos seleccionar la opción “PWM Generation CHx”, donde x será el número del canal en cuestión.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parámetro para configurar el registro de PSC.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parámetro para configurar el valor del registro ARR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; parámetro para modificar el registro de CCR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; Debemos seleccionar PWM mode 1.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Además, en nuestro código debemos activar el timer ya configurado e inicializado de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Podemos modificar el valor de CCR (aceder al registro) mediante código de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
donde CCR1 indica que estamos accediendo al registro del canal 1, new_ccr es el nuevo valor entero que queremos establecer y htimx es la instancia correspondiente al timer x (por ejemplo, htim2 o htim3).&lt;br /&gt;
&lt;br /&gt;
De igual manera, para modificar el registro del canal 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=681</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=681"/>
				<updated>2023-02-06T09:16:33Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Lectura y escritura de pines &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Lectura&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Escritura&amp;lt;/h2&amp;gt;&lt;br /&gt;
- A nivel alto:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- A nivel bajo:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de encoder en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Principales registros &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El preescalado es un registro que especifica entre cuánto se debe dividir la frecuencia de referencia del reloj usado por el timer.&lt;br /&gt;
En concreto, la reducción  de frecuencia se aplica de la siguiente manera:&lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, hay que tener en cuenta que si queremos mantener la misma frecuencia que la del reloj de referencia debemos fijar PSC=0.&lt;br /&gt;
Los timers del STM32 admiten valores de preescalado de hasta 65535, mediante registros de 16 bits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) y Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El registro ARR almacena el valor máximo que debe alcanzar el contador antes de volver a cero. &lt;br /&gt;
Por otra parte, CCR registra valor del contador del timer asociado a partir del cual la señal PWM de salida pasa de nivel alto a nivel bajo. &lt;br /&gt;
Cada canal del timer usado para la generación de señal PWM tendrá un registro CCR diferente (por ejemplo CCR1 y CCR para canales 1 y 2). &lt;br /&gt;
De esta manera, el valor de CCR junto con el valor de ARR definen la anchura de los pulsos y con ello el ciclo de trabajo de la señal PWM:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
Es el registro que almacena el valor actual del contador usado para la generación PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de PWM en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Para configurar el timer como PWM primero debemos seleccionar uno de los posibles timers configurables como generador PWM. &lt;br /&gt;
También debemos decidir los canles que queremos usar como salidas PWM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt; Al usar varias salidas PWM es recomendable usar diferentes canales del mismo timer en la medida de lo posible.&lt;br /&gt;
&lt;br /&gt;
Los principales timers configurables como PWM son el TIM2, TIM3, TIM4 y TIM5, con 4 canales independientes cada uno. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt;  Es recomendable usar el timer y los canales que se correspondan directamente con los pines que alimentan las entradas del Puente H para modular la velocidad del motor. En caso contrario deberemos puentear las salidas del timer PWM con las entradas del puente H.&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, deberemos buscar los pines asociados a los canales del timer a usar en la vista “Pinout” del entorno de desarrollo.&lt;br /&gt;
&lt;br /&gt;
Una vez hemos activado los canales del timer necesarios, debemos modificar la configuración y parámetros del timer.&lt;br /&gt;
Los principales parámetros&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; reloj a tomar como referencia por el timer. Debemos seleccionar la opción Internal clock. Además, debemos asegurarnos que la frecuencia del reloj usada es la deseada, en la pestaña de clock configuration.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; configuración deseada para el canal x del timer. Debemos seleccionar la opción “PWM Generation CHx”, donde x será el número del canal en cuestión.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parámetro para configurar el registro de PSC.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parámetro para configurar el valor del registro ARR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; parámetro para modificar el registro de CCR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; Debemos seleccionar PWM mode 1.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Además, en nuestro código debemos activar el timer ya configurado e inicializado de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Podemos modificar el valor de CCR (aceder al registro) mediante código de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
donde CCR1 indica que estamos accediendo al registro del canal 1, new_ccr es el nuevo valor entero que queremos establecer y htimx es la instancia correspondiente al timer x (por ejemplo, htim2 o htim3).&lt;br /&gt;
&lt;br /&gt;
De igual manera, para modificar el registro del canal 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=680</id>
		<title>Nucleo Boards for Control Systems</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=Nucleo_Boards_for_Control_Systems&amp;diff=680"/>
				<updated>2023-02-06T09:14:48Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Lectura y escritura de pines &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Lectura&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_9);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Escritura&amp;lt;/h2&amp;gt;&lt;br /&gt;
- A nivel alto:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- A nivel bajo:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Encoder &amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
hohslhalsodhas&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de encoder en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; PWM &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Teoría &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Principales registros &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h3&amp;gt; Prescaler (PSC) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El preescalado es un registro que especifica entre cuánto se debe dividir la frecuencia de referencia del reloj usado por el timer.&lt;br /&gt;
En concreto, la reducción  de frecuencia se aplica de la siguiente manera:&lt;br /&gt;
&lt;br /&gt;
f_PWM = f_CLK / (PSC + 1)&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, hay que tener en cuenta que si queremos mantener la misma frecuencia que la del reloj de referencia debemos fijar PSC=0.&lt;br /&gt;
Los timers del STM32 admiten valores de preescalado de hasta 65535, mediante registros de 16 bits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Auto Reload Register (ARR) y Capture Compare Register (CCR) &amp;lt;/h3&amp;gt;&lt;br /&gt;
El registro ARR almacena el valor máximo que debe alcanzar el contador antes de volver a cero. &lt;br /&gt;
Por otra parte, CCR registra valor del contador del timer asociado a partir del cual la señal PWM de salida pasa de nivel alto a nivel bajo. &lt;br /&gt;
Cada canal del timer usado para la generación de señal PWM tendrá un registro CCR diferente (por ejemplo CCR1 y CCR para canales 1 y 2). &lt;br /&gt;
De esta manera, el valor de CCR junto con el valor de ARR definen la anchura de los pulsos y con ello el ciclo de trabajo de la señal PWM:&lt;br /&gt;
&lt;br /&gt;
Duty_Cycle (%) = 100 * (CCR / ARR)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; CNT &amp;lt;/h3&amp;gt;&lt;br /&gt;
Es el registro que almacena el valor actual del contador usado para la generación PWM. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Configuración de PWM en STM32CubeIDE&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Para configurar el timer como PWM primero debemos seleccionar uno de los posibles timers configurables como generador PWM. &lt;br /&gt;
También debemos decidir los canles que queremos usar como salidas PWM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt; Al usar varias salidas PWM es recomendable usar diferentes canales del mismo timer en la medida de lo posible.&lt;br /&gt;
&lt;br /&gt;
Los principales timers configurables como PWM son el TIM2, TIM3, TIM4 y TIM5, con 4 canales independientes cada uno. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Consejo:&amp;lt;/b&amp;gt;  Es recomendable usar el timer y los canales que se correspondan directamente con los pines que alimentan las entradas del Puente H para modular la velocidad del motor. En caso contrario deberemos puentear las salidas del timer PWM con las entradas del puente H.&lt;br /&gt;
&lt;br /&gt;
Por lo tanto, deberemos buscar los pines asociados a los canales del timer a usar en la vista “Pinout” del entorno de desarrollo.&lt;br /&gt;
&lt;br /&gt;
Una vez hemos activado los canales del timer necesarios, debemos modificar la configuración y parámetros del timer.&lt;br /&gt;
Los principales parámetros&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Clock Source:&amp;lt;/b&amp;gt; reloj a tomar como referencia por el timer. Debemos seleccionar la opción Internal clock. Además, debemos asegurarnos que la frecuencia del reloj usada es la deseada, en la pestaña de clock configuration.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Channel x:&amp;lt;/b&amp;gt; configuración deseada para el canal x del timer. Debemos seleccionar la opción “PWM Generation CHx”, donde x será el número del canal en cuestión.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Prescaler (PSC):&amp;lt;/b&amp;gt; Parámetro para configurar el registro de PSC.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Counter Period:&amp;lt;/b&amp;gt; Parámetro para configurar el valor del registro ARR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Pulse (16 bits):&amp;lt;/b&amp;gt; parámetro para modificar el registro de CCR.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;Mode: &amp;lt;/b&amp;gt; Debemos seleccionar PWM mode 1.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Además, en nuestro código debemos activar el timer ya configurado e inicializado de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HAL_TIM_PWM_Start(&amp;amp;htim3, TIM_CHANNEL_1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Podemos modificar el valor de CCR (aceder al registro) mediante código de la siguiente manera:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR1 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
donde CCR1 indica que estamos accediendo al registro del canal 1, new_ccr es el nuevo valor entero que queremos establecer y htimx es la instancia correspondiente al timer x (por ejemplo, htim2 o htim3).&lt;br /&gt;
&lt;br /&gt;
De igual manera, para modificar el registro del canal 2: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
htimx.Instance-&amp;gt;CCR2 = new_ccr;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=1DOF_Haptic&amp;diff=579</id>
		<title>1DOF Haptic</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=1DOF_Haptic&amp;diff=579"/>
				<updated>2018-07-23T17:14:48Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Note: &amp;lt;/b&amp;gt; The electronics of the robot are based on a Arduino Due board: https://www.arduino.cc/en/Main/ArduinoBoardDue&lt;br /&gt;
Moreover, the motor control is done through a H-Bridge board from ST: http://www.st.com/en/ecosystems/x-nucleo-ihm04a1.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Configuring the environment  &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Setting up the Arduino Software &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Download the Arduino IDE 1.6.x according to your operating system from: https://www.arduino.cc/en/Main/Software . &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Install the Arduino IDE &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If you have chosen to download the installer, run the installer and install the software in a path of your convenience. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If you have chosen to download the sources (Linux or zip on Windows), uncompress the software in a path of your convenience &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open/run Arduino IDE, so it will create all the folders needed&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Installing Tools and Libraries &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The 1DOF haptic robot uses a Arduino DUE board, so the Arduino IDE support must be installed. Open Boards configurator: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tools &amp;amp;rarr; Boards &amp;amp;rarr; Boards' Manager&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install support for SAM Boards - (32-bits ARM Cortex-M3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Download the DueTimer.zip library from: https://github.com/ivanseidel/DueTimer/releases &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Install the library: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Program &amp;amp;rarr; Include library &amp;amp;rarr; Add Zip library&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Select the zip file that has been downloaded &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Installing FTDI drivers &amp;lt;/h3&amp;gt;&lt;br /&gt;
If you are using Linux or Mac, skip this step.&lt;br /&gt;
If you are using Windows, power up the robot and connect it to your computer.&lt;br /&gt;
Windows should ask you to install some FTDI drivers to be able to connect to the robot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Hello World example  &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have created a helloWorld example to test the communication with the robot.&lt;br /&gt;
Please download it from [[media:1DOFHAP-HelloWorldMotor.tgz | here ]] in your prefered destination.&lt;br /&gt;
Untar the file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvzf helloWorld.tgz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Compiling the code &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open Arduino IDE and load the .ino file in your environment: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File &amp;amp;rarr; Open &amp;amp;rarr; &amp;lt;HELLOWORLD_EXAMPLE&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Select the Arduino DUE board: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tools &amp;amp;rarr; Board &amp;amp;rarr; Arduino Due&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Compile the program: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Program &amp;amp;rarr; Verify/Compile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Downloading the code to the robot &amp;lt;/h2&amp;gt;&lt;br /&gt;
The Arduino Due has two usb ports. The one that is closer to the power jack is the programming port and the one used with the 1DOF Haptic Robot.&lt;br /&gt;
&lt;br /&gt;
Select the correct port to download the binaries:&lt;br /&gt;
In Linux, typically:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tools &amp;amp;rarr; Port &amp;amp;rarr; /dev/ttyUSBX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Windows, typically:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tools &amp;amp;rarr; Port &amp;amp;rarr; COMX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where X depends on your system and the number of peripherals on it&lt;br /&gt;
&lt;br /&gt;
Upload your code to the board:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Program &amp;amp;rarr; Upload&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The IDE will notify that it is &amp;lt;i&amp;gt; uploading &amp;lt;/i&amp;gt; and after some seconds it will say &amp;lt;i&amp;gt; uploaded &amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Playing with HelloWorld &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example allows you to see the functionality of some of the functions handcoded.&lt;br /&gt;
Once the software has been loaded, the robot should move 1 second  counterclockwise and 1 second clockwise.&lt;br /&gt;
After those 2 seconds it should stop.&lt;br /&gt;
&lt;br /&gt;
Once the code have been loaded, you can open the serial port:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tools &amp;amp;rarr; Serial Monitor&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see in real time the information provided by the helloworld example, basically:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Count: The communication time, in timer ticks&lt;br /&gt;
&amp;lt;li&amp;gt; Pos: The position, in encoder pulses units&lt;br /&gt;
&amp;lt;li&amp;gt; Vel: The speed, in encoder pulses units&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Practice 2 Template (P2)&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the implementation of Practice 2 of the &amp;quot;Control and Robotics in Medicine&amp;quot; subject of the &amp;quot;Master on Bioengineering&amp;quot;  of the UPM, we have created a students template.&lt;br /&gt;
You can download the template from [[media:1DOFHAP-P2Template.tgz | here ]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Structure &amp;lt;/h2&amp;gt; &lt;br /&gt;
The template has 5 different block of files:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; encoder.{c,h} &amp;lt;/b&amp;gt;: where functions related to the measurement of the encoder are developed.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; motor.{c,h} &amp;lt;/b&amp;gt;: where functions related to the movement of the motor are developed.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; comm.{c,h} &amp;lt;/b&amp;gt;: where functions related to the serial port communication are developed.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; controller.{c,h} &amp;lt;/b&amp;gt;: where specific controllers could be developed. &amp;lt;b&amp;gt; It will not be used on P2 &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; P2-Template.ino &amp;lt;/b&amp;gt;: The place where the practice should be developed.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Methods &amp;lt;/h2&amp;gt;&lt;br /&gt;
This Section provides important information for the resolution of Practice2.&lt;br /&gt;
It is based on the explanation of different methods to control the robot, but it does not explain the complete set of methods.&lt;br /&gt;
To get and exahustive description of all methods all fies must be studied.&lt;br /&gt;
&lt;br /&gt;
Given some restrictions to the Arduino software structure, some function prototypes are defined in the main file.&lt;br /&gt;
However, sections related to the header files refer to its implementation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Encoder &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This library is in charge of calculating the movement of the motor related to the encoder.&lt;br /&gt;
The functions to control the encoder are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void ENCODER_Init (void) &amp;lt;/b&amp;gt;: It configures the pinout of the encoder and launches the interrupts related to channel A and B. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void ENCODER_Init (void)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures the pinout of the encoder and launches the interrupts related to channel A and B.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void ENCODER_StartSpeedCalculation  ( long l_sampling_time ) &amp;lt;/b&amp;gt;: It configures a timer in charge of calculating the speed average of the motor.  &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void ENCODER_StartSpeedCalculation  ( long l_sampling_time )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures a timer in charge of calculating the speed average of the motor.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long l_sampling_time &amp;lt;/b&amp;gt;: It defines the sampling period in milliseconds.&lt;br /&gt;
&amp;lt;/ul&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long ENCODER_GetCount ( void ) &amp;lt;/b&amp;gt;: It returns the actual count of the encoder, that is, the position of the motor related to its initial condition. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
long ENCODER_GetCount ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It returns the actual count of the encoder, that is, the position of the motor related to its initial condition.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; return &amp;lt;/b&amp;gt;: It returns a long value related to the pulses of the encoder, positive or negative, related to the initial position of the encoder. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long ENCODER_GetCountInSpeedInterval ( void) &amp;lt;/b&amp;gt;: It returns an averge speed, expressed in counts per second. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
long ENCODER_GetCountInSpeedInterval ( void)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It returns an averge speed, expressed in counts per second. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; return &amp;lt;/b&amp;gt;: It returns a long value related to the pulses per second of the encoder, positive or negative.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; IMPORTANT: The encoder available on Practice 2, is a 48 quadrature Counts Per Revolution (CPR) encoder.&lt;br /&gt;
This means that &amp;lt;i&amp;gt; ENCODER_GetCount (void) &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; ENCODER_GetCountInSpeedInterval (void) &amp;lt;/i&amp;gt; functions return a value related to the encoder counts.&lt;br /&gt;
That means that for every turn on the motor axis, there are 48 values (1 pulse every 7.5 degrees). &lt;br /&gt;
This value must be multiplied by the reduction ratio of the motor to check the position outside the motor axis. &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Motor &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This library is in charge of moving the motor. &lt;br /&gt;
The motor is moved based on a PWM which is executed at a sampling period.&lt;br /&gt;
&lt;br /&gt;
The functions to control the motor are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void MOTOR_Init ( void ) &amp;lt;/b&amp;gt;: It configures the pinout of the H-bridge to control the motor and inits the PWM peripheral to control it. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MOTOR_Init ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures the pinout of the H-bridge to control the motor and inits the PWM peripheral to control it.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void MOTOR_SetVoltage ( float f_voltage ) &amp;lt;/b&amp;gt;: It sets up a voltage to be sent to the motor. Remember the motor is controlled through a PWM, so it really sets up a PWM to controlthe H-Bridge. --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MOTOR_SetVoltage ( float f_voltage )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It sets up a voltage to be sent to the motor. Remember the motor is controlled through a PWM, so it really sets up a PWM to controlthe H-Bridge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; flot f_voltage &amp;lt;/b&amp;gt;: This is the value of the voltage to be applied to the motor. It can be positive or negative, and the function limits the maximum and minimum values according to the &amp;lt;i&amp;gt; MOTOR_MAX_VOLTAGE &amp;lt;/i&amp;gt; variable defined in &amp;lt;i&amp;gt; motor.h &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Communication &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This library is in charge of managing periodic communications through the serial port.&lt;br /&gt;
The functions are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_Init ( int speed );  &amp;lt;/b&amp;gt;: It configures the serial port at a specific speed. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_Init ( int speed );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures the serial port at a specific speed.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; int speed &amp;lt;/b&amp;gt;: The speed, in bauds, to configure and open the serial port. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_Start ( long l_sampling_time ) &amp;lt;/b&amp;gt;: It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_Start ( long l_sampling_time )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long l_sampling_time &amp;lt;/b&amp;gt;: It defines the sampling period in milliseconds.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_Stop ( void ) &amp;lt;/b&amp;gt;: It stops the timer in charge of calling &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt;, so communication stops. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_Stop ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It stops the timer in charge of calling &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt;, so communication stops.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Controller &amp;lt;/h3&amp;gt;&lt;br /&gt;
This library is in charge of managing a periodic timer to implement the controller developed.&lt;br /&gt;
The functions are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void CONTROLLER_Start ( long l_sampling_time ) &amp;lt;/b&amp;gt;: It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; CONTROLLER_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt;&amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void CONTROLLER_Start ( long l_sampling_time )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; CONTROLLER_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long l_sampling_time &amp;lt;/b&amp;gt;: It defines the sampling period in milliseconds.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; P2-Template.ino &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_ROB ( void ) &amp;lt;/b&amp;gt;: In this function you should implement which is the information you want to send through the serial port, to obtain specific data and plot some graphs. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_ROB ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This function should implement which is the information you want to send through the serial port, to obtain specific data and plot some graphs.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void CONTROLLER_ROB ( void )&amp;lt;/b&amp;gt;: In this function you should implement your controllers. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void CONTROLLER_ROB ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This function should implement the controllers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Important &amp;lt;/b&amp;gt;: It is important that the helloworld and template files are studied before starting Practice 2.&lt;br /&gt;
Moreover, it is recommended that before arriving to the laboratory, two functions to convert encoder counts to position (in radians) and speed (in radians/second) are already programmed, to save time and get a basic understanding of the robot electronics.&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	<entry>
		<id>https://wiki.robolabo.etsit.upm.es/index.php?title=1DOF_Haptic&amp;diff=578</id>
		<title>1DOF Haptic</title>
		<link rel="alternate" type="text/html" href="https://wiki.robolabo.etsit.upm.es/index.php?title=1DOF_Haptic&amp;diff=578"/>
				<updated>2018-07-23T17:14:34Z</updated>
		
		<summary type="html">&lt;p&gt;Blancal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Note: &amp;lt;/b&amp;gt; The electronics of the robot are based on a Arduino Due board: https://www.arduino.cc/en/Main/ArduinoBoardDue&lt;br /&gt;
Moreover, the motor control is done through a H-Bridge board from ST: http://www.st.com/en/ecosystems/x-nucleo-ihm04a1.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Configuring the environment  &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PEPEPSPSPS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Setting up the Arduino Software &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Download the Arduino IDE 1.6.x according to your operating system from: https://www.arduino.cc/en/Main/Software . &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Install the Arduino IDE &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If you have chosen to download the installer, run the installer and install the software in a path of your convenience. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If you have chosen to download the sources (Linux or zip on Windows), uncompress the software in a path of your convenience &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open/run Arduino IDE, so it will create all the folders needed&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Installing Tools and Libraries &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The 1DOF haptic robot uses a Arduino DUE board, so the Arduino IDE support must be installed. Open Boards configurator: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tools &amp;amp;rarr; Boards &amp;amp;rarr; Boards' Manager&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Install support for SAM Boards - (32-bits ARM Cortex-M3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Download the DueTimer.zip library from: https://github.com/ivanseidel/DueTimer/releases &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Install the library: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Program &amp;amp;rarr; Include library &amp;amp;rarr; Add Zip library&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Select the zip file that has been downloaded &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Installing FTDI drivers &amp;lt;/h3&amp;gt;&lt;br /&gt;
If you are using Linux or Mac, skip this step.&lt;br /&gt;
If you are using Windows, power up the robot and connect it to your computer.&lt;br /&gt;
Windows should ask you to install some FTDI drivers to be able to connect to the robot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Hello World example  &amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have created a helloWorld example to test the communication with the robot.&lt;br /&gt;
Please download it from [[media:1DOFHAP-HelloWorldMotor.tgz | here ]] in your prefered destination.&lt;br /&gt;
Untar the file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tar -xvzf helloWorld.tgz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Compiling the code &amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open Arduino IDE and load the .ino file in your environment: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File &amp;amp;rarr; Open &amp;amp;rarr; &amp;lt;HELLOWORLD_EXAMPLE&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Select the Arduino DUE board: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tools &amp;amp;rarr; Board &amp;amp;rarr; Arduino Due&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Compile the program: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Program &amp;amp;rarr; Verify/Compile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Downloading the code to the robot &amp;lt;/h2&amp;gt;&lt;br /&gt;
The Arduino Due has two usb ports. The one that is closer to the power jack is the programming port and the one used with the 1DOF Haptic Robot.&lt;br /&gt;
&lt;br /&gt;
Select the correct port to download the binaries:&lt;br /&gt;
In Linux, typically:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tools &amp;amp;rarr; Port &amp;amp;rarr; /dev/ttyUSBX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Windows, typically:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tools &amp;amp;rarr; Port &amp;amp;rarr; COMX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where X depends on your system and the number of peripherals on it&lt;br /&gt;
&lt;br /&gt;
Upload your code to the board:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Program &amp;amp;rarr; Upload&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The IDE will notify that it is &amp;lt;i&amp;gt; uploading &amp;lt;/i&amp;gt; and after some seconds it will say &amp;lt;i&amp;gt; uploaded &amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Playing with HelloWorld &amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example allows you to see the functionality of some of the functions handcoded.&lt;br /&gt;
Once the software has been loaded, the robot should move 1 second  counterclockwise and 1 second clockwise.&lt;br /&gt;
After those 2 seconds it should stop.&lt;br /&gt;
&lt;br /&gt;
Once the code have been loaded, you can open the serial port:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tools &amp;amp;rarr; Serial Monitor&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see in real time the information provided by the helloworld example, basically:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Count: The communication time, in timer ticks&lt;br /&gt;
&amp;lt;li&amp;gt; Pos: The position, in encoder pulses units&lt;br /&gt;
&amp;lt;li&amp;gt; Vel: The speed, in encoder pulses units&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt; Practice 2 Template (P2)&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the implementation of Practice 2 of the &amp;quot;Control and Robotics in Medicine&amp;quot; subject of the &amp;quot;Master on Bioengineering&amp;quot;  of the UPM, we have created a students template.&lt;br /&gt;
You can download the template from [[media:1DOFHAP-P2Template.tgz | here ]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Structure &amp;lt;/h2&amp;gt; &lt;br /&gt;
The template has 5 different block of files:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; encoder.{c,h} &amp;lt;/b&amp;gt;: where functions related to the measurement of the encoder are developed.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; motor.{c,h} &amp;lt;/b&amp;gt;: where functions related to the movement of the motor are developed.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; comm.{c,h} &amp;lt;/b&amp;gt;: where functions related to the serial port communication are developed.&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; controller.{c,h} &amp;lt;/b&amp;gt;: where specific controllers could be developed. &amp;lt;b&amp;gt; It will not be used on P2 &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; P2-Template.ino &amp;lt;/b&amp;gt;: The place where the practice should be developed.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Methods &amp;lt;/h2&amp;gt;&lt;br /&gt;
This Section provides important information for the resolution of Practice2.&lt;br /&gt;
It is based on the explanation of different methods to control the robot, but it does not explain the complete set of methods.&lt;br /&gt;
To get and exahustive description of all methods all fies must be studied.&lt;br /&gt;
&lt;br /&gt;
Given some restrictions to the Arduino software structure, some function prototypes are defined in the main file.&lt;br /&gt;
However, sections related to the header files refer to its implementation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Encoder &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This library is in charge of calculating the movement of the motor related to the encoder.&lt;br /&gt;
The functions to control the encoder are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void ENCODER_Init (void) &amp;lt;/b&amp;gt;: It configures the pinout of the encoder and launches the interrupts related to channel A and B. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void ENCODER_Init (void)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures the pinout of the encoder and launches the interrupts related to channel A and B.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void ENCODER_StartSpeedCalculation  ( long l_sampling_time ) &amp;lt;/b&amp;gt;: It configures a timer in charge of calculating the speed average of the motor.  &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void ENCODER_StartSpeedCalculation  ( long l_sampling_time )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures a timer in charge of calculating the speed average of the motor.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long l_sampling_time &amp;lt;/b&amp;gt;: It defines the sampling period in milliseconds.&lt;br /&gt;
&amp;lt;/ul&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long ENCODER_GetCount ( void ) &amp;lt;/b&amp;gt;: It returns the actual count of the encoder, that is, the position of the motor related to its initial condition. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
long ENCODER_GetCount ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It returns the actual count of the encoder, that is, the position of the motor related to its initial condition.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; return &amp;lt;/b&amp;gt;: It returns a long value related to the pulses of the encoder, positive or negative, related to the initial position of the encoder. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long ENCODER_GetCountInSpeedInterval ( void) &amp;lt;/b&amp;gt;: It returns an averge speed, expressed in counts per second. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
long ENCODER_GetCountInSpeedInterval ( void)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It returns an averge speed, expressed in counts per second. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; return &amp;lt;/b&amp;gt;: It returns a long value related to the pulses per second of the encoder, positive or negative.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; IMPORTANT: The encoder available on Practice 2, is a 48 quadrature Counts Per Revolution (CPR) encoder.&lt;br /&gt;
This means that &amp;lt;i&amp;gt; ENCODER_GetCount (void) &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; ENCODER_GetCountInSpeedInterval (void) &amp;lt;/i&amp;gt; functions return a value related to the encoder counts.&lt;br /&gt;
That means that for every turn on the motor axis, there are 48 values (1 pulse every 7.5 degrees). &lt;br /&gt;
This value must be multiplied by the reduction ratio of the motor to check the position outside the motor axis. &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Motor &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This library is in charge of moving the motor. &lt;br /&gt;
The motor is moved based on a PWM which is executed at a sampling period.&lt;br /&gt;
&lt;br /&gt;
The functions to control the motor are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void MOTOR_Init ( void ) &amp;lt;/b&amp;gt;: It configures the pinout of the H-bridge to control the motor and inits the PWM peripheral to control it. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MOTOR_Init ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures the pinout of the H-bridge to control the motor and inits the PWM peripheral to control it.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void MOTOR_SetVoltage ( float f_voltage ) &amp;lt;/b&amp;gt;: It sets up a voltage to be sent to the motor. Remember the motor is controlled through a PWM, so it really sets up a PWM to controlthe H-Bridge. --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MOTOR_SetVoltage ( float f_voltage )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It sets up a voltage to be sent to the motor. Remember the motor is controlled through a PWM, so it really sets up a PWM to controlthe H-Bridge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; flot f_voltage &amp;lt;/b&amp;gt;: This is the value of the voltage to be applied to the motor. It can be positive or negative, and the function limits the maximum and minimum values according to the &amp;lt;i&amp;gt; MOTOR_MAX_VOLTAGE &amp;lt;/i&amp;gt; variable defined in &amp;lt;i&amp;gt; motor.h &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Communication &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This library is in charge of managing periodic communications through the serial port.&lt;br /&gt;
The functions are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_Init ( int speed );  &amp;lt;/b&amp;gt;: It configures the serial port at a specific speed. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_Init ( int speed );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It configures the serial port at a specific speed.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; int speed &amp;lt;/b&amp;gt;: The speed, in bauds, to configure and open the serial port. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_Start ( long l_sampling_time ) &amp;lt;/b&amp;gt;: It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt; &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_Start ( long l_sampling_time )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long l_sampling_time &amp;lt;/b&amp;gt;: It defines the sampling period in milliseconds.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_Stop ( void ) &amp;lt;/b&amp;gt;: It stops the timer in charge of calling &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt;, so communication stops. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_Stop ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It stops the timer in charge of calling &amp;lt;i&amp;gt; COMMUNICATION_ROB &amp;lt;/i&amp;gt;, so communication stops.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Controller &amp;lt;/h3&amp;gt;&lt;br /&gt;
This library is in charge of managing a periodic timer to implement the controller developed.&lt;br /&gt;
The functions are defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void CONTROLLER_Start ( long l_sampling_time ) &amp;lt;/b&amp;gt;: It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; CONTROLLER_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt;&amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void CONTROLLER_Start ( long l_sampling_time )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It starts a timer to handle periodically the communications. This timer calls the &amp;lt;i&amp;gt; CONTROLLER_ROB &amp;lt;/i&amp;gt; function at &amp;lt;i&amp;gt; l_sampling_time &amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; long l_sampling_time &amp;lt;/b&amp;gt;: It defines the sampling period in milliseconds.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; P2-Template.ino &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void COMMUNICATION_ROB ( void ) &amp;lt;/b&amp;gt;: In this function you should implement which is the information you want to send through the serial port, to obtain specific data and plot some graphs. &amp;lt;/li&amp;gt; --&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void COMMUNICATION_ROB ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This function should implement which is the information you want to send through the serial port, to obtain specific data and plot some graphs.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;li&amp;gt; &amp;lt;b&amp;gt; void CONTROLLER_ROB ( void )&amp;lt;/b&amp;gt;: In this function you should implement your controllers. &amp;lt;/li&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void CONTROLLER_ROB ( void )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This function should implement the controllers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Important &amp;lt;/b&amp;gt;: It is important that the helloworld and template files are studied before starting Practice 2.&lt;br /&gt;
Moreover, it is recommended that before arriving to the laboratory, two functions to convert encoder counts to position (in radians) and speed (in radians/second) are already programmed, to save time and get a basic understanding of the robot electronics.&lt;/div&gt;</summary>
		<author><name>Blancal</name></author>	</entry>

	</feed>