Related to: [HW] Motor Module
This library contains functions to control different HomeLab motors. There are functions for DC, stepper and servo motors.
Initializes one of the DC motor controllers. Parameters:
Drives one of the DC motor controllers. Parameters:
Drives one of the DC motor controllers. Motor rotates in a predetermined direction and speed. Parameters:
Initializes one of the unipolar stepper motor controllers. Parameters:
Unipolar stepper motor half-stepping command. Functions is blocking as it is fulfilled as long as steps are done. Parameters:
Initializes bipolar stepper motor controller.
Bipolar stepper motor half-stepping command. Functions is blocking as it is fulfilled as long as steps are done. Parameters:
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:
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:
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); }
This example demonstrates the speed adjustments of a DC motor.
#include <homelab/module/motors.h> int main(void) { unsigned char speed = 0; // DC motors initialization dcmotor_drive_pwm_init(0, TIMER2_NO_PRESCALE); while(1) { speed = 100; // DC motors drives predefined speed and direction. dcmotor_drive_pwm(0, 1, speed); } }