This is an old revision of the document!


Table of Contents

Motors

Related to: [HW] Motor Module

This library contains functions to control different HomeLab motors. There are functions for DC, stepper and servo motors.

Functions

  • void dcmotor_init(unsigned char index)

Initializes one of the DC motor controllers. Parameters:

  • index - Index of motor controller. 0 to 3.
  • void dcmotor_drive(unsigned char index, signed char direction)

Drives one of the DC motor controllers. Parameters:

  • index - Index of motor controller. 0 to 3.
  • direction - Motor polarity. -1, 0 or +1. In case of 0 motor is stopped, otherwise it turns in given direction.
  • void unipolar_init(unsigned char index)

Initializes one of the unipolar stepper motor controllers. Parameters:

  • index - Index of motor controller. 0 or 1.
  • void unipolar_halfstep(unsigned char index, signed char direction, unsigned short num_steps, unsigned char speed)

Unipolar stepper motor half-stepping command. Functions is blocking as it is fulfilled as long as steps are done. Parameters:

  • index - Index of motor controller. 0 or 1.
  • direction - Directions of rotation. -1 or +1.
  • num_steps - Count of half-steps.
  • speed - Time of a single step in milliseconds.
  • void bipolar_init(void)

Initializes bipolar stepper motor controller.

  • void bipolar_halfstep(signed char direction, unsigned short num_steps, unsigned char speed)

Bipolar stepper motor half-stepping command. Functions is blocking as it is fulfilled as long as steps are done. Parameters:

  • direction - Directions of rotation. -1 or +1.
  • num_steps - Count of half-steps.
  • speed - Time of a single step in milliseconds.
  • void servomotor_init(unsigned char index)

Initializes one of a servo motor PWM signal generations units in ATmega128 timer 1. PWM signal is 50 hz with high period of 1.5 ms ± 0.5 ms. Parameters:

  • index - Index of servo motor. 0 or 1.
  • void servomotor_position(unsigned char index, signed short position)

Servo motor pulse width control command. If positioning servo motor is driven, its position is altered, if rotating one, its rotation speed is altered. Parameters:

  • index - Index of servo motor. 0 or 1.
  • position - Position or rotation speed. -100 to +100. 0 corresponds to stop.

Example

The following program demonstrates the usage of DC, stepper and servo motors.

#include <homelab/module/motors.h>
 
int main(void)
{
	// DC motors initialization.
	dcmotor_init(0);
	dcmotor_init(1);
 
	// Bipolar stepper initialization.
	bipolar_init();
 
	// Servo motors initialization.
	servomotor_init(0);
	servomotor_init(1);
 
	// One DC motors drives forward, another in backward direction.
	dcmotor_drive(0, -1);
	dcmotor_drive(1, +1);
 
	// Rotating the stepper motor 100 steps in one direction
	// and then back with twice the speed.
	bipolar_halfstep(1, 100, 50);
	bipolar_halfstep(-1, 100, 25);
 
	// Rotating servo motors in opposite directions.
	servomotor_position(0, -100);
	servomotor_position(1, +100);
}
en/software/homelab/library/module/motor.1271142755.txt.gz · Last modified: (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0