Sie sind auf Seite 1von 4

Cd-Rom 3 phase Sensored BLDC Motor Arduino Controller Sensored Cd-Rom BLDC

Motor Hall Effect Sensors Three Phase BLDC Motor Bridge

By reading the Hall effect sensors, a 3-bit code can be obtained with values
ranging from 1 to 6. Each code value represents a sector on which the rotor is
presently located. Each code value, therefore, gives us information on which windings
need to be excited. Thus a simple lookup table can be used by the program to
determine which two specific windings to excite and, thus, turn the rotor.

Note that state ‘0’ and ‘7’ are invalid states for Hall effect sensors. Software should
check for these values and appropriately make all outputs equal to zero.
Change Notification Input:

Most of the microchip microcontrollers equipped with an interrupt called RB


port change interrupt which means that when at least one of the RB7:RB4 pins
changed state an interrupt will be occurred. This interrupt allows us to connect our
three wires which comes from hall sensors to pins RB4, RB5, and RB6 (RB7 is
connected to +Vcc).
BLDC motor controller circuit:

The complete circuit is shown in the following image:


There are two switches, one for start and the other for stop the motor. The
potentiometer is used to control the speed of the motor. The LED is on when the
system at on state. RB7 must be connected to +5V because we have RB port change
interrupt and we need only 3 inputs. For the three phase bridge and hall effect sensors
boxes are explained on the related topics above.

BLDC motor controller mikroC code:

We have three interrupts in our code:


1- External interrupt: RB0 connected to push button used to stop the motor,
2- RB port change interrupt: used to interrupt when the motor changes its position,
3- Timer1 interrupt: interrupts every 100ms to read the analog value on AN0 and
generate its corresponding pwm signal.

The code

unsigned short hall;


unsigned char MoveTable[8] = {0, 33, 6, 36, 24, 9, 18, 0};
unsigned dt, dt0;
void Interrupt(){
if(INTF_bit){ //External Interrupt occurred
INTCON = 0; //Disable all interrupts
PORTB.F2 = 0;
PORTD = 0;
PWM1_Stop();
}
if (TMR1IF_bit){ //Timer1 Interrupt occurred
TMR1IF_bit = 0;
TMR1H = 0x6D;
TMR1L = 0x84;
dt = ADC_Read(0); //Read analog value
if (dt != dt0) {
dt0 = dt;
dt0 = dt0 >> 2;
PWM1_Set_Duty(dt0);
PWM1_Start(); }
}
if (RBIF_bit){ //Pin change Interrupt occurred
RBIF_bit = 0;
hall = PORTB;
hall = hall & 112;
hall = hall >> 4;
PORTD = MoveTable[hall];
}
}
void InitInterrupts(){
OPTION_REG = 0;
T1CON = 0x31;
TMR1IF_bit = 0;
TMR1H = 0x6D;
TMR1L = 0x84;
TMR1IE_bit = 1;
INTCON = 0; //Disable all interrupts
}
void main() {
ADCON1 = 14; // Configure AN0 as analog
CMCON = 7; //Disable comparators
PORTB = 0;
TRISB = 243;
PORTD = 0;
TRISD = 0;
InitInterrupts();
PWM1_Init(10000);

while(1){
while(PORTB.F1); //wait for start key hit
while(!PORTB.F1); // wait till key is released
PORTB.F2 = 1;
hall = PORTB;
hall = hall & 112;
hall = hall >> 4;
PORTD = MoveTable[hall];
INTCON = 0xD8; //Enable all interrupts
PWM1_Start();
}
}

Das könnte Ihnen auch gefallen