4.2 The revised Program Flow
4.2.1 My previous plan is running on FreeRTOS, which is fit for time-critical tasks and more concise in programming.
Of course, application of interruption can do same job but if I have enough resource, I still would like to use real-time OS control. Now, My Flow Chart is as follows,
4.2.2 The function allocation of port A
There are two pins to be used in this design, one for up direction and the other for down direction sensing. I have selected four I2C channels FDC2114 as capacitive distance sensor as control source. Before the PCB is delivered and components welded, I shall use two buttons to control the rotary direction of the PMSM motor.
In this case,
Pin PortA 12 and PortA 13 shall be used, which is in J1 conntection of FRDM-KV31, with number J1-3 and J1-12 respectively. The pin is defined to trigger IRQ on falling edge.
/* enable port for LEFT_Button J1-3 */
PORT_WR_PCR_MUX(PORTA, 12, 1); /* Set PORTA, port 12, MUX 1 - GPIO J1-3*/
PORT_WR_PCR_PE(PORTA, 12, TRUE); /* Pull-up resistor enabled */
PORT_WR_PCR_PS(PORTA, 12, TRUE); /* Pull-up resistor selected */
PORT_WR_PCR_PFE(PORTA, 12, TRUE); /* Enable passive filter */
PORT_WR_PCR_IRQC(PORTA, 12, 0xA); /* IRQ on falling edge */
/* enable port for RIGHT_Button J1-12 */
PORT_WR_PCR_MUX(PORTA, 13, 1); /* Set PORTA, port 13, MUX 1 - GPIO J1-12 */
PORT_WR_PCR_PE(PORTA, 13, TRUE); /* Pull-up resistor enabled */
PORT_WR_PCR_PS(PORTA, 13, TRUE); /* Pull-up resistor selected */
PORT_WR_PCR_PFE(PORTA, 13, TRUE); /* Enable passive filter */
PORT_WR_PCR_IRQC(PORTA, 13, 0xA); /* IRQ on falling edge */
4.2.3 Enable & setup interrupts
The following code enable the interrupts
/* Enable & setup interrupts */
NVIC_EnableIRQ(PORTA_IRQn); /* Enable Interrupt */
NVIC_SetPriority(PORTA_IRQn, 4); /* Set priority to interrupt */
, The number of PORTA_IRQn is 59, according to reference manual, 59 is for PortA IRQ, which means falling edge on J1-3 or J1-12 can trigger this interrupt.
4.2.4 The IRQ handler PORTA_IRQHandler(void) shall put function void DemoSpeedStimulator(void) into operation.
Therefore the definition of Port A-12 and Port A-13 can control the direction and degree of the motor.
ui32ButtonDirection is 1 for one direction and -1 for opposite direction. ui32ButtonDeltaSpeed is constant 500 for now, this shall be changed with the movement speed of arm sensed by FDC2114 distance sensor.
if(PORT_RD_PCR_ISF(PORTA, 12));
{
PORT_WR_PCR_ISF(PORTA, 12 , TRUE);
/* proceed only if pressing longer than timeout */
if(ui32ButtonFilter > 100)
{
ui32ButtonFilter = 0;
ui32ButtonDirection= 0;
ui32ButtonDeltaSpeed= 0;
mbM1SwitchAppOnOff = TRUE;
M1_SetAppSwitch(mbM1SwitchAppOnOff);
bDemoMode = TRUE;
ui32SpeedStimulatorCnt = 0;
RED_LED_OFF();
GREEN_LED_ON();
}
}
if(PORT_RD_PCR_ISF(PORTA, 13));
{
PORT_WR_PCR_ISF(PORTA, 13 , TRUE);
/* proceed only if pressing longer than timeout */
if(ui32ButtonFilter > 200)
{
ui32ButtonFilter = 0;
ui32ButtonDirection= 1;
ui32ButtonDeltaSpeed= 500;
mbM1SwitchAppOnOff = TRUE;
M1_SetAppSwitch(mbM1SwitchAppOnOff);
bDemoMode = TRUE;
4.2.5 The motor control is accomplished in void DemoSpeedStimulator(void) with the following codes,
if(bDemoMode)
{
M1_SetSpeed(ui32ButtonDirection*FRAC16(1000.0/M1_N_MAX+ui32ButtonDeltaSpeed));
}
4.2.6 Above is description of the pilot project for Elbow-motion-assistance-actuator.
It is obvious that, FRDM-KV31F + FRDM-MC-LVPMSM is idea platform for motor control development. It takes me quite a while to read codes and understand the main procedure for motor control and Freemaster UI. As for Kinetics Motor Suite API, motor control, fault detection, motor protection, and user defined parameters are complete packages suitable for all kinds of motor application from home application as air-conditioner or industrial motor control.
With experience in electrical engineering and motor design, I can understand the how difficult it is to control motor in multi-operation conditions. This motor control library is more than a tools for me, it is a piece of delicate artwork. The principle of motor control can be used for motor with rated voltage of over 400 volt and power capacity of over 100kW. Furthermore, this development platform can work as invertor with front-end AC/DC rectifier.