This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| et:examples:motor:dc_speed [2013/03/26 21:15] – external edit 127.0.0.1 | et:examples:motor:dc_speed [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | < |
| + | ====== | ||
| - | <note important> | + | //Vajalikud teadmised: [HW] [[et: |
| - | //Necessary knowledge: [HW] [[en: | ||
| + | ===== Teooria ===== | ||
| + | [{{ : | ||
| + | Püsimagnetiga DC mootorid on väga laialt levinud robootikas ja mehatroonikas. DC mootorite kiirust ja pöörlemissuunda on suhteliselt lihtne juhtida. Mootori pöörlemissuunda muudetakse mootorile antava pinge polaarsusega. Mikrokontrolleriga juhtimisel kasutatakse H-silda. | ||
| - | ===== Theory ===== | + | Kuigi DC mootori kiirust on lihtne juhtida, siis puudub garantii, et soovitud kiirus siiski saavutatakse. Tegelik kiirus sõltub paljudest factoritest, põhiliselt jõumomendist mootori väljundvõllil, |
| - | [{{ : | + | |
| - | Permanent magnet DC motors are very common in robotics and mechatronics. DC motors are relatively easy to control, both direction and speed. Motor rotation direction is determined by power supply polarity and H-bridge driver is often used when DC motor is controlled by microcontroller. | + | |
| - | Even DC motor speed is easy to control there is no guarantee that required speed is also actually obtained. The reason is that the actual speed depends on several factors, primarily of the torque applied on the shaft, feeding current and other motor characteristics. The relationship between torque and speed of a ideal DC motor is linear, which means: the higher is the load on the shaft the lower is the speed of the shaft and the higher is the current through the coil. In reality it is not linear and can vary depending on the motor quite a lot. | + | Alalisvoolu mootorit saab juhtida nii analoog kui digitaal signaalidega. |
| - | Controlling the speed of DC motor can be realized either by analogous or digital signaling. | + | [{{ :examples:motor: |
| - | [{{ : | + | Tavaliselt on mootori kiirus sõltuvuses mootor klemmidele antavast pingest. Kui mootorile anda nominaalpinge, |
| - | In general, motor speed is dependent of the applied voltage. When powering motor with its nominal voltage, motor runs at its nominal speed at no load condition. When reducing the voltage motor speed and torque also decreases. This kind of speed control can be called as analogous motor speed control. This can be realized for example with one transistor. | + | Robootikas juhitakse alalisvoolu mootoreid mikrokontrolleritega ning kuna need on digitaalsed seadmed, siis tuleks ka mootoreid digitaalselt juhtida. Selle saavutamiseks tuleks transistore pidevalt natuke lahti hoidmise asemel lülitada neid kiiresti sisse - välja kasutades pulsilaius modulatsiooni (PWM). Koguenergia, mis mootorile antakse jääb kusagile seisva mootori ja täiskiirusel pöörleva mootori vahepeale. Avatud oleku aja kirjeldamiseks kasutatakse töötsükli mõistet, mida mõõdetakse protsentides. 0% tähendab, et transistor |
| - | In robotics DC motors are in most cases controlled by microcontrollers and as microcontrollers are digital devices it is much easier to control motor speed also digitally. To do that, instead of keeping transistor open partly, transistors need to be closed and opened constantly using pulse width modulation (PWM), so the total energy supplied to the motor is somewhere between motor switched off and motor running on full power. Opened time in the whole PWM period is called duty cycle, which is marked as percents. 0% means the transistor is closed constantly – it is not conducting current. 100% means the transistor is constantly open and is conducting current all the time. The frequency of the PWM has to be high enough to avoid vibrations in the shaft of the motor. At low frequencies the motor produces noise and due to that, modulation frequencies over 20 kHz are used quite often. On the other hand the efficiency of the transistors might not be so good at higher frequencies. Vibrating of the shaft of the motor is reduced by inertia of the rotor and the inductivity of the coils. Instead of using single transistor, | + | Robotites kasutatakse ühe transistori asemel tavaliselt |
| - | By using digital contorol, i.e. PWM signal to control the transistor and by this motor speed, there are several advantages over the analogous control. Most important ones for microcontroller driven systems are that speed can be controlled only by one single digital output (no need for complicated digital-analogous converter) and control is more effective | + | Digitaalsel juhtimisel (nt PWM) on mitmed eelised analoog juhtimise üle. Põhiline eelis mikrokontrolleriga juhitavate süsteemide puhul on see, et vaja on vaid üht digitaalväljundit ning puudub vajaduse keerulisel digitaal - analoog muundiri järele. Lisaks on digitaalne juhtimine effektiivsem |
| - | [{{ : | + | [{{ : |
| - | Simplified control schematics is shown on the figure. | + | Lihtsustatud juhtimisskeem |
| - | Control voltage | + | Juhtpinge |
| - | We can calculate the power dissipated by the transistor by using formula | + | Me saame arvutada ka transistori läbiva koguvõimsuse valemiga |
| - | P = I × Vq, and if Vq = 0 also P = 0 W | + | P = I * Vq, ja kui Vq ~ 0, siis P ~ 0W |
| - | This means that almost no power is consumed by transistor | + | See tähendab, et transistor |
| + | P = I × Vq, ja kui I = 0, siis P = 0W | ||
| - | P = I × Vq, and if I = 0 also P = 0 W | + | Kokkuvõttes võime öelda, kui transistor on skeemis lülitava elemendina, siis on süsteemi effektiivsus väga kõrge ning transistori kasutatav võimsus on väga madal. Võrreldes lineaarse (analoog) süsteemiga, |
| - | As a conclusion, when transistor operates only on and off states the efficiency can be very high as nearly no power is consumed by transistor itself. Compared with linear (analogous) control of the transistor when half of the power can be consumed by transistor in case motor is operated at half speed. However in practice, digital control (PWM) is also not totally lossless as transistors cannot be turned on and off instantaneously. Therefore little dissipation occurs in every transistor and every switching, by cousing bigger dissipation when frequency is higher. | + | PS: mitte segi ajada RC Servo juhtsignaali |
| + | ===== Praktika ===== | ||
| - | Note: do not mix up RC Servo PWM signal with ordinary PWM signals. | + | Kodulabori Mootorimoodul sisaldab Mootori plaati ning DC mootorit ülekande ning koodriga. Mootoriplaadile on võimalik ühendada kuni neli alalisvoolumootorit. Skeemid ja õpetused on vastaval alamlehel " |
| - | + | Iga mootorit, mis on ühendatud | |
| - | + | Mootori kiirust juhtiakse suhteliste väärtustega | |
| - | ===== Practice ===== | + | |
| - | + | ||
| - | The Motor module of the HomeLab includes motor board and DC motor equipped with integrated gearbox and encoder. Motor board allows connecting up to four DC motors. The schemes and instructions for connection are found in the chapter “Motors module”. | + | |
| - | Every motor is connected to H-bridge which is controlled with two digital output pins of the microcontroller. Motor speed is controlled by timers which are generating software | + | |
| - | Motor speed can be controlled by relative value between | + | |
| <code c> | <code c> | ||
| Line 64: | Line 62: | ||
| }; | }; | ||
| - | // Initialize | + | // Käivita |
| void dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler) | void dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler) | ||
| { | { | ||
| Line 76: | Line 74: | ||
| pwm = PWMDEFAULT; | pwm = PWMDEFAULT; | ||
| - | for(i=0 ; i<CHMAX ; i++) // initialize all channels | + | for(i=0 ; i<CHMAX ; i++) // Käivita kõik kanalid |
| { | { | ||
| - | compare[i] = pwm; // | + | compare[i] = pwm; // |
| - | compbuff[i] = pwm; // set default | + | compbuff[i] = pwm; // algväärtusta |
| } | } | ||
| - | // Timer 2 normal regime, set prescaler | + | // Timer 2 normaal režiimis, sea jagur |
| timer2_init_normal(prescaler); | timer2_init_normal(prescaler); | ||
| - | // Timer 2 interrupts set enabled | + | // Timer 2 luba katkestused |
| timer2_overflow_interrupt_enable(true); | timer2_overflow_interrupt_enable(true); | ||
| - | // Enable global interrupts | + | // Luba globaalsed katkestused |
| sei(); | sei(); | ||
| } | } | ||
| Line 107: | Line 105: | ||
| </ | </ | ||
| - | With the array dcmotor_pins | + | Mootorite teegi maatriksis |
| - | For controlling motor speed the function | + | Mootorite kiiruse juhtimiseks kasutatakse funktsiooni |
| - | The following is an example program which controls first DC motor (DC motor connector 0) so that motor speed is half of the full speed. The speed is modulated with PWM signal of controlling pin. | + | Järgnevalt on toodud väiteprogramm, |
| <code c> | <code c> | ||
| Line 120: | Line 118: | ||
| int main(void) | int main(void) | ||
| { | { | ||
| - | // DC motor 0 init with no prescaler | + | // Eelseadista DC0 mootor, ilma timer2 jagurita |
| dcmotor_drive_pwm_init(0, | dcmotor_drive_pwm_init(0, | ||
| while(1) | while(1) | ||
| { | { | ||
| - | | + | |
| dcmotor_drive_pwm(0, | dcmotor_drive_pwm(0, | ||
| } | } | ||
| Line 131: | Line 129: | ||
| </ | </ | ||
| - | Another example program which controls first DC motor (DC motor connector 0) with potentiometer from Sensor module. | + | Teine näiteprogramm juhib esimest |
| <code c> | <code c> | ||
| Line 143: | Line 141: | ||
| int speed; | int speed; | ||
| - | // Adjusting ADC | + | // Käivita analoog-digitaal muundir |
| adc_init(ADC_REF_AVCC, | adc_init(ADC_REF_AVCC, | ||
| - | // DC motor 0 init with no prescaler | + | // Eelseadista DC0 mootor, ilma timer2 jagurita |
| dcmotor_drive_pwm_init(0, | dcmotor_drive_pwm_init(0, | ||
| while(1) | while(1) | ||
| { | { | ||
| - | // Potentiometer is connected to channel | + | // Potensiomeeter on ühendatud kanalisse |
| - | // Average of 4 samples are acquired | + | // Võtame nelja lugemi keskmise väärtuse |
| speed = adc_get_average_value(3, | speed = adc_get_average_value(3, | ||
| - | // DC motor drive with speed from potentiometer | + | // Loeme DC mootori kiiruse potensiomeetrist |
| - | // As potentiometer has 10-bit output but DC motor drive | + | // Kuna potensiomeetri väärtus on 10-bitine kuid DC mootori |
| - | // function | + | // funktsioon on 8-bitine, tuleb adc väärtus muundada 8-bitiseks |
| - | // to 8-bit e.g dividing the output with 4, or shifting bit | + | // jagades adc väärtus neljaga või nihutades adc väärtust paremale |
| - | // 2 position | + | // 2 kohta >>2 |
| dcmotor_drive_pwm(0, | dcmotor_drive_pwm(0, | ||
| } | } | ||
| } | } | ||
| </ | </ | ||