This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:examples:motors:dc [2009/03/26 17:50] – raivo.sell | en:examples:motors:dc [2010/02/04 14:29] (current) – removed mikk.leini | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== DC Motors ===== | ||
| - | The operation of direct current (DC) motors, like all other electric motors, is based on | ||
| - | simple electromagnetism. Brushed DC motors have two wire connectors, positive and | ||
| - | negative. The rotation direction is determined by the polarity and speed by the | ||
| - | voltage. | ||
| - | Controlling the DC motor: | ||
| - | One full H-bridge or two half bridges (push–pull drivers) can be used for driving one | ||
| - | DC motor forwards and backwards. Drive circuits are available as ASICs, or can be | ||
| - | built from separate components, such as transistors. In this lab we are using the IC | ||
| - | L293D, which contains four push–pull drivers in one chip package. | ||
| - | |||
| - | |||
| - | ===== Simple test program. ===== | ||
| - | With this compied program you can test your equipment set-up. | ||
| - | DC motor is connected to DC1 port 2 and servo motor PWM1 | ||
| - | {{: | ||
| - | |||
| - | ===== Connection schema ===== | ||
| - | |||
| - | {{: | ||
| - | |||
| - | Motor drive signals from ATmega128 to the actuator board | ||
| - | |||
| - | {{: | ||
| - | |||
| - | ===== Connecting the components ===== | ||
| - | Electrical connections | ||
| - | - Make sure all power is off. | ||
| - | - Connect the actuator board and main board with a 26-pin cable. | ||
| - | - Connect the DC motor(s) to the actuator board, as shown in figure. | ||
| - | - Connect the JTAG converter with the ATmega128 main board and the PC. | ||
| - | - Finally, connect the power to the main and actuator boards. | ||
| - | |||
| - | {{: | ||
| - | {{: | ||
| - | |||
| - | ===== Example code ===== | ||
| - | <code c> | ||
| - | / | ||
| - | Title: DC motor with Actuator Board | ||
| - | Date: 080424 | ||
| - | Ver.: 1.2 | ||
| - | Compiler: AVR-GCC | ||
| - | Target: ATmega128 | ||
| - | Hardware: ATmega128 controller board, Actuator board, DC motor | ||
| - | Author: Raivo Sell 2008 | ||
| - | Notes: in1 PD7 in2 PD6 | ||
| - | Optimization: | ||
| - | Description: | ||
| - | Motor is connected to the DC1 pins 3 | ||
| - | ---------------------------------------------------------------*/ | ||
| - | #define SET(x) |= (1<< | ||
| - | #define CLR(x) & | ||
| - | #define MS (100) //defines delay | ||
| - | #define F_CPU 14745600UL //CPU Frequency (influences delay function) | ||
| - | #include < | ||
| - | ///////////////// | ||
| - | void dc_drive(int pin, int op){ // DC motor control function | ||
| - | if (op==1) PORTD SET(pin); | ||
| - | else PORTD CLR(pin); | ||
| - | } | ||
| - | |||
| - | void _delay_ms(int t){ // Delay function | ||
| - | int i,j; | ||
| - | for (i=0; | ||
| - | for (j=0; | ||
| - | } | ||
| - | } | ||
| - | ///////////////// | ||
| - | int main (void){ | ||
| - | DDRD = 0xFF;// set port direction (output) | ||
| - | PORTD = 0x00;// initialize port | ||
| - | while(1){ | ||
| - | dc_drive(6, | ||
| - | dc_drive(7, | ||
| - | _delay_ms(MS); | ||
| - | dc_drive(6, | ||
| - | dc_drive(7, | ||
| - | _delay_ms(MS); | ||
| - | dc_drive(6, | ||
| - | dc_drive(7, | ||
| - | _delay_ms(MS); | ||
| - | } | ||
| - | } | ||
| - | </ | ||