element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Make Life Accessible
  • Challenges & Projects
  • Design Challenges
  • Make Life Accessible
  • More
  • Cancel
Make Life Accessible
Blog Step Four:  4.2 Programming and Software Design
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 5 Jul 2016 5:02 AM Date Created
  • Views 413 views
  • Likes 1 like
  • Comments 0 comments
  • accessibility_projects
Related
Recommended

Step Four:  4.2 Programming and Software Design

fyaocn
fyaocn
5 Jul 2016

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.

image

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,

image

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.

image

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.

Attachments:
PMSM_Elbow.rar
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube