This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:motor:dc_speed [2012/05/21 17:25] – drive_pwm lühemkas heikopikner | en:examples:motor:dc_speed [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 29: | Line 29: | ||
| P = I × Vq, and if Vq = 0 also P = 0 W | P = I × Vq, and if Vq = 0 also P = 0 W | ||
| - | This means that almost no power is consumed by transistor when it is ON state. Similar situation is also when transistor is closed (OFF state). In this situation | + | This means that almost no power is consumed by transistor when it is ON state. Similar situation is also when transistor is closed (OFF state). In this situation |
| P = I × Vq, and if I = 0 also P = 0 W | P = I × Vq, and if I = 0 also P = 0 W | ||
| - | As a conclusion, when transistor operates only on and off states the efficency | + | As a conclusion, when transistor operates only on and off states the efficiency |
| Line 47: | Line 47: | ||
| <code c> | <code c> | ||
| - | // | ||
| - | // The setup of the pins driving pins. | ||
| - | // | ||
| static pin dcmotor_pins[4][2] = | static pin dcmotor_pins[4][2] = | ||
| { | { | ||
| Line 66: | Line 63: | ||
| }; | }; | ||
| - | // | ||
| // Initialize PWM for specified DC motor. | // Initialize PWM for specified DC motor. | ||
| - | // | ||
| void dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler) | void dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler) | ||
| { | { | ||
| Line 118: | Line 113: | ||
| <code c> | <code c> | ||
| - | // | + | |
| - | // Desc.: DC motor speed control | + | |
| - | // Hardware: ATMega2561 Controller board, Motor board with DC motor | + | |
| - | // Author: Raivo Sell, 2012 | + | |
| - | // | + | |
| #include < | #include < | ||
| #include < | #include < | ||
| Line 128: | Line 119: | ||
| int main(void) | int main(void) | ||
| { | { | ||
| - | |||
| // DC motor 0 init with no prescaler | // DC motor 0 init with no prescaler | ||
| dcmotor_drive_pwm_init(0, | dcmotor_drive_pwm_init(0, | ||
| Line 134: | Line 124: | ||
| while(1) | while(1) | ||
| { | { | ||
| - | + | // DC motor drive with half of the nominal speed | |
| - | // DC motor drive with half of the nominal speed | + | |
| dcmotor_drive_pwm(0, | dcmotor_drive_pwm(0, | ||
| } | } | ||
| Line 144: | Line 133: | ||
| <code c> | <code c> | ||
| - | // | ||
| - | // Desc.: DC motor speed control with potentiometer | ||
| - | // Hardware: ATMega2561 Controller board, Motor board with DC motor, Sensor board | ||
| - | // Author: Raivo Sell, 2012 | ||
| - | // | ||
| - | #include < | ||
| + | #include < | ||
| #include < | #include < | ||
| #include < | #include < | ||
| Line 171: | Line 155: | ||
| // DC motor drive with speed from potentiometer | // DC motor drive with speed from potentiometer | ||
| - | // As potentiometer has 10-bit output but DC motor drive function | + | // As potentiometer has 10-bit output but DC motor drive |
| - | // 8-bit input the adc output have to be converted | + | // function |
| - | // e.g dividing the output with 4, or shifting bit 2 position >>2 | + | // to 8-bit e.g dividing the output with 4, or shifting bit |
| + | // 2 position >>2 | ||
| dcmotor_drive_pwm(0, | dcmotor_drive_pwm(0, | ||
| } | } | ||
| } | } | ||
| </ | </ | ||