Baby-O PID interrupt control of brushless FAN

In this project I am using a baby-O to control the motor rpm of a brushless FAN motor.

The motor has 4 magnets and 4 coils, there is a HALL sensor which detects the position of the magnets, as soon as the HALL is interrupted we look into the direction of the field and decide to change the direction of the “motor”

I used the Pololu LV168 Demo3 example and the motor outputs to control 4 FET’s in a H-bridge. The avg routine where it sets the motor rpm was moved to the interrupt routine and the if where the motor direction is decided was modified to readout the value of PDD2 (INT0)
Appnote AVR 442 was very useful in setting up the FAN control with the Hall sensor
Appnote AVR 221 supplied me the needed PID controlling function

The FAN is running at 1700 rpm on 7,6V supply and reacting very well on PID settings for Kp, Ki and Kd.
In this example I have used the same number of coils as magnets so the motor does not start from itself. This increases the ability to change motor rpm a lot, in a normal motor spooling down can take some time, this one is very fast.
The next version will incorporate a Pololu motor driver, this setup was to prove the concept.

I have not quite understood the setting up of the pwm, when I need full throttle I have to set pwm to a maximum value of 511, in the comment it says /2 which is ok as w use an 8 bit timer, in the code I do not see the division. Can anyone explain me where this division takes place?

Original code in the demo3 software:
M1_FORWARD((511 - avg) >> 1); // M1 speed = (511 - avg) / 2
PID 4_8V fan.pdf (408 KB)


Can anyone explain me where this division takes place?
M1_FORWARD((511 - avg) >> 1);

The division takes place in the line of code that you quoted. In most cases “x>>1” is equivalent to “x/2”. The “>>” operator shifts all the bits in the number to the “right”, making the number smaller.

-David

Thanks, this will help to set up the motor driver with timer1.

Setting up the PID parameters for the AVR221 took a bit more time than expected. I started with just a Kp value and found out that after a couple of seconds the rpm suddenly dropped by 20%. At a higher frequency it took less time. Disconnecting the processor made the problem disappear, it reappeared again after the same number of seconds.

Then I introduced a Ki factor of 0.10 and the problem disappeared. I have not found it in the code but a value of 0 for the Ki is not allowed.