C/C++ on Linux/Unix

Moderators: Lundin
Number of threads: 314
Number of posts: 633

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
c program for stepper motor in controlling the movement of a camera Posted by felnlily on 10 Feb 2005 at 2:53 AM
i need help its urgent

a sourcecode for linux in c for the stepper motor


pls....

help

Report
Re: c program for stepper motor in controlling the movement of a camer Posted by sumitxshah on 28 Mar 2005 at 12:28 AM
: i need help its urgent
:
: a sourcecode for linux in c for the stepper motor
:
:
: pls....
:
: help

Here is the code for controlling stepper motor...Hope u can compile it in Linux 9 (2.4 ker)
/* Stepper.c */
#include <stdio.h> /* for printf() */
#include <sys/io.h> /* for ioperm() */
#include <unistd.h> /* for usleep() */

#include "port.h"

#define PORT 0x378
#define TIME 1000

void clockwise(){
int i;
/* i've got one rotor cycle in 12 loops */
for (i=0; i<12; i++){
port_out(PORT, 0x01); /* 0001 */
usleep(TIME);
port_out(PORT, 0x03); /* 0011 */
usleep(TIME);
port_out(PORT, 0x02); /* 0010 */
usleep(TIME);
port_out(PORT, 0x06); /* 0110 */
usleep(TIME);
port_out(PORT, 0x04); /* 0100 */
usleep(TIME);
port_out(PORT, 0x0c); /* 1100 */
usleep(TIME);
port_out(PORT, 0x08); /* 1000 */
usleep(TIME);
port_out(PORT, 0x09); /* 1001 */
usleep(TIME);
}
}

void counter_clockwise(){
int i;
for (i=0; i<12; i++){
port_out(PORT, 0x08); /* 1000 */
usleep(TIME);
port_out(PORT, 0x0c); /* 1100 */
usleep(TIME);
port_out(PORT, 0x04); /* 0100 */
usleep(TIME);
port_out(PORT, 0x06); /* 0110 */
usleep(TIME);
port_out(PORT, 0x02); /* 0010 */
usleep(TIME);
port_out(PORT, 0x03); /* 0011 */
usleep(TIME);
port_out(PORT, 0x01); /* 0001 */
usleep(TIME);
port_out(PORT, 0x09); /* 1001 */
usleep(TIME);
}
}


int main(){
int i;
if (ioperm(PORT, 1, 1) == -1)
printf("There's something wrong...\n");


for (i=0; i<30; i++)
clockwise();

return 0;
}


/* port.h */

#ifndef PORT_H
#define PORT_H

static inline int port_in( int port )
{
unsigned char value;
__asm__ volatile ("inb %1,%0"
: "=a" (value)
: "d" ((unsigned short)port));
return value;
}

static inline void port_out( unsigned short int port, unsigned char val ){
__asm__ volatile (
"outb %0,%1\n"
:
: "a" (val), "d" (port)
);
}

#endif





With Regards...
Sumit Shah.

Report
Re: c program for stepper motor in controlling the movement of a camer Posted by spsidpatel on 19 Oct 2012 at 7:49 PM
Hi,
Sumit I want help in program of controlling stepper motor in 'C' language, Actually I am doing 1 embedded systrm project in which i have to run the motor from pulses can you tell me How can i program? And the motor is 5 wire unipolar.
Regards
Sid
Report
Re: c program for stepper motor in controlling the movement of a camer Posted by spsidpatel on 19 Oct 2012 at 7:50 PM
Hi,
Sumit I want help in program of controlling stepper motor in 'C' language, Actually I am doing 1 embedded systrm project in which i have to run the motor from pulses can you tell me How can i program? And the motor is 5 wire unipolar.
Regards
Sid



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.