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/03/25 19:22] – mikk.leini | en: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: | //Related to: [HW] [[en: | ||
| - | This library contains functions to control different | + | This library contains functions to control different |
| + | |||
| + | ===== Data Types ===== | ||
| + | |||
| + | * **// | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| ===== Functions ===== | ===== Functions ===== | ||
| * **//void dcmotor_init(unsigned char index)//** \\ | * **//void dcmotor_init(unsigned char index)//** \\ | ||
| - | Initializes one of a 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 a DC motor controllers. Parameters: | + | Drives one of the DC motor controllers. Parameters: |
| + | * //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. | * //index// - Index of motor controller. 0 to 3. | ||
| - | * // | + | * // |
| + | * //speed// - Motor speed. | ||
| * **//void unipolar_init(unsigned char index)//** \\ | * **//void unipolar_init(unsigned char index)//** \\ | ||
| - | Initializes one of a 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 | + | // One DC motors drives forward, another |
| dcmotor_drive(0, | dcmotor_drive(0, | ||
| dcmotor_drive(1, | dcmotor_drive(1, | ||
| Line 77: | Line 96: | ||
| servomotor_position(0, | servomotor_position(0, | ||
| servomotor_position(1, | servomotor_position(1, | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | 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, | ||
| + | } | ||
| } | } | ||
| </ | </ | ||