Pages

Monday, September 30, 2013

A simple brushless sensorless motor driver for AVR Atmega

Brushless electric motor (BLDC motors) are synchronous motors that are powered by a DC electric source via an integrated inverter/switching power supply, which produces an AC electric signal to drive the motor.



For an introduction to BLDC motors, please look at my sensored motor driver post, here: http://davidegironi.blogspot.it/2013/09/a-simple-brushless-sensored-motor.html


For this project, I've implemented a simple brushless sensoreless motor driver for AVR Atmega. The code i propose it's not perfect, and can be improved, but for the needs i had it works.

The motor can be controlled in speed and direction (clockwise and anti-clockwise).

This project use open loop startup and bemf zero crossing detection method with ADC.
Speed change can be done only when motor is not running, ADC is used during spinning phase in zc detection so it can not be used during the motor spinning, but digital speed changing can be implemented.
ZC threshold current should be defined by user depending on the motor type.

User has to setup the port used to read the the bemf current. Also the timer interrupt and prescaler should be setup for different running frequency.
The running step for the motor are defined as default, anyway user can change it to fit any motor.


A sample main routine is provided to help you understand how the library works.

The same test board of sensored library post is used, reported here the schamatics, for further info look at the sensored library post.

Setup parameters are contained in bldcsensorless.h

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz.

Code
Notes
  • read risk disclaimer
  • excuse my bad english

Sunday, September 15, 2013

A simple brushless sensored motor driver for AVR Atmega



Brushless electric motor (BLDC motors) are synchronous motors that are powered by a DC electric source via an integrated inverter/switching power supply, which produces an AC electric signal to drive the motor. Additional electronics control the inverter output amplitude and waveform (and therefore percent of DC bus usage/efficiency) and frequency (i.e. rotor speed). Because the controller must direct the rotor rotation, the controller requires some means of determining the rotor's orientation/position (relative to the stator coils). Some designs use Hall effect sensors or a rotary encoder to directly measure the rotor's position, others measure the back EMF in the undriven coils to infer the rotor position, eliminating the need for separate Hall effect sensors, and therefore are often called sensorless controllers.


The following explanation is taken from "AVR443: Sensor-based control of three phase Brushless DC motor" sheet.
Theory of operation: A three phase BLDC consists of a Stator with a number of coils. The fundamental three phase BLDC motor has three coils. Usually the three coils are referred to as U, V and W. In many motors the fundamental number of coils are replicated to have smaller rotation steps and smaller torque ripple. The rotor in a BLDC motor consists of an even number of permanent magnets. To simplify the explanation of how to operate a three-phase BLDC motor a fundamental BLDC with only three coils is considered. To make the motor rotate the coils are energized (or “activated”) in a predefined sequence, making the motor turn in one direction, say clockwise. Running the sequence in reverse order the motor run in the opposite direction. The direction of the current determines the orientation of the magnetic field generated by the coil. The magnetic field attracts and rejects the permanent magnets of the rotor. By changing the current flow in the coils and thereby the polarity of the magnetic fields at the right moment – and in the right sequence – the motor rotates. Alternation of the current flow through the coils to make the rotor turn is referred to as commutation. A three-phase BLDC motor has six states of commutation. When all six states in the commutation sequence have been performed the sequence is repeated to continue the rotation. The sequence represents a full electrical rotation. For motors with multiple poles the electrical rotation does not correspond to a mechanical rotation. A four-pole BLDC motor uses two electrical rotation cycles to per mechanical rotation. When specifying the number of Rotations Per Minute subsequently, the number of electrical rotations is referred to unless otherwise mentioned. The most elementary commutation driving method used for BLDC motors is an on-off scheme: A coil is either conducting (in one or the other direction) or not conducting. The strength of the magnetic field determines the torque and speed of the motor. For BLDC motors the commutation control is handled by electronics. The simplest way to control the commutation is to commutate according the outputs from a set of position sensors inside the motor. Usually Hall sensors are used, but even back EMF can be used to detect the stator position. A common commutation is the one represented by the image below.


For this project, I've implemented a simple brushless sensored motor driver for AVR Atmega. The code i propose it's not perfect, and can be improved, but for the needs i had it works.

Using this library, the motor can be controlled in speed and direction (clockwise and anti-clockwise).
The running step for the motor are defined as default, anyway user can change it to fit any motor. Below you can find the commutation sequence (for clockwise and anti-clockwise rotation) i've used:


User has to setup the port used to read the hall sensor, and the port to control the FET status. Also the timer interrupt and prescaler should be setup for different running frequency.

A sample main routine is provided to help you understand how the library works.

To test this project i've used a brushless motor taken from a cd-rom, it is connected to a LM339 voltage compartor to build an encloder. You can find connection circuit below.



The power drive stage for the brushless motor is build using IRF640 mosfet and IR2101 high and low side driver. The complete schematics below:


Note that even a back EMF wiring are present there, if you just want to use hall sensor you can skip those connections. Also an external crystal is connected just to test the circuit at 16Mhz, even if tests are done at 8Mhz.

Setup parameters are contained in bldcsensored.h

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz.

Code
Notes
  • read risk disclaimer
  • excuse my bad english

Monday, September 2, 2013

AVR Atmega dehumidifier controller board, update

This project is an update to the previous dehumidifier based you can here: http://davidegironi.blogspot.it/2013/04/avr-atmega-dehumidifier-controller.html
This update adds some usefull functions.


The main issue that i've fixed is the microcontroller crash, that happens sometimes. I've noticed that sometimes the controller stop running, crash or doesn't works as expected.
After some experimets, i've noticed that probem was due to Electromagnetic Interference (EMI), EMI happens when the compressor and fan starts or stops.
I've solved this issues by:
  • insulating relays with metal tape
  • outdistance relays from the microcontroller
If you look at the image below you can see that relays are not distant from the microcontroller.


To build a more secure controller, i've added a watchdog control to reset the microcontroller if anything goes wrong.

Another improvement to the previous design is the additions of a minimum off/on time to prevent the compressor to be switched on and off in a short time. Some compressor may get broken if those timed function does not exists.

Finally i've switched the DHT11/22 sensor with an AMT1001 sensor. The AMT1001 sensor is less sensible to EMI, and it has analogic output.


Changelog
  • 1.0.9: added offset calibration for humidity/temperature sensor
  • 1.0.8: fix minimum on/off compressor time with antifrost temperature.
  • 1.0.6: DHT switched to AMT1001, add watchdog, add minimum on/off compressor time.
  • 1.0.4: DHT library update to prevent blocking.
  • 1.0.3:first release.




Code

Notes
  • read risk disclaimer
  • excuse my bad english