libpruio  0.0
AM33xx-PRU driver for digital input / output and analog input
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
stepper.c File Reference

Example: control a stepper motor. More...

#include "stdio.h"
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include "../c_wrapper/pruio_c_wrapper.h"
#include "../c_wrapper/pruio_pins.h"
Include dependency graph for stepper.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE   1
 
#define P1   P8_08
 
#define P2   P8_10
 
#define P3   P8_12
 
#define P4   P8_14
 

Functions

int isleep (unsigned int mseconds)
 wait for keystroke or timeout More...
 
void move (PruIo *Io, char Rot)
 make the motor move the next step. More...
 
int main (int argc, char **argv)
 

Detailed Description

Example: control a stepper motor.

This file contains an example on how to use libpruio to control a 4-wire stepper motor:

  • configure 4 pins as output
  • receive user action in loop
  • inform user about the current state
  • change motor direction
  • change motor speed
  • stop holded or in power off mode
  • move a single step (in holded mode)
  • quit

Licence: GPLv3

Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net

Compile by:

gcc -Wall -o stepper stepper.c /usr/local/lib/freebasic/fbrt0.o -lpruio -L"/usr/local/lib/freebasic/" -lfb -lpthread -lprussdrv -ltermcap -lsupc++ -Wno-unused-variable

Definition in file stepper.c.

Macro Definition Documentation

#define _GNU_SOURCE   1

Definition at line 28 of file stepper.c.

#define P1   P8_08

Definition at line 39 of file stepper.c.

#define P2   P8_10

Definition at line 40 of file stepper.c.

#define P3   P8_12

Definition at line 41 of file stepper.c.

#define P4   P8_14

Definition at line 42 of file stepper.c.

Function Documentation

int isleep ( unsigned int  mseconds)

wait for keystroke or timeout

Parameters
msecondstimeout value in milliseconds
Returns
0 if timeout, 1 if input available, -1 if error

Wait for a keystroke or timeout and return which of the events happened.

Definition at line 53 of file stepper.c.

void move ( PruIo Io,
char  Rot 
)

make the motor move the next step.

Parameters
Iopointer to PruIo structure
Rotdirection of rotation (1 or -1)

This function sets 4 output pins for a stepper motor driver. It remembers the last step as static variable (starting at 0 = zero) and adds the new position to it. So the Rot parameter should either be 1 or -1 to make the motor move one step in any direction.

Definition at line 82 of file stepper.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 109 of file stepper.c.

Here is the call graph for this function: