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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Documents Codewarrior Tutorial for FRDM-KL25Z & ARDUINO : Motor Shield with the Freescale Freedom Board
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: FreescaleTools_and_Software
  • Date Created: 7 Jan 2013 4:06 PM Date Created
  • Last Updated Last Updated: 8 Oct 2021 5:23 AM
  • Views 1188 views
  • Likes 0 likes
  • Comments 0 comments
Related
Recommended

Codewarrior Tutorial for FRDM-KL25Z & ARDUINO : Motor Shield with the Freescale Freedom Board

This tutorial was extracted from Erich Styger blog http://mcuoneclipse.wordpress.com with his agreement.

 

image image

  

The great thing with the Freedom FRDM-KL25Z board is its compatibility with Arduino Shields: a great set of board available at very reasonable prices. I had my hands on the Adafruit Data Logger shield, and now it was time to use the original Arduino Motor Shield R3.

 

image

Freedom FRDM-KL25Z with Arduino Motor Shield and Arexx Chassis

 

 

 

I already had an Arexx Robo Chassis available: a simple platform with two DC motors. So I added the FRDM-KL25Z with the Arduino Motor Shield R3 on top of it:

 

image

Top View with Arduino Motor Shield on top of Freedom board and motor chassis

 

 

Power Supply

 

The battery pack (4 AAA NiMH rechargeable batteries) provide 5V to the motor shield. That 5V is powering the FRDM-KL25Z through trace on the Motor Shield. There is an outstanding issue: the Motor Shield expects that the CPU board provides both 3.3V and 5V. 3.3V is provided, but the FRDM-KL25Z only provides 5V is either the KL25Z or the K20 is USB powered. So for now I need to power the system as well with a USB cable until I find a different solution.

 

 

Current Sensing

  

The shield provides two analog pins for motor current sensing. According to the documentation 3.3V should be full-scale for 2A. However, I’m measuring around 60 mV even with no current. It is not clear to me from the shield schematics if the analog signal depens on the AREF signal or not: the problem could be because the Freedom board does *not* route that signal to the header without hardware modification. So not sure where I am now with this, as I’m measuring the wrong values.

 

 

Console/Shell Interface

 

To manually control the motor, I have added a simple shell interface:

  

image

Shell Interface

 

 

That way I can manually control the motors and get status information:

  

image

Shell Motor Commands and Status

 

 

Processor Expert

 

The CodeWarrior for MCU10.3 project is using Processor Expert components to abstract from the hardware, and runs FreeRTOS:

 

image

Arduino Motor Processor Expert Components

  

  

Motor Driver

 

The motor driver functionality is in Motor.c and Motor.h. The interface is as below:

 

01 /*

02 * Motor.h

03 *

04 * Author: Erich Styger

05 */

06 

07 #ifndef MOTOR_H_

08 #define MOTOR_H_

09 

10 #include "PE_Types.h"

11 #include "FSSH1.h"

12 

13 typedef enum {

14 MOT_DIR_FORWARD, /*!< Motor forward direction */

15 MOT_DIR_BACKWARD /*!< Motor backward direction */

16 } MOT_Direction;

17 

18 typedef int8_t MOT_SpeedPercent; /* -100%...+100%, where negative is backward */

19 

20 typedef struct MOT_MotorDevice_ {

21 bool brake; /* if brake is enabled or not */

22 MOT_SpeedPercent currSpeedPercent; /* our current speed in %, negative percent means backward */

23 uint16_t currPWMvalue; /* current PWM value used */

24 LDD_TError (*SetRatio16)(LDD_TDeviceData*, uint16_t);

25 LDD_TDeviceData *PWMdeviceData; /* LDD device handle for PWM */

26 void (*DirPutVal)(LDD_TDeviceData *, bool); /* function to set direction bit */

27 LDD_TDeviceData *DIRdeviceData; /* LDD device handle for direction */

28 void (*BrakePutVal)(LDD_TDeviceData *, bool); /* function to enable/disable brake */

29 LDD_TDeviceData *BRAKEdeviceData; /* LDD device handle for brake pin */

30 uint16_t currentValue; /* current AD current sensor value */

31 uint16_t offset; /* current AD sensor offset value */

32 LDD_TDeviceData *SNSdeviceData; /* LDD current AD device handle */

33 } MOT_MotorDevice;

34 

35 /*!

36 * \brief Sets the PWM value for the motor.

37 * \param[in] motor Motor handle

38 * \param[in] val New PWM value.

39 */

40 void MOT_SetVal(MOT_MotorDevice *motor, uint16_t val);

41 

42 /*!

43 * \brief Return the current PWM value of the motor.

44 * \param[in] motor Motor handle

45 * \return Current PWM value.

46 */

47 uint16_t MOT_GetVal(MOT_MotorDevice *motor);

48 

49 /*!

50 * \brief Change the direction of the motor

51 * \param[in] motor Motor handle

52 * \param[in] dir Direction to be used

53 */

54 void MOT_SetDirection(MOT_MotorDevice *motor, MOT_Direction dir);

55 

56 /*!

57 * \brief Returns the direction of the motor

58 * \param[in] motor Motor handle

59 * \return Current direction of the motor

60 */

61 MOT_Direction MOT_GetDirection(MOT_MotorDevice *motor);

62 

63 /*!

64 * \brief Shell command line parser.

65 * \param[in] cmd Pointer to command string

66 * \param[out] handled If command is handled by the parser

67 * \param[in] io Std I/O handler of shell

68 */

69 uint8_t MOT_ParseCommand(const unsigned char *cmd, bool *handled, const FSSH1_StdIOType *io);

70 

71 /*!

72 * \brief Initialization function.

73 */

74 void MOT_Init(void);

75 

76 #endif /* MOTOR_H_ */

 

 

Summary

 

It was very easy to use the Motor Shield with the help of CodeWarrior for MCU10.3 and Processor Expert. The basic functionality with the exception of current sensing works and with the shell interface it is easy to explore and add further functionality. I still have an ultrasonic sensor to integrate :-) .

 

The CodeWarrior project and sources are available from this link.

 

Happy Motoring :-)

  • tutorial
  • avr
  • microchip
  • freescale
  • robots
  • control
  • kinetis
  • robot
  • arduino_tutorials
  • frdm-kl25z
  • stm32
  • arduino_tutorial
  • kinetis-l
  • st
  • motor
  • arduino
  • freedom
  • pic
  • atmel
  • Share
  • History
  • More
  • Cancel
  • 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 © 2026 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