stepper motor
Moderator: Benj
stepper motor
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: stepper motor
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.
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.
- 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
Hello Ben
This should help you to get started.
This should help you to get started.
- Attachments
-
- stepper example.fcf
- (6.5 KiB) Downloaded 458 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: stepper motor
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
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
- 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
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.
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.
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: stepper motor
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.
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.
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: stepper motor
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.
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.
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel