This tutorial was extracted from Erich Styger's blog http://mcuoneclipse.wordpress.com.
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.
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:
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:
That way I can manually control the motors and get status information:
Processor Expert
The CodeWarrior for MCU10.3 project is using Processor Expert components to abstract from the hardware, and runs FreeRTOS:
Motor Driver
The motor driver functionality is in Motor.c and Motor.h. The interface is as below:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/*
|
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.