Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:software:homelab:library:module:motor [2010/04/13 10:12]
raivo.sell
en:software:homelab:library:module:motor [2018/12/27 12:53] (current)
Line 4: Line 4:
  
 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 =====
Line 15: Line 24:
     * //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 0 motor is stopped, otherwise it turns in given direction.     * //​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.
 +    * //​direction//​ -  Motor polarity. -1 or +1. 
 +    * //speed// - Motor speed. ​ 0 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)//** \\
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.txt ยท Last modified: 2018/12/27 12:53 (external edit)
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