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/04/29 08:04] rellermaaet: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]]// //Vajalikud teadmised: [HW] [[et:hardware:homelab:motor]], [AVR] [[et:avr:io]], [LIB] [[et:software:homelab:library:module:motor]], [LIB] [[et:software:homelab:library:delay]]//
Line 40: Line 39:
 PS: mitte segi ajada RC Servo juhtsignaali PWM signaaliga PS: mitte segi ajada RC Servo juhtsignaali PWM signaaliga
  
-===== Practice =====+===== Praktika =====
  
-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”.  +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"
-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.  +Iga mootorit, mis on ühendatud H-silla külge juhitakse kahe mikrokontrolleri digitaalväljundigaMootori kiirust juhitakse taimeritega, mis genereerivad pideva PWM signaali H-sillale
-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.+Mootori kiirust juhtiakse suhteliste väärtustega 255, kus tähendab seisvat mootorit ning 255 maksimaalsel kiirusel liikuvat mootorit.
  
 <code c> <code c>
Line 63: 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 75: 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 106: 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 119: 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 130: 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 142: 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.1367222652.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