Designing a MCU-driven permanent magnet BLDC motor controller: Part 3
Once the central timer is started, the pre-scaler adjustments are limited to one count (either up or down). This puts some limitation on the RAMP table. RAMP table pre-scale values cannot change more than one count between table entries.
The actual step time is calculated based on the peripheral clock speed, the pre-scale value, and the time value to be loaded into the commutation timer. The example used assumes a 4MHz peripheral clock.
The step pre-scaler (ratio setting) is set to 6. This provides a time-base of 32 microsecond/count with the timer ((26+1)/4MHz). The first time value of the ramp table is 150. This calculates to a first step time of 4.8ms (150 x 32 microseconds).
The ramp table uses a constant pre-scale value to make the step time calculations easier. The pre-scaler value may need to be changed (usually deccremented) if the motor needs to be stepped faster, requiring a finer time scale.
The ramp table in the example has an exponentially faster progressing step times. The "shape" of the ramp table may either be linear, exponential, or something in between. Some experimentation may be necessary to determine what table shape works best for the target motor.
During the switched mode, the PHASE and RAMP tables are independently stepped through. The Commutation timer is loaded with the step time from the RAMP table and determines if the pre-scaler needs to be adjusted from the pre-scaler values of the same table. The Demagnetization timer is loaded every time a C-event occurs with one-fourth of the commutation time.
Since the RAMP and PHASE tables are of differing sizes, each table is individually tracked. The PHASE table is looped as the phases driven in a repeating pattern. The RAMP table is stepped through until a reliable BEMF is detected.
If the end of the RAMP table is reached and suitable BEMF has not been detected, then a serious error has occurred. Typically, BEMF is detectable within 3-5 steps of the RAMP.
During the first four steps of the RAMP table, any BEMF detections are ignored. This is to prevent spurious BEMF zero crossing events from being counted. After the fourth step of the RAMP, the zero crossing interrupts are enabled.
The number of zero crossing events to be ignored is based on the motor driven, some experimentation may be necessary - just as some motors will require more speed to obtain a reliable zero crossing point than others.
Therefore, the RAMP table step time, acceleration rate, and the number of ignored zero crossings will need to be optimized for a given motor.
The interrupt routine:
@interrupt void MTC_R_Z_IT(void)
manages the Zero Crossing Event.
During the switched mode of operation the Z-event interrupt routine counts the number of zero crossings detected and the C-event interrupt also checks for a Z-event for every C-event.
If the Z-events are not consecutive, the C-event interrupt clears the zero crossing counter and the entire process begins again. Once 12 consecutive zero crossings have been detected, the process of changing to the auto-switch mode begins.
The optimum number of zero crossings before the running motor is
stable and is ready for auto-switched mode will depend upon the target
motor.


Loading comments... Write a comment