stepper motor

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

stepper motor

Post by ben »

Hello

I am trying to get a stepper motor to rotate 180 degrees and back, with respect to a sensor attached to a port. I know I need to introduce some kind of interrupt, but so far I have failed. would anyone give me a little advice on this please. Many thanks.

Ben
Attachments
stepper motor rotation.fcf
(6.5 KiB) Downloaded 396 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: stepper motor

Post by Benj »

Hello Ben,

Have you played around with the timer interrupt before. You may want to have a look at some of the examples available in the examples pack and on the forum as they will give you a good insight onto how this works.

You should be able to use a direction flag variable and a counter variable to keep track of where the motor is and which direction it is moving in. This way you can move to your desired position, change the direction flag and then move back to where you started from.

ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Re: stepper motor

Post by ben »

Hi Benj

Thank you for your reply. I am very novice when it comes to programming. Although I have tried to look for timer interrupt, but I can't work it out. I am not too sure how to use a direction flag and a counter variable.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: stepper motor

Post by Benj »

Hello Ben

This should help you to get started.
Attachments
stepper example.fcf
(6.5 KiB) Downloaded 458 times

ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Re: stepper motor

Post by ben »

Hi Benj

As ever thank you very much, I will try.

Regards

Ben

ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Re: stepper motor

Post by ben »

Hi Benj,
I did try, but I am afraid I can't get it working. Is there anything I should do on the hardware ? I have basically compiled and programmed the chip(Successfully) and layed the hardware by connecting the ports to a stepper motor, power and the earth. Many thanks.

Regards

Ben

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: stepper motor

Post by Benj »

Hello Ben,

For a 5, 6 or 8-pin motor do as follows.

You will probably need to amplify the current provided by the microcontroller to allow the stepper motor to work. Running the motor coils directly from an output pin will probably not work.

The way I do this is to use NPN transistors as shown here, 1 for each coil.
Stepper.jpg
Stepper.jpg (5.01 KiB) Viewed 7616 times
The TIP122 devices are fairly inexpensive and can switch up to 5A per coil.

I then connect the common leads of the stepper motor to +V eg 5V or 12V depending on the motor. When a transistor connected to one of the coils is activated there is a direct path from the common lead to ground via the motor coil.

For a 4 pin motor you will need to use a H-Bridge configuration as each coil needs to be able to push and pull current.

The MIAC's transistor outputs can drive a 4,5 or 6-wire stepper motor directly.

ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Re: stepper motor

Post by ben »

Hi Benj,
Once again thank you, but I think I didn't explain myself proprely !! The motor driver side is fine and I have used H- bridge for my 4 pin motor, as you suggested. I am not sure about my connection on PIC device 16f88. There are no pulses from the port on the device and this let me think, may be the PIC configuraion is wrong.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: stepper motor

Post by Benj »

Ah I see the problem.

Either you have not called the motor enable component macro, you must do this before it will allow the pins to be activated.

Or the configuration is incorrect. You can change to config settings via the Chip -> Configure menu.

ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Re: stepper motor

Post by ben »

Hi Benj

I am sorry I still can't get this working, although simulation is fine, but when I connect the hardware nothing happens. Is it possible for me to E-mail my flowcode for you check please. Thank you.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: stepper motor

Post by Benj »

Hello

YOu can attach your program to the forums or PM me with your program if you do not want it to be publically released to the forum community.

Post Reply