Stepper motor controller using FEZ Mini

I am working with FEZ mini to control the stepper motor. I want to control the position of motor with the potentiometer, I have attached the potentiometer with the stepper motor with a rotating gear to get the position feedback( the picture is attached below). The stepper motor I am using is 15degree and takes 24 steps to complete a revolution. I am very new with FEZ and C#. Any help would be very much appreciated.

taimur22, welcome to the forum.

Sure sounds feasible, controlling a stepper motor, as long as you have a stepper controller board - what stepper controller do you have? Can I also ask what you’re going to do with the potentiometer? Its almost like an old-school electronic volume control :slight_smile:

edit: here’s a driver and board you might like to look at http://www.tinyclr.com/codeshare/entry/514

I am actually using MOSFET circuit to drive this motor, which are controlled and signaled by FEZ mini. I am using potentiometer because I need to control the revolution and speed of motor. I hope this is what you asking me :s

ok, so what are you asking us?

@ Brett - I am asking for help with writing a code.

but what part of the code are you not able to do?

Tell us what works already and what you need help with.

@ Brett - I have not done any coding yet. As I am not sure that what data I would need for coding. So far, I have found a code about reading the analog input from potentiometer which is given below. Please tell me if that’s the right way of doing it.

using System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
    public class Program
    {
        public static void Main()
        {
            // Create POT object assigned to the a Potentiometer Component connected to An0 with analog input
feature
            AnalogInput myPOT = new AnalogInput(FEZ_Pin.AnalogIn.An0);
            int value = 0;
while (true)
            {
                value = myPOT.GetPosition();
                Debug.Print("myPOT's position is: " + value.ToString());
                Thread.Sleep(100);
            }
       }
    }

So I want to just check. The picture you show us looks like the stepper is coupled to something - which I assumed was the potentiometer, and you were trying to turn the pot with the stepper. But that’s not how you describe the way it will work - you want the pot to be an input, and based on that you’ll change the stepper’s position. Can you please clarify?

I would approaach this by breaking the task down.

  1. Wire up the potentiometer to your analog in pin, and with the code you have test out how the value changes as you move it through the full range of settings.
  2. Wire up the stepper motor as you intend, and just set an easy routine like 50 steps clockwise, then 50 counterclockwise, in a loop.

Then you need to explain what you’d like the potentiometer to do - ie at one end of the range is the motor going flat out one direction, the other end of the range it’s going flat out in reverse direction, and somewhere in the middle the motor stops? That can then help you figure out a control algorithm

@ Brett - I am sorry that I wasn’t much clear before. And yes, you are right! Potentiometer is coupled to stepper motor which will rotate with the rotation of stepper motor.
The motor takes 24 steps to complete one revolution.

I want potentiometer to stop the motor when it reaches the 2.5V and then reverses the motor when it reaches to 5V.

So, first thing, Fez is 3v3 only so you do NOT want your analog input voltage to be 5v, you must use another voltage divider to get to 3v3 max reading.

And second, do you mean that when your program starts, it’s going to check the voltage and figure out how to turn the motor to bring it within the 50%-100% range? And then it will oscillate between that 50% to 100% range, going backwards and forwards?

As I said, I think you should break down the things you want to achieve. Figure out how to drive your stepper, then figure out how to read your potentiometer, then figure out how to incorporate the two.

@ Brett - As the Fez analogIn is only 3.3V- Can I not use the same potentiometer and utilize only range from 0V to 3.3V?
I am stilll trying to figure out the control algorithm for motor. Please help me with this query.
I really appreciate your help.
GoodDay

you cannot use the same potentiometer if it will result in sending more than 3v3 to the fez’s pin. That will provide you with a burnt out fez and many unhappy faces. You need to add in another voltage divider, or change the one you’re using already, to make sure that you can’t exceed 3v3.

I can’t be sure what you mean here:

Are you asking me to detail what the behaviour should be? That should come from your requirements, not something that I can help you with. It seems to me that your system is never going to work or never going to do anything - certainly nothing useful that I can think of, in it’s own right. Perhaps you need to go back to first principles and explain to us what it is you’re trying to achieve, not just where you’re up to in your implementation that you’ve alreadt dreamt up?