Main Site Documentation

Stepper L6470 Module


#1

Anyone have example code or am I not finding something that’s already out there? It seems there are a lot of parameters to set up and reading through the driver source has left me in no better position.

Thanks if you can help!


#2

Here is a snippet of sample code. The parameters to the registers are set with default settings. If you require specific settings, the value of the registers will depend on the motor itself.

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
 
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
 
namespace Stepper_L6470_Example
{
    public partial class Program
    {
        const uint MAX_MOTOR_SPEED = 100000;
        const uint MOTOR_SPEED_INCREMENT = 1000;
        uint MOTOR_SPEED = 0;
        bool MOTOR_MOVING = false;
 
        /// <summary>
        /// Move the motor to a specific position
        /// </summary>
        /// <param name="location">How many steps to move</param>
        void GoTo(uint location)
        {
            stepper_L6470.GoToPosition(location);
        }
 
        /// <summary>
        /// Set the motor to the specified speed
        /// </summary>
        /// <param name="speed"></param>
        void SetSpeed(uint speed)
        {
            MOTOR_SPEED = speed;
 
            if (MOTOR_SPEED > MAX_MOTOR_SPEED)
                MOTOR_SPEED = MAX_MOTOR_SPEED;
 
            if (MOTOR_MOVING)
            {
                stepper_L6470.HardStop();
                stepper_L6470.Run(GTM.GHIElectronics.Stepper_L6470.Direction.FWD, MOTOR_SPEED);
            }
        }
 
        void GetStatus()
        {
            ushort mask = 0x01;
            ushort status = stepper_L6470.GetStatus();
 
            if ((status & mask) == 0x01)
                Debug.Print("HiZ Detected");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("Device is busy");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("SW_F Detected");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("SW_ENV Detected");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("DIR: True");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("MOT_STATUS_1 Detected");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("MOT_STATUS_2");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("NOTPERF_CMD");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("Wrong Command Detected");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("UVLO");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("THERMAL WARNING");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("TH_SD");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("Over-current detection");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("STEP_LOSS_A");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("STEP_LOSS_B");
 
            //Shift to next register
            status = (ushort)(status >> 1);
 
            if ((status & mask) == 0x01)
                Debug.Print("SCK_MOD");
        }
    }
}