Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:software:homelab:library:module:motor [2010/03/25 19:22] mikk.leinien:software:homelab:library:module:motor [2020/07/20 12:00] (current) – external edit 127.0.0.1
Line 3: Line 3:
 //Related to: [HW] [[en:hardware:homelab:motor]]// //Related to: [HW] [[en:hardware:homelab:motor]]//
  
-This library contains functions to control different Homelab motors. There are functions for DC, stepper and servo motors.+This library contains functions to control different HomeLab motors. There are functions for DC, stepper and servo motors
 + 
 +===== Data Types ===== 
 + 
 +  * **//prescale//** \\  PWM clock prescaler enumration data type. It determines the division factor of system clock. It is recommended to use the first two division factors. Options: 
 +    * //TIMER2_NO_PRESCALE// - Division factor not used. 
 +    * //TIMER2_PRESCALE_8// - Division factor 8. 
 +    * //TIMER2_PRESCALE_64// - Division factor 64. 
 +    * //TIMER2_PRESCALE_256// - Division factor 256. 
 +    * //TIMER2_PRESCALE_1024// - Division factor 1024.
  
 ===== Functions ===== ===== Functions =====
  
   * **//void dcmotor_init(unsigned char index)//** \\   * **//void dcmotor_init(unsigned char index)//** \\
-    Initializes one of DC motor controllers. Parameters:+    Initializes one of the DC motor controllers. Parameters:
     * //index// - Index of motor controller. 0 to 3.     * //index// - Index of motor controller. 0 to 3.
  
   * **//void dcmotor_drive(unsigned char index, signed char direction)//** \\   * **//void dcmotor_drive(unsigned char index, signed char direction)//** \\
-    Drives one of DC motor controllers. Parameters:+    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 dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler)//** \\     Initializes one of the DC motor controllers for speed control. In addition, you can set the appropriate prescaler, depending on the frequency of the PWM's you need. Parameters: 
 +    * //index// - Index of motor controller. 0 to 3. 
 +    * //prescaler// - Clock prescaler selection. Interruptions can occur very quickly upset the program of work. For example, when the UH sensor is used, it is necessary to set the prescaler TIMER2_PRESCALE_8.  
 + 
 +  * **//void dcmotor_drive_pwm(unsigned char index, signed char direction, unsigned char speed) //** \\ 
 +Drives one of the DC motor controllers. Motor rotates in a predetermined direction and speed. Parameters:
     * //index// - Index of motor controller. 0 to 3.     * //index// - Index of motor controller. 0 to 3.
-    * //direction// - Motor polarity. -1, 0 or +1. In case of motor is stopped, otherwise it turns on either of directions.+    * //direction// Motor polarity. -1 or +1.  
 +    * //speed// - Motor speed.  to 255. 0 the engine is stopped and the 255 is the maximum possible speed.
  
   * **//void unipolar_init(unsigned char index)//** \\   * **//void unipolar_init(unsigned char index)//** \\
-    Initializes one of unipolar stepper motor controllers. Parameters:+    Initializes one of the unipolar stepper motor controllers. Parameters:
     * //index// - Index of motor controller. 0 or 1.     * //index// - Index of motor controller. 0 or 1.
  
Line 65: Line 84:
  servomotor_init(1);  servomotor_init(1);
  
- // One DC motors drives to forward, another to backward direction.+ // One DC motors drives forward, another in backward direction.
  dcmotor_drive(0, -1);  dcmotor_drive(0, -1);
  dcmotor_drive(1, +1);  dcmotor_drive(1, +1);
Line 77: Line 96:
  servomotor_position(0, -100);  servomotor_position(0, -100);
  servomotor_position(1, +100);  servomotor_position(1, +100);
 +}
 +</code>
 +
 +This example demonstrates the speed adjustments of a DC motor. 
 +
 +<code c>
 +#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);       
 +  }
 } }
 </code> </code>
en/software/homelab/library/module/motor.1269537720.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