for a START button depression and release. The START
button code drops the firmware into ALIGN mode.
Here's the ALIGN mode entry code:
case ALIGNMODE:
mode = ALIGNMODE;
pwm_control(OFF);
disable_TMR5int;
TIMER5OFF;
TMR5H = 0x00;
TMR5L = 0x00;
PR5H = 0x13; //load TMR5 for 1ms
PR5L = 0x88;
voltage = 0; //PWM voltage = 0
delay = 0; //init align delay ctr
tenms_counter = 0; //10mS counter
LED2 = ON; //for us humans
OVDCOND = comm_sequence[5]; //set commutation
// state
comm_slice = 1; //tell TMR5 interrupt
// not to commutate
//enable the PWMs
//kick off TMR5 1ms
// intervals
//TMR5 ON
//set the operating mode
//disable the PWMs
//no interrupts for TMR5
//TMR5 OFF
//TMR5 counts up to PR5
pwm_control(ON);
enable_TMR5int;
TIMER5ON;
break;
The ALIGN mode operational code shares space with
the STOP, START, and RUN mode algorithms in the
mode_service function, which is called by the TMR5
interrupt handler. The ALIGNMODE case statements I just
revealed also share program memory area with the entry
code that supports the STOP, START, and RUN operational
service routines. Each entry mode routine prepares the
environment to execute the newly selected operational
mode that is about to go into service.
As you can see in the ALIGNMODE entry case
statements, TMR5 is shut down to allow it to be loaded
with a 1 ms period value. TMR5 is unique in that it counts
up towards a match with the PR5 register pair. Once the
TMR5 registers have incremented their way to the same
value as the PR5 registers, the TMR5 registers are reset to
zero, the TMR5 interrupt flag is set, and the upwards count
begins anew.
The alignment process ramps up the PWM voltage for
approximately 1 second and holds it there for about two
seconds. The idea is to supply just enough PWM voltage
to nudge the BLDC motor shaft into the desired electrical
position. In our case, the desired electrical position is 6.
The code to accomplish the nudge goes like this:
/ align time in 10ms increments
/ #define ALIGNMODE_LOOPS 255
//***********************************************
//* ALIGN MODE
//***********************************************
case ALIGNMODE:
//has 10mS passed?
if(++tenms_counter >= 10)
{
if(voltage <= 560) //ramp voltage to 50%+
{
voltage += 5; //inc 5 PWM counts/sec
//load new PWM values
PDC0H = make8(voltage,1);
50 SERVO 02.2009
PDC0L = make8(voltage,0);
PDC1H = make8(voltage,1);
PDC1L = make8(voltage,0);
PDC2H = make8(voltage,1);
PDC2L = make8(voltage,0);
}
else if (delay < ALIGNMODE_LOOPS)
//2 second align delay
{
++delay;
}
else
{
enter_mode(STARTMODE); //enter next state
}
tenms_counter = 0;
//clr the 10ms
//counter
}
break;
The 50% PWM voltage mark is represented by the
value 512 loaded in the PDCX duty cycle registers. You'll
find that the BLY171S-24V-4000 will not spin its shaft for
any PWM voltages that are specified as less than 512.
We want to be sure that the BLDC motor shaft locks into
the nearest selected electrical cycle position. So, we add
a boost factor to the 50% PWM value of 512. If you're
wondering how I came up with the PWM voltage value
of 560, it was by experimentation. I increased the PWM
voltage value until I could actually feel the motor shaft
move into the alignment position. Note also that I applied
a liberal fudge factor to the alignment delay value. After
feeling that little "thump" of the BLDC motor shaft, I let
out a big YEEE HAAAA!
Spinning Up
Here we go. The BLDC motor shaft is aligned at
electrical position 6 and START mode has been entered.
Like the ALIGN mode, the START mode is also preceded
by START mode entry code:
case STARTMODE:
mode = STARTMODE;
comm_slice = 0; //commutate on next TMR5
interrupt
LED2 = OFF; //exiting alignment routine
voltage = 0; //reset PWM voltage value
tmr5val = 0xA018; // 305 RPM value
//kill TMR5 and its interrupt
disable_TMR5int;
TIMER5OFF;
TMR5H = 0x00;
TMR5L = 0x00;
//init TMR5 up counter
//TMR5 counts up to PR5 value
PR5H = make8(tmr5val,1);
PR5L = make8(tmr5val,0);
//enable TMR5 and its interrupt
enable_TMR5int;
TIMER5ON;
break;
The tmr5val variable is derived from a basic BLDC
motor equation:
tmr5val = 60 / RPM Pole Pairs 6