This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:software:homelab:library:module:motor [2010/02/08 14:42] – Page name changed from en:software:homelab:library:module:motors to en:software:homelab:library:module:motor mikk.leini | en:software:homelab:library:module:motor [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | //Seotud mooduliga: [HW] [[en: | + | //Related to: [HW] [[en: |
| - | Mootorite teek võimaldab juhtida kodulabori mootorite moodulit ja mootoreid, mis sinna ühenduvad. Olemas on alalisvoolu-, samm- ja servomootorite juhtimise funktsioonid. | + | This library contains functions to control different HomeLab motors. There are functions for DC, stepper and servo motors. |
| - | ===== Funktsioonid | + | ===== Data Types ===== |
| + | |||
| + | * **// | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | |||
| + | ===== Functions | ||
| * **//void dcmotor_init(unsigned char index)//** \\ | * **//void dcmotor_init(unsigned char index)//** \\ | ||
| - | | + | |
| - | * //index// - Mootorikontrolleri number. Väärtus | + | * //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)// | ||
| - | | + | |
| - | * //index// - Mootorikontrolleri number. Väärtus | + | * //index// - Index of motor controller. 0 to 3. |
| - | * // | + | * // |
| + | |||
| + | * **//void dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler)// | ||
| + | * //index// - Index of motor controller. 0 to 3. | ||
| + | * // | ||
| + | |||
| + | * **//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. | ||
| + | * // | ||
| + | * //speed// - Motor speed. | ||
| + | |||
| + | * **//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. | ||
| + | * // | ||
| + | * // | ||
| + | * //speed// - Time of a single step in milliseconds. | ||
| * **//void bipolar_init(void)// | * **//void bipolar_init(void)// | ||
| - | | + | |
| * **//void bipolar_halfstep(signed char direction, unsigned short num_steps, unsigned char speed)//** \\ | * **//void bipolar_halfstep(signed char direction, unsigned short num_steps, unsigned char speed)//** \\ | ||
| - | | + | |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * //speed// - Ühe sammu tegemise aeg millisekundites. | + | * //speed// - Time of a single step in milliseconds. |
| * **//void servomotor_init(unsigned char index)//** \\ | * **//void servomotor_init(unsigned char index)//** \\ | ||
| - | | + | |
| - | * //index// - Servomootori number. Väärtus | + | * //index// - Index of servo motor. 0 or 1. |
| * **//void servomotor_position(unsigned char index, signed short position)// | * **//void servomotor_position(unsigned char index, signed short position)// | ||
| - | Servo-mootori juhtkäsk. Kui juhitakse positsioneerivat servomootorit, siis muutub rootori asend, kui lõputult pöörlevat, siis muutub pöörlemise kiirus. Parameetrid: | + | 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// - Servomootori number. Väärtus | + | * //index// - Index of servo motor. 0 or 1. |
| - | * // | + | * // |
| - | ===== Näide | + | ===== Example |
| - | Järgnev näide demonstreerib kõiki teegi funktsioone. Järjest seadistatakse mootorikontrollerid ja liigutatakse mootoreid. | + | The following program demonstrates the usage of DC, stepper and servo motors. |
| <code c> | <code c> | ||
| Line 43: | Line 73: | ||
| int main(void) | int main(void) | ||
| { | { | ||
| - | // Alalisvoolu mootorikontrollerite 0 ja 1 seadistamine | + | // DC motors initialization. |
| dcmotor_init(0); | dcmotor_init(0); | ||
| dcmotor_init(1); | dcmotor_init(1); | ||
| - | // Bipolaarse samm-mootori kontrolleri seadistamine | + | // Bipolar stepper initialization. |
| bipolar_init(); | bipolar_init(); | ||
| - | // Servomootorite 0 ja 1 juhtsignaalide seadistamine | + | // Servo motors initialization. |
| servomotor_init(0); | servomotor_init(0); | ||
| servomotor_init(1); | servomotor_init(1); | ||
| - | // Üks alalisvoolu mootor pöörlema ühtpidi, teine teistpidi | + | // One DC motors drives forward, another in backward direction. |
| dcmotor_drive(0, | dcmotor_drive(0, | ||
| dcmotor_drive(1, | dcmotor_drive(1, | ||
| - | // Samm-mootori pööramine | + | // Rotating the stepper motor 100 steps in one direction |
| - | // 2 korda kiiremini teisele poole | + | // and then back with twice the speed. |
| bipolar_halfstep(1, | bipolar_halfstep(1, | ||
| bipolar_halfstep(-1, | bipolar_halfstep(-1, | ||
| - | // Servomootorite vastassuunda keeramine | + | // Rotating servo motors in opposite directions. |
| servomotor_position(0, | servomotor_position(0, | ||
| servomotor_position(1, | servomotor_position(1, | ||
| Line 69: | Line 99: | ||
| </ | </ | ||
| + | This example demonstrates the speed adjustments of a DC motor. | ||
| + | <code c> | ||
| + | #include < | ||
| + | int main(void) | ||
| + | { | ||
| + | unsigned char speed = 0; | ||
| + | |||
| + | // DC motors initialization | ||
| + | dcmotor_drive_pwm_init(0, | ||
| + | while(1) | ||
| + | { | ||
| + | speed = 100; | ||
| + | |||
| + | // DC motors drives predefined speed and direction. | ||
| + | dcmotor_drive_pwm(0, | ||
| + | } | ||
| + | } | ||
| + | </ | ||