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_speed [2012/05/18 08:50] raivo.sellen:examples:motor:dc_speed [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 29: Line 29:
 P = I × Vq, and if Vq = 0 also P = 0 W P = I × Vq, and if Vq = 0 also P = 0 W
  
-This means that almost no power is consumed by transistor when it is ON state. Similar situation is also when transistor is closed (OFF state). In this situation nealy no current  flows through the motor and transistor. Calculating the power consumed by transistor once again:+This means that almost no power is consumed by transistor when it is ON state. Similar situation is also when transistor is closed (OFF state). In this situation nearly no current  flows through the motor and transistor. Calculating the power consumed by transistor once again:
  
  
 P = I × Vq, and if I = 0 also P = 0 W P = I × Vq, and if I = 0 also P = 0 W
  
-As a conclusion, when transistor operates only on and off states the efficency 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 consumbed 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.+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.
  
  
Line 47: Line 47:
  
 <code c> <code c>
-// 
-// The setup of the pins driving pins. 
-// 
 static pin dcmotor_pins[4][2] = static pin dcmotor_pins[4][2] =
 { {
Line 58: Line 55:
 }; };
  
 +static int motorindex[4][2] =
 +{
 + { 0, 1 },
 + { 2, 3 },
 + { 4, 5 },
 + { 6, 7 }
 +};
  
-// 
 // Initialize PWM for specified DC motor.  // Initialize PWM for specified DC motor. 
-// 
 void dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler) void dcmotor_drive_pwm_init(unsigned char index, timer2_prescale prescaler)
 { {
Line 87: Line 89:
  sei();  sei();
 } }
- 
  
 void dcmotor_drive_pwm(unsigned char index, signed char direction, unsigned char speed)  void dcmotor_drive_pwm(unsigned char index, signed char direction, unsigned char speed) 
 { {
- static int motorindex[4][2] = 
- { 
- { 0, 1 }, 
- { 2, 3 }, 
- { 4, 5 }, 
- { 6, 7 } 
- }; 
-  
  if(direction == -1)  if(direction == -1)
  {  {
- compbuff[motorindex[index,0]] = 0x00; + compbuff[motorindex[index][0]] = 0x00; 
- compbuff[motorindex[index,1]] = speed;+ compbuff[motorindex[index][1]] = speed;
  }  }
  if(direction == 1)  if(direction == 1)
  {  {
- compbuff[motorindex[index,0]] = speed; + compbuff[motorindex[index][0]] = speed; 
- compbuff[motorindex[index,1]] = 0x00;+ compbuff[motorindex[index][1]] = 0x00;
  
 } }
Line 120: Line 113:
  
 <code c> <code c>
-// +
-// Desc.: DC motor speed control +
-// Hardware: ATMega2561 Controller board, Motor board with DC motor +
-// Author: Raivo Sell, 2012 +
-//+
 #include <homelab/delay.h> #include <homelab/delay.h>
 #include <homelab/module/motors.h> #include <homelab/module/motors.h>
Line 130: Line 119:
 int main(void) int main(void)
 { {
- 
  // DC motor 0 init with no prescaler  // DC motor 0 init with no prescaler
   dcmotor_drive_pwm_init(0, TIMER2_NO_PRESCALE);   dcmotor_drive_pwm_init(0, TIMER2_NO_PRESCALE);
Line 136: Line 124:
   while(1)   while(1)
   {       {   
-  +  // DC motor drive with half of the nominal speed
- // DC motor drive with half of the nominal speed+
  dcmotor_drive_pwm(0, 1, 128);         dcmotor_drive_pwm(0, 1, 128);       
   }   }
Line 146: Line 133:
  
 <code c> <code c>
-// 
-// Desc.: DC motor speed control with potentiometer 
-// Hardware: ATMega2561 Controller board, Motor board with DC motor, Sensor board 
-// Author: Raivo Sell, 2012 
-// 
-#include <homelab/delay.h> 
  
 +#include <homelab/delay.h>
 #include <homelab/module/motors.h> #include <homelab/module/motors.h>
 #include <homelab/adc.h> #include <homelab/adc.h>
Line 173: Line 155:
  
  // DC motor drive with speed from potentiometer  // DC motor drive with speed from potentiometer
- // As potentiometer has 10-bit output but DC motor drive function + // As potentiometer has 10-bit output but DC motor drive  
- // 8-bit input the adc output have to be converted to 8-bit + // function 8-bit input the adc output have to be converted  
- // e.g dividing the output with 4, or shifting bit 2 position >>2+ // to 8-bit e.g dividing the output with 4, or shifting bit  
 + // 2 position >>2
  dcmotor_drive_pwm(0, 1, speed/4);  dcmotor_drive_pwm(0, 1, speed/4);
   }   }
 } }
 </code> </code>
en/examples/motor/dc_speed.1337331002.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