sábado, 8 de febrero de 2014

Oscilador lineal

el siguiente programa controla el motor DC de una impresora a través de la señal de un potenciómetro

const int LeftAnalogOutPin = 9;
const int RightAnalogOutPin = 10;
int outputValue = 0;
int TiempoQueDuraLaCondicion =1;
//int Incrementos=8;
int sensorPin=A0;
int sensorValue=0;

void setup() { }
void loop() {
  sensorValue = analogRead(sensorPin);
  int Incrementos=map(sensorValue,0,1023,2,10);
  for (int thisPin = 41; thisPin <= 255; thisPin+=Incrementos+1) {
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);                
  }
   for (int thisPin = 255; thisPin >= 1; thisPin-=Incrementos) {
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);
  }
  analogWrite(LeftAnalogOutPin,0);
  for (int thisPin = 41; thisPin <= 255; thisPin+=Incrementos+2) {
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);                
  }
  for (int thisPin = 255; thisPin >= 1; thisPin-=Incrementos) {
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);
  }                  
  analogWrite(RightAnalogOutPin,0);
}

domingo, 2 de febrero de 2014

DC Motor controlled by Arduino UNO - speed ramp and reversing rotation

The Arduino program shown below let us change angular speed and reverse rotation to a little DC motor removed from a DeskPrinter.
For controlling the sense of rotation I used an H-Bridge, L293NE, who requires high speed diodes (SES5001) for being protected from motor's coils intensity. Anyway, I didn't find such high speed diodes (100ns=trr) so I used the 1N4007; but as the DC Motor is turning free, without any mechanical charge, I believe the response from DC motor internal coil is not doing any damage to the IC.

From datasheet, the diagram is mounted as follows. The blue areas have not been connected:
The whole system has been tested on a breadboard as shown on the picture.

The program developed directly in a easy and confortable way is as follows. The analog ouputs used from Arduino UNO are 9 and 10. The angular speed is controlled through PWM outputs.
The acceleration when turning is reached through increments on the for loop i.e.+=1
Furthermore, the delay on each loop inside the for structure decrease the angular acceleration linked directly to the increments +=1 referred before.
The initial value to be "written" when increasing from speed 0 rad/s should be greater than 1, as it has been experienced the motor doesn't starts to move until the value is more than 30. This value is still low, so I write a 41...

const int LeftAnalogOutPin = 9; 
const int RightAnalogOutPin = 10; 
int outputValue = 0;       
void setup() { }
void loop() {
  for (int thisPin = 41; thisPin < 255; thisPin+=1) { 
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);   
    delay(50);                  
  }
   for (int thisPin = 255; thisPin >= 1; thisPin-=1) { 
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);   
    delay(50); 
  }
  analogWrite(LeftAnalogOutPin,0);
  for (int thisPin = 41; thisPin < 255; thisPin+=1) { 
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);   
    delay(50);                  
  }
  for (int thisPin = 255; thisPin >= 1; thisPin-=1) { 
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);   
    delay(50); 
  }                   
  analogWrite(RightAnalogOutPin,0);
}

The next video shows how everything was mounted and the DC motor turning.