create account

Controlling a brushless motor with 3 Mosfets EN/ES. by electronico

View this thread on: hive.blogpeakd.comecency.com
· @electronico · (edited)
$8.67
Controlling a brushless motor with 3 Mosfets EN/ES.
<div class=text-justify>

Now that we've looked at some [brushless motor theory](https://ecency.com/hive-196387/@electronico/brushless-motors-theoretical-basis-en) and established some [safety considerations](https://ecency.com/hive-196387/@electronico/brushless-motor-with-half-bridge) we're ready for our first real test with a brushless motor.
***
>Ahora que vimos un poco de [teor铆a sobre motores brushless](https://ecency.com/hive-196387/@electronico/brushless-motors-theoretical-basis-en) y establecimos algunas [consideraciones de seguridad](https://ecency.com/hive-196387/@electronico/brushless-motor-with-half-bridge) estamos listos para nuestra primera prueba real con un motor brushless.
***
<center> ![](https://images.ecency.com/DQmVfaaq3zctErq6p3CUWzgAtBzxeDw6jTnLNjHktWhu922/image.png) </center>

One of the features that makes a brushless motor stand out is its ability to work at several tens of thousands of RPMs, that speed makes them a favorite in drone construction, when used in computer disk drives however the speed is tried to be kept at 7200 RPMs in most cases.

Now let's consider their use in cars or electric bikes, I wouldn't want to be on an electric bike whose wheel spins at 7200RPMs or more 馃ぃ.

The complexity is not only in producing the spin, but also in controlling the speed of the spin. In today's practice we will set up an open loop circuit that only requires 3 mosfets and a microcontroller to set up control for illustrative purposes.

To do this I have taken one that is attached to the casing of a storage unit (recycled and dusty) popularly known as hard disk, since the electronic card that controls this motor has been removed by default we will connect the 4 wires (3 coils plus common) to take them to our control circuit.
***
>Una de las caracter铆sticas que hace resaltar un motor brushless es su capacidad para trabajar a varias decenas de miles de RPMs, esa velocidad hace que sean los favoritos en la construcci贸n de drones, cuando se usan en unidades de discos para ordenadores sin embargo la velocidad se intenta mantener en 7200 RPMs en la mayor铆a de los casos.

>Ahora consideremos su uso en coches o bicicletas el茅ctricas, no quisiera estar sobre una bicicleta el茅ctrica cuya rueda gire a 7200RPMs o m谩s 馃ぃ.

>La complejidad no solo est谩 en producir el giro sino, adem谩s, en controlar la velocidad del mismo. En la pr谩ctica de hoy estableceremos un circuito de bucle abierto que solo requiere de 3 mosfets y un microcontrolador para establecer un control con fines ilustrativos.

>Para ello he sacado uno que va pegado a la carcaza de una unidad de almacenamiento (reciclada y polvorienta) conocida popularmente como Disco Duro, ya que se ha retirado la tarjeta electr贸nica que controla este motor por defecto conectaremos los 4 cables (3 bobinas m谩s com煤n) para llevarlos a nuestro circuito de control.
***
<center> ![](https://images.ecency.com/DQmc7YVrc2jkzqm1m8rVgxDv1AepiMc56FXXum6ipdkeYzR/20240108_183825.jpg) </center>

We remove the ends of the cables connected at the front and in this way we can make the connections and observe the behavior of the motor in operation.
***
>Extraemos las puntas de los cables conectados por la parte delantera y de esa forma podremos hacer las conexiones y observar el comportamiento del motor en funcionamiento.
***
<center> ![](https://images.ecency.com/DQmYeoSttwnmMeJLDnHEQSxkcBkUXkZYZiVMRuf9uHJmfyZ/20240108_183835.jpg) </center>

To control this man we are going to use our PIC18F2550, with 3 mosfets accompanied by the protection components described above. 

With an ADC we will be able to adjust the switching times of the coils which should affect the speed of the motor.
***
>Para controlar a este se帽or vamos a usar nuestro PIC18F2550, con 3 mosfets acompa帽ados de los componentes de protecci贸n descritos anteriormente. 

>Con un ADC podremos ajustar los tiempos de conmutaci贸n de las bobinas lo cual deber铆a afectar la velocidad de giro del motor.
***
<center> ![](https://images.ecency.com/DQmQHbHb7pJQn6SD1n1MAJ9w8BkkhbrXgxanDccW9K1neUu/20240108_191223.jpg) </center> 

Finally we connect our motor to the breadboard as agreed in the circuit where the protection components are implemented.
***
>Finalmente conectamos nuestro motor a la protoboard seg煤n convenimos en el circuito donde se implementan los componentes de protecciones.
***
<center> https://images.ecency.com/p/2gsjgna1uruvGBHDnRaj2z6FsL6XEQR3pnqa26GnVd4M7vfxxpWsxcpCt8BcdiYBkmmBtwqEpZmJLg1FVDCS6G1dX86xWto3AoSUvTWLckB64EypvS.webp?format=webp&mode=fit </center>

The physical connection of all interconnected components to each other then takes on the following appearance:
***
>La conexi贸n f铆sica de todos los componentes interconectados entre s铆 toma entonces la siguiente apariencia:
***
<center> ![](https://images.ecency.com/DQmXJd1nMyCj2teXysG23Bs1zafWLg9WLssvuHr8ig1R93x/image.png) </center>

And with this we have completed all the physical part, now comes the exciting part, the one where we write in a code our desire about the behavior of the motor. Let's program it!

We must take into account a certain activation sequence because otherwise our motor will do anything but turn!

The correct sequence to the right if we consider the ABC coils in a logic where 1 is a value of activation and 0 of deactivation we have: 100 110 010 011 001 101.

If we want it to rotate in the opposite direction the sequence is: 101 001 011 010 110 100.

We will establish the first sequence with the following program for our PIC18F2550:
***
>Y con esto tenemos completada toda la parte f铆sica, ahora viene la parte emocionante, esa en la que escribimos en un c贸digo nuestro deseo sobre el comportamiento del motor. 隆Vamos a programarlo!

>Debemos tomar en cuenta cierta secuencia de activaci贸n porque de lo contrario 隆nuestro motor har谩 cualquier cosa menos girar.!

>La secuencia correcta hacia la derecha si consideramos las bobinas ABC en una l贸gica donde 1 es un valor de activaci贸n y 0 de desactivaci贸n tenemos: 100 110 010 011 001 101.

>Si queremos que gire en sentido contrario la secuencia es: 101 001 011 010 110 100.

>Estableceremos la primera secuencia con el siguiente programa para nuestro PIC18F2550:
***
~~~
#include <18f2550.h>
#device ADC = 10
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,CPUDIV1,NODEBUG,USBDIV,PLL5,VREGEN,NOPBADEN
#use delay(Clock=20000000)
#use standard_io(C)
#include <map_function.c

#define L1 PIN_C0                  
#define L2 PIN_C1
#define L3 PIN_C2
~~~

We have set L1, L2 and L3 as the ABC coils respectively. We will set a variable to capture the ADC value and another one to take the value of the time that each coil is active, remember that long times can damage the coil.
***
>Hemos establecido L1, L2 y L3 como las bobinas ABC respectivamente. Estableceremos una variable para capturar el valor del ADC y otra para llevar el valor del tiempo que dura activa cada bobina, recordemos que tiempos largos pueden da帽ar la bobina.
***
~~~
int16 adc;
int16 speed;
~~~

Then if we are going to use an ADC we configure it to play with the potentiometer, we will use the map function to adapt the ADC value to the time range that we will allow between each activation signal.
***
>Luego si vamos a usar un ADC lo configuramos para jugar con el potenci贸metro, usaremos la funci贸n map para adaptar el valor del ADC al rango de tiempo que permitiremos entre cada se帽al de activaci贸n.
***
~~~
void main()
{
   setup_adc_ports(AN0);                     
   setup_adc(adc_clock_internal);

   while(true)
   {
    set_adc_channel(0);
    delay_us(20);
    adc = read_adc();
    speed=map(adc, 0, 1023, 30000, 800);
~~~

Now we just write the activation sequence in the order described above, between each interval we include a delay whose value corresponds to the speed variable associated to the ADC values, thus determining the time between each change.
***
>Ahora solo escribimos la secuencia de activaci贸n en el orden descrito unos p谩rrafos arriba, entre cada intervalo incluimos un retardo cuyo valor se corresponde a la variable speed asociada a los valores del ADC, as铆 determinamos el tiempo entre cada cambio.
***
~~~
    
    output_low(L1); //0
    output_low(L2); //0
    output_low(L3); //0
    delay_us(speed);
    output_high(L1); //1
    output_low(L2);  //0
    output_low(L3); //0
    delay_us(speed);
    output_high(L1); //1
    output_high(L2); //1
    output_low(L3); //0
    delay_us(speed);
    output_low(L1); //0
    output_high(L2); //1
    output_low(L3); //0
    delay_us(speed);
    output_low(L1); //0
    output_high(L2); //1
    output_high(L3); //1
    delay_us(speed);
    output_low(L1); //0
    output_low(L2); //0
    output_high(L3); //1
    delay_us(speed);
    output_high(L1); //1
    output_low(L2); //0
    output_high(L3); //1
    delay_us(speed);
  }
}
~~~

With all this we can now see our contraption working with a simple circuit and a simple program, believe me, it won't always be so easy with this kind of motors 馃槑.
***
>Con todo esto ya podemos ver nuestro artilugio funcionando con un circuito sencillo y un programa sencillo, creeme, no siempre ser谩 tan f谩cil con este tipo de motores 馃槑.
***
<center> ![20240112_172454.gif](https://images.hive.blog/DQmT8qHdJyhE61PuPAQncCAfzzjD5M6MD6Pm3ueY7CB88SN/20240112_172454.gif) </center> 


<iframe width="315" height="560" src="https://www.youtube.com/embed/0M6hhwujZWU" title="20240109 195221" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

***
***
***
***
***
***
***
<center>https://images.ecency.com/p/3W72119s5BjW4PvRk9nXBzqrPWMsMTjNrXDPFFf12CAfRz5MY8jCm5vGDUj7o96hwAT3YCMBJgcTgcWmsqeuBbZL1YbmxtaV4gyfByenDkmAkgv6rkm9ZP.webp?format=webp&mode=fit</center>


<center>![](https://images.ecency.com/DQmcDEJsitAuNPBHeVWasdWpQzemRFJi6hzwpC3pz5moBTL/timestamp.gif)</center>

If you want to give an extra boost to the blog with a donation you can send it to the addresses:
***
>Si quieres darle un impulso extra al blog con una donaci贸n puedes enviarla a las direcciones:
***
BEP-20: 0x5Aee5e3e3ED3203e77eF0d8Bb3E3a420E5229Ce0
ERC-20: 0x5Aee5e3e3ED3203e77eF0d8Bb3E3a420E5229Ce0
Arbitrum One: 0x5Aee5e3e3ED3203e77eF0d8Bb3E3a420E5229Ce0
Polygon: 0x5Aee5e3e3ED3203e77eF0d8Bb3E3a420E5229Ce0
Avalanche: 0x5Aee5e3e3ED3203e77eF0d8Bb3E3a420E5229Ce0
</div>
馃憤  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 441 others
properties (23)
authorelectronico
permlinkcontrolling-a-brushless-motor-with
categoryhive-196387
json_metadata"{"app":"ecency/3.0.37-vision","description":"Now that we've looked at some [brushless motor theory](Brushless motors - Theoretical basis. EN/ES) and established some safety considerations we're ready for our first real test with a brushless motor.","format":"markdown+html","image":["https://images.hive.blog/DQmT8qHdJyhE61PuPAQncCAfzzjD5M6MD6Pm3ueY7CB88SN/20240112_172454.gif","https://images.ecency.com/DQmVfaaq3zctErq6p3CUWzgAtBzxeDw6jTnLNjHktWhu922/image.png","https://images.ecency.com/DQmc7YVrc2jkzqm1m8rVgxDv1AepiMc56FXXum6ipdkeYzR/20240108_183825.jpg","https://images.ecency.com/DQmYeoSttwnmMeJLDnHEQSxkcBkUXkZYZiVMRuf9uHJmfyZ/20240108_183835.jpg","https://images.ecency.com/DQmQHbHb7pJQn6SD1n1MAJ9w8BkkhbrXgxanDccW9K1neUu/20240108_191223.jpg","https://images.ecency.com/p/2gsjgna1uruvGBHDnRaj2z6FsL6XEQR3pnqa26GnVd4M7vfxxpWsxcpCt8BcdiYBkmmBtwqEpZmJLg1FVDCS6G1dX86xWto3AoSUvTWLckB64EypvS.webp?format=webp&mode=fit","https://images.ecency.com/DQmXJd1nMyCj2teXysG23Bs1zafWLg9WLssvuHr8ig1R93x/image.png","https://images.ecency.com/p/3W72119s5BjW4PvRk9nXBzqrPWMsMTjNrXDPFFf12CAfRz5MY8jCm5vGDUj7o96hwAT3YCMBJgcTgcWmsqeuBbZL1YbmxtaV4gyfByenDkmAkgv6rkm9ZP.webp?format=webp&mode=fit","https://images.ecency.com/DQmcDEJsitAuNPBHeVWasdWpQzemRFJi6hzwpC3pz5moBTL/timestamp.gif"],"image_ratios":["0.8478","0.7484","0.7500","0.7500","1.3333"],"tags":["hive-196387","ecency","ocd","waivio","leofiance","neoxian","education","technology","proofofbrain","electronica-ie"]}"
created2024-01-12 22:15:45
last_update2024-01-12 22:17:42
depth0
children6
last_payout2024-01-19 22:15:45
cashout_time1969-12-31 23:59:59
total_payout_value4.268 HBD
curator_payout_value4.405 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length10,349
author_reputation43,746,257,869,160
root_title"Controlling a brushless motor with 3 Mosfets EN/ES."
beneficiaries
0.
accountstemsocial
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,435,475
net_rshares19,458,898,750,934
author_curate_reward""
vote details (505)
@agileautomation ·
WOW, what an amazing tutorial, you've spend some time on this project obviously, nice job!  I do a lot of controls myself (and now post tips for python asI've done a lot of controls using python actually), very little with PIC processors though, but great little project, a lot to learn.  Following...
properties (22)
authoragileautomation
permlinkre-electronico-s79i6t
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2023.11.3"}
created2024-01-14 17:35:15
last_update2024-01-14 17:35:15
depth1
children0
last_payout2024-01-21 17:35:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length301
author_reputation55,848,601,723
root_title"Controlling a brushless motor with 3 Mosfets EN/ES."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,478,190
net_rshares0
@buckmiggatesla · (edited)
I should try this because I should have all of this stuff.... how do I add a throttle?
properties (22)
authorbuckmiggatesla
permlinkre-electronico-2024424t81858824z
categoryhive-196387
json_metadata{"type":"post","tags":["hive-196387","ecency","ocd","waivio","leofiance","neoxian","education","technology","proofofbrain","electronica-ie"],"app":"ecency/3.0.46-mobile","format":"markdown+html"}
created2024-04-24 13:19:00
last_update2024-04-24 13:19:12
depth1
children0
last_payout2024-05-01 13:19:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length86
author_reputation863,248,620
root_title"Controlling a brushless motor with 3 Mosfets EN/ES."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id133,083,373
net_rshares0
@clinton19 · (edited)
It would have been nice if you had actually constructed the motor from scratch or did you ?

I used to be a fan of these kind of DIY projects, especially the electromagnetic kinds in the past. There's this kind of joy I get when I build from scratch, including trying to introduce new ideas. Unfortunately, for some reasons I have not quite understood, I lost interest. 馃榿

Great post by the way. 馃憤
馃憤  ,
properties (23)
authorclinton19
permlinkre-electronico-2024113t23729266z
categoryhive-196387
json_metadata{"tags":["hive-196387","ecency","ocd","waivio","leofiance","neoxian","education","technology","proofofbrain","electronica-ie"],"app":"ecency/3.0.37-vision","format":"markdown+html"}
created2024-01-13 01:37:30
last_update2024-01-13 01:41:09
depth1
children1
last_payout2024-01-20 01:37:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length397
author_reputation79,544,135,733,220
root_title"Controlling a brushless motor with 3 Mosfets EN/ES."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,439,283
net_rshares111,023,463
author_curate_reward""
vote details (2)
@electronico ·
Sure, it would have been more exciting but it would have taken me more time than I usually have for these things. Anyway the main purpose I'm looking for is the understanding about electronic control systems, maybe in the future when I'm a little less loaded we'll build some engines from scratch....

When we abandon the practice we usually lose interest, in fact it is one of the reasons why I created the blog, I can share knowledge while staying active in the area.

Thanks my friend, it pleases me very much to read comments like yours in my articles.
馃憤  ,
properties (23)
authorelectronico
permlinkre-clinton19-2024112t22722728z
categoryhive-196387
json_metadata{"tags":["hive-196387","ecency","ocd","waivio","leofiance","neoxian","education","technology","proofofbrain","electronica-ie"],"app":"ecency/3.0.37-vision","format":"markdown+html"}
created2024-01-13 02:19:33
last_update2024-01-13 02:19:33
depth2
children0
last_payout2024-01-20 02:19:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length556
author_reputation43,746,257,869,160
root_title"Controlling a brushless motor with 3 Mosfets EN/ES."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,439,854
net_rshares110,830,234
author_curate_reward""
vote details (2)
@stemsocial ·
re-electronico-controlling-a-brushless-motor-with-20240113t172745843z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

Thanks for including @stemsocial as a beneficiary, which gives you stronger support.&nbsp;<br />&nbsp;<br />
</div>
馃憤  
properties (23)
authorstemsocial
permlinkre-electronico-controlling-a-brushless-motor-with-20240113t172745843z
categoryhive-196387
json_metadata{"app":"STEMsocial"}
created2024-01-13 17:27:45
last_update2024-01-13 17:27:45
depth1
children1
last_payout2024-01-20 17:27:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length545
author_reputation22,903,677,158,169
root_title"Controlling a brushless motor with 3 Mosfets EN/ES."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,453,617
net_rshares27,754,433,592
author_curate_reward""
vote details (1)
@electronico ·
![GIF by Australian Open](https://media2.giphy.com/media/sjkl9MJD57BWersvzJ/200.gif)
properties (22)
authorelectronico
permlinkre-stemsocial-2024114t9142839z
categoryhive-196387
json_metadata{"tags":["ecency"],"app":"ecency/3.0.37-vision","format":"markdown+html"}
created2024-01-14 13:26:21
last_update2024-01-14 13:26:21
depth2
children0
last_payout2024-01-21 13:26:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length84
author_reputation43,746,257,869,160
root_title"Controlling a brushless motor with 3 Mosfets EN/ES."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,472,691
net_rshares0