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
en:examples:motor:dc [2015/11/11 14:25] heikopikneren:examples:motor:dc [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~PB~~+<pagebreak>
 ====== DC motor ====== ====== DC motor ======
  
-//Necessary knowledge: [HW] [[en:hardware:homelab:motor]], [AVR] [[en:avr:io]], [LIB] [[en:software:homelab:library:module:motor]], [LIB] [[en:software:homelab:library:delay]]//+//Necessary knowledge:  
 +[HW] [[en:hardware:homelab:digi]], [HW] [[en:hardware:homelab:combo]], 
 +[AVR] [[en:avr:timers]], [AVR] [[en:avr:adc]],  
 +[LIB] [[en:software:homelab:library:module:motor]], [LIB] [[en:software:homelab:library:adc]]//
  
 ===== Theory ===== ===== Theory =====
Line 61: Line 64:
  
 <code c> <code c>
-// The setup of the pins driving pins.+// The setup of the pins driving pins
 static pin dcmotor_pins[4][2] = static pin dcmotor_pins[4][2] =
 { {
Line 87: Line 90:
   pwm = PWMDEFAULT;   pwm = PWMDEFAULT;
    
-  // Kõigi kanalite käivitamine+  // Starting all channels
   for(i=0 ; i<CHMAX ; i++)   for(i=0 ; i<CHMAX ; i++)
   {   {
-      // PWM-i algväärtustamine+      // PWM state variable initialization
       compare[i] = pwm;                  compare[i] = pwm;           
       compbuff[i] = pwm;                 compbuff[i] = pwm;          
   }   }
    
-  // Timer 2 normaalrežiimis käivitamine+  // Starting Timer 2 to normal mode
   timer2_init_normal(prescaler);   timer2_init_normal(prescaler);
-  // Timer 2 katkestuste lubamine+  // Allow Timer 2 interrupt
   timer2_overflow_interrupt_enable(true);   timer2_overflow_interrupt_enable(true);
    
-  // Globaalsete katkestuste lubamine+  // Enable global interrupts
   sei();   sei();
 } }
Line 120: Line 123:
 </code> </code>
  
-With the array //dcmotor_pins// in the library, the controlling pins of four motor-controllers are determined. Before controlling the motors, function //dcmotor_init// with the number of the motor-controller (0 – 3) must be called out. It sets the pins as output. For controlling is the function //dcmotor_drive//with it the negative //direction// parameter is used to give to the motor one revolving direction and other direction with positive parameterand 0 if the motor is stopped.+The controlling pins of four motor-controllers are determined with the array dcmotor_pins in the library. Before controlling the motors, function dcmotor_drive_pwm_init with the number of the motor-controller (0 – 3) must be called out. It sets the pins as output. It should also set the timer prescalerfor HomeLab II timer2_prescale and for HomeLab III timer_prescale, which determines the frequency of the PWM signal. In case of HomeLab II, as the program does not have functions which are using timer, it is appropriate for the value TIMER2_NO_PRESCALE. When for example an ultrasound sensor are used, then should be chosen TIMER2_PRESCALE 8, otherwise the controller performance may not be sufficient and the sensor readings may be corrupted. This is not applying in the HomeLab III. Higher values of the prescaler are not recommendedbecause it makes the motor rotation intermittent, and generates vibration.
  
-The following is an example program which controls first and second DC motor so that they alter their revolving direction after every second. The speed could be controlled if one controlling pin were modulated with PWM signal.+Function dcmotor_drive_pwm is for control motor speed. This function need three input values: motor number, direction (-1, 0, +1), where -1 is the rotation in one direction, +1 other direction and 0 for stop and thirdly, the speed range of 0-255. The speed value is not linked to a specific rotational speed, it is the relative value between minimal and maximal motor speed. Motor actual speed depends on the motor type, load and the supply voltage. Motor speed accuracy is 8-bits, which means that the minimum control accuracy is 1/255 of the maximum engine speed. 
 + 
 +The following is an example program which controls first and second DC motor so that first motor rotates half of the speed and the second motor speed is controlled by a potentiometer.
  
 <code c> <code c>
en/examples/motor/dc.1447251929.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