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 15:36] 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 122: Line 125:
 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 prescaler, for 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 recommended, because it makes the motor rotation intermittent, and generates vibration. 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 prescaler, for 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 recommended, because 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.1447256199.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