Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
et:examples:motor:dc_speed [2013/03/26 21:15] – external edit 127.0.0.1et:examples:motor:dc_speed [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== DC motor speed ======+<pagebreak> 
 +====== Alalisvoolu mootori kiirus ======
  
-<note important>Tõlkida</note>+//Vajalikud teadmised: [HW] [[et:hardware:homelab:motor]], [AVR] [[et:avr:io]], [LIB] [[et:software:homelab:library:module:motor]], [LIB] [[et:software:homelab:library:delay]]//
  
-//Necessary knowledge: [HW] [[en:hardware:homelab:motor]], [AVR] [[en:avr:io]], [LIB] [[en:software:homelab:library:module:motor]], [LIB] [[en:software:homelab:library:delay]]// 
  
 +===== Teooria =====
 +[{{  :examples:motor:dc:mootor_rattaga_v.jpg?220|rattaga DC motoor}}]
 +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 saavutatakseTegelik kiirus sõltub paljudest factoritestpõhiliselt jõumomendist mootori väljundvõllil, töövoolust ja muudest mootori karakteristikutestMootori ja kiiruse ning väljundmomendi suhe on ideaalsel mootoril lineaarses suhtes, st mida suurem on väljundmoment, seda madalam on kiirus ning seda rohkem tarbib mootor voolu, kuid reaalsete mootorite puhul sõltub see täpse mootori tüübist.
-[{{  :examples:motor:dc:mootor_rattaga_v.jpg?220|DC motor with wheel}}] +
-Permanent magnet DC motors are very common in robotics and mechatronicsDC motors are relatively easy to controlboth direction and speedMotor 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:dc:sample_pwm_signals.png?220|PWM signaali näide ühe perioodi kohta}}]
  
-[{{  :examples:motor:dc:sample_pwm_signals.png?220|PWM signal examples for one period}}]+Tavaliselt on mootori kiirus sõltuvuses mootor klemmidele antavast pingest. Kui mootorile anda nominaalpinge, siis mootor pöörleb nominaalkiirusega kui mootorit pole koormatud. Kui vähendada mootorile antavat pinget, siis mootori kiirus ning arendatav jõumoment samuti vähenevad. Sellist kiiruse juhtimist nimetatakse analoog juhtimiseks. Seda saab realiseerida näiteks transistoriga või reostaadiga.
  
-In generalmotor speed is dependent of the applied voltageWhen powering motor with its nominal voltagemotor runs at its nominal speed at no load conditionWhen reducing the voltage motor speed and torque also decreasesThis 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 seadmedsiis tuleks ka mootoreid digitaalselt juhtidaSelle saavutamiseks tuleks transistore pidevalt natuke lahti hoidmise asemel lülitada neid kiiresti sisse - välja kasutades pulsilaius modulatsiooni (PWM). Koguenergiamis mootorile antakse jääb kusagile seisva mootori ja täiskiirusel pöörleva mootori vahepealeAvatud oleku aja kirjeldamiseks kasutatakse töötsükli mõistet, mida mõõdetakse protsentides0% tähendab, et transistor on pidevalt suletud asendis ning mootor seisab, 100% tähendab, et transistor on pidevalt avatud ning mootor pöörleb nominaalkiirusel. PWMi sagedus peab olema piisavalt kõrge, et mootori pöörlemine oleks võimalikult sujuv ning väljundvõlli katkendlik pöörlemine ei tekitaks lisavibratsioone. Samuti tekitab mootori mähis madalatel sagedustel müra. Seetõttu kasutatakse tavaliselt sagedusi üle 20kHz. Sagedust piirab aga ka transistoride effektiivsus, mis kõrgemate sageduste puhul langeb.
  
-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, H-bridge can be feed with the same PWM signal by controlling so motor speed and direction.+Robotites kasutatakse ühe transistori asemel tavaliselt H-silda, mis võimaldab lisaks kiiruse muutmisele ka mootorite suunda muuta.
  
-By using digital contorol, i.e. PWM signal to control the transistor and by this motor speedthere are several advantages over the analogous controlMost 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 (power dissipation are minimized).+Digitaalsel juhtimisel (nt PWM) on mitmed eelised analoog juhtimise ülePõhiline eelis mikrokontrolleriga juhitavate süsteemide puhul on seeet vaja on vaid üht digitaalväljundit ning puudub vajaduse keerulisel digitaal - analoog muundiri järeleLisaks on digitaalne juhtimine effektiivsem (vähem energiat muundatakse lihtsalt soojuseks).
  
-[{{  :examples:motor:dc:mootori_pwm_juhtimine.png?220|Controlling motor speed with PWM}}]+[{{  :examples:motor:dc:mootori_pwm_juhtimine.png?220|Mootori juhtimine PWMga}}]
  
-Simplified control schematics is shown on the figure.  +Lihtsustatud juhtimisskeem on näidatud kõrvalasuval joonisel
-Control voltage Vc from microcontroller output pin turns on and off the transistor in approx. 20 kHz frequencyWhen is turned on (saturation)full current flows freely through the motor M. In this state transistor acts as a closed switch and voltage on the transistor Vq is nearly by leaving almost full Vdd across the motor.  +Juhtpinge Vc tuleb mikrokontrolleri väljundviigult ning lülitab transistori sisse - välja umbes 20kHz sagedusegaKui Q on sisse lülitatudliigub kogu vool läbi mootori M. Sellisel juhul käitub transistor kui suletud lüliti ja pingelang Vq on 0-i lähedane ning mootorile jääb kogu pinge Vdd. 
-We can calculate the power dissipated by the transistor by using formula P = I × V. Applying this to Q:+Me saame arvutada ka transistori läbiva koguvõimsuse valemiga P = I V.
  
-P = I × Vq, and if Vq also = 0 W+P = I Vq, ja kui Vq 0, siis ~ 0W
  
-This means that almost no power is consumed by transistor when it is ON stateSimilar situation is also when transistor is closed (OFF state)In this situation nearly no current  flows through the motor and transistorCalculating the power consumed by transistor once again:+See tähendab, et transistor ei kuluta peaaegu üldse energiat avatud olekusSarnane situatsioon on ka juhul, kui transistor on suletud olekusSellisel juhul ei liigu läbi transistori ega mootori voolArvutades transistori läbiva võimsuse:
  
 +P = I × Vq, ja kui I = 0, siis P = 0W
  
-P = I × Vqand if I = 0 also P = 0 W+Kokkuvõttes võime öeldakui 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, kus transistor kulutab sama palju voolu, kui juhitav mootor on tegemist väga effektiivse süsteemiga. Praktikas ei ole aga olemas kadudeta süsteemi ning nii esinevad kaod ka transistori ümberlülitamisel ühest asendist teise. Seega esinevad suuremad kaod juhul, kui transistore lülitatakse kiiremal sagedusel.
  
-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 PWM signaaliga
  
 +===== Praktika =====
  
-Note: do not mix up RC Servo PWM signal with ordinary PWM signals. +Kodulabori Mootorimoodul sisaldab Mootori plaati ning DC mootorit ülekande ning koodrigaMootoriplaadile on võimalik ühendada kuni neli alalisvoolumootoritSkeemid ja õpetused on vastaval alamlehel "Mootorite moodul"
- +Iga mootorit, mis on ühendatud H-silla külge juhitakse kahe mikrokontrolleri digitaalväljundigaMootori kiirust juhitakse taimeritega, mis genereerivad pideva PWM signaali H-sillale
- +Mootori kiirust juhtiakse suhteliste väärtustega 255, kus tähendab seisvat mootorit ning 255 maksimaalsel kiirusel liikuvat mootorit.
-===== Practice ===== +
- +
-The Motor module of the HomeLab includes motor board and DC motor equipped with integrated gearbox and encoderMotor board allows connecting up to four DC motorsThe 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 microcontrollerMotor speed is controlled by timers which are generating software PWM signal for H-bridge.  +
-Motor speed can be controlled by relative value between to 255, where means that motor is stopped and 255 that motor runs at maximum speed.+
  
 <code c> <code c>
Line 64: Line 62:
 }; };
  
-// Initialize PWM for specified DC motor. +// Käivita PWM valitud mootori jaoks
 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;           // set default PWM values +      compare[i] = pwm;           // algväärtusta PWM väärtused 
-      compbuff[i] = pwm;          // set default PWM values+      compbuff[i] = pwm;          // algväärtusta PWM väärtused
   }   }
  
- // Timer 2 normal regimeset prescaler+ // Timer 2 normaal režiimissea 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:
 </code> </code>
  
-With the array dcmotor_pins in the librarythe controlling pins of four motor-controllers are determinedBefore controlling the motors and their speed, function dcmotor_drive_pwm_init with the number of the motor-controller (0 – 3) must be called outIt sets the pins as outputIn addition prescaler - //timer2_prescale prescaler// have to be set as a second parameterPrescaler sets PWM frequency and is important when using other timer based functions on the same time. If only motors are used TIMER2_NO_PRESCALE value is most suitableIf other timer based functions are used on the same time e.g. ultrasonic sensor TIMER2_PRESCALE_8 is recommended valueBigger prescaler values are not suitable for DC motor speed control as vibration will be too high. However the same function can be used for example flashing the LED and in this case bigger prescaler values are important to consider.+Mootorite teegi maatriksis dcmotor_pins määratakse ära viigudkuhu on ühendatud Mootoriplaadi 4 mootori juhtsignaalidEnne mootori kiiruse juhtimist tuleb välja kutsuda funktsioon dcmotor_drive_pwm_init selle mootori kohta (0-3), mille kiirust on soov juhtima hakataSee seab vastavad viigud väljunditeksSamuti tuleks seadistada Timer2 jagur //timer2_prescale//, mis määrab PWMi sageduseKui koodus ei kasutata rohkem taimeri peal jooksvaid süsteeme, siis on sobilik väärtus TIMER2_NO_PRESCALE. Kui aga kasutatakse näiteks ka ultraheliandurit vmt, siis tuleks valida TIMER2_PRESCALE_8, muidu võib protsessori jõudlust väheks jääda ja anduri tulemustesse võib tekkida vigaSuuremaid jaguri väärtuseid pole soovitatav kasutada, sest see muudab mootori pöörlemise katkendlikuks tekitades vibratsiooni.
  
-For controlling motor speed the function dcmotor_drive_pwm is included into libraryWith this function three parameters are needed. First is motor index (0-3), second is direction -negative direction parameter is used to give to the motor one revolving direction and other direction with positive parameterand if the motor is stopped. Third parameter is speed where the value can be from to 255. The speed value is not any specific rpmbut is relative value and the actual speed is depending on the motor and power supplyThe precision of motor speed control is 8-bitmeaning that smallest controlling value is 1/255 of full speed.+Mootorite kiiruse juhtimiseks kasutatakse funktsiooni dcmotor_drive_pwm. See funktsioon vajab kolme väärtust: esiteks mootori numbrit, mille kiirust reguleeritakse (0-3), teiseks suunda (-1, 0, +1), kus -1 tähistab pöörlemist ühes suunas, +1 teises ning tähistab seismist, ning kolmandaks kiirust vahemikus 0 - 255. Kiiruse väärtus ei ole seotud mingi kindla pöörlemiskiirusega vaid suhteline väärtus mootori maksimaalse pöörlemiskiiruse ja seisva mootori vahel. Mootori reaalne pöörlemiskiirus sõltub mootoristtoitepingest ning koormusestMootori kiiruse täpsus on 8-bitinemis tähendab, et minimaalne jutimisetäpsus on 1/255 mootori maksimaalsest kiirusest.
  
-The following is an example program which controls first DC motor (DC motor connector 0so that motor speed is half of the full speedThe speed is modulated with PWM signal of controlling pin.+Järgnevalt on toodud väiteprogramm, mis paneb esimese mootori (ühendatud DC0 viikudelepöörlema poolel kiiruselKiirust juhitakse PWM signaaliga.
  
 <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, TIMER2_NO_PRESCALE);   dcmotor_drive_pwm_init(0, TIMER2_NO_PRESCALE);
    
   while(1)   while(1)
   {       {   
-  // DC motor drive with half of the nominal speed+  // Mootorile pool nominaalkiirusest.
  dcmotor_drive_pwm(0, 1, 128);         dcmotor_drive_pwm(0, 1, 128);       
   }   }
Line 131: Line 129:
 </code> </code>
  
-Another example program which controls first DC motor (DC motor connector 0with potentiometer from Sensor module+Teine näiteprogramm juhib esimest DC mootorit (ühendatud DC0 viikudelepotensiomeetriga, mis on ühendatud Andurite mooduli plaadile.
  
 <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_PRESCALE_8);  adc_init(ADC_REF_AVCC, ADC_PRESCALE_8);
  
- // DC motor 0 init with no prescaler+ // Eelseadista DC0 mootor, ilma timer2 jagurita
   dcmotor_drive_pwm_init(0, TIMER2_NO_PRESCALE);   dcmotor_drive_pwm_init(0, TIMER2_NO_PRESCALE);
  
   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, 4);  speed = adc_get_average_value(3, 4);
  
- // 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 8-bit input the adc output have to be converted  + // 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+ // 2 kohta >>2
  dcmotor_drive_pwm(0, 1, speed/4);  dcmotor_drive_pwm(0, 1, speed/4);
   }   }
 } }
 </code> </code>
et/examples/motor/dc_speed.1364332544.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0