• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Regulacja obrotów
#1
Witam
Jestem początkującym urzytkownikiem. Naszło mnie na zrobienie kontrolera temp w PC. Chiałbym prędkość wiatraków regulować za pomocą arduino, pomijając potencjometr fizyczny. Znalazłem tutaj schemat który to teoretycznie umożliwia lecz wyświetla kosmiczne wartości RPM i nie wiem jak sterować obrotami. Obecnie działa na Uno lecz wolał bym to mieć na nano. Poniżej zamieszczam kod oraz schemat
Kod:
/* -------------------------------------------
/* CPU-Lüfter Steuern und messen
/* www.frag-duino.de
/* -------------------------------------------
/* Befehle:
/* 0-10 --> Länge des HIGH-Signals in ms*10
/* Langsam nach schnell: 1,2,3,4,5,6,7,8,9
/* 0 fuer STOP
------------------------------------------- */

// PINs
#define PIN_BLAU 6
#define PIN_YELLOW 2
#define INTERRUPT_GELB 0  // Interrupt 0 == Pin 2
#define UPDATE_ZYKLUS 1000 // Jede Sekunde 1 ms Ausgabe der Geschwindigkeit.
const int ANZAHL_INTERRUPTS = 1; // Anzahl der Interrupts pro Umdrehung (1 oder 2)

// Variablen
int counter_rpm = 0;
int rpm = 0;
unsigned long letzte_ausgabe = 0;
char eingabe;
int dauer_low = 1;
int dauer_high = 9;
int baseTime = 10; // Insgesamt 10 ms

void setup()
{
 // Initialisieren
 Serial.begin(9600);
 pinMode(PIN_BLAU, OUTPUT);
   pinMode(PIN_YELLOW, INPUT);
 digitalWrite(PIN_YELLOW, HIGH);
 attachInterrupt(INTERRUPT_GELB, rpm_fan, FALLING);
}

void loop(){

 if(dauer_low * 10 != 0){
   digitalWrite(PIN_BLAU, LOW);
   delayMicroseconds(dauer_low * 10);
 }

 if(dauer_high * 10 != 0){
   digitalWrite(PIN_BLAU, HIGH);
   delayMicroseconds(dauer_high * 10);
 }

 if (Serial.available()){
   eingabe = Serial.read() - 48; // ASCII 0-9 lesen
   if(eingabe == 0)
     eingabe = 10;
   else
     eingabe = 10 - eingabe;

   dauer_low = eingabe;
   dauer_high = baseTime - eingabe;
   Serial.print("Dauer des HIGH: ");
   Serial.println(dauer_high);
 }

 if (millis() - letzte_ausgabe >= UPDATE_ZYKLUS){
   // Interrupt deaktivieren um das rechnen nicht zu unterbrechen.
   detachInterrupt(0);

   // RPM errechnen und ausgeben:
   rpm = counter_rpm * (60 / ANZAHL_INTERRUPTS);
   Serial.print("RPM: ");
   Serial.println(rpm);

   // Counter zuruecksetzen
   counter_rpm = 0;

   // Zeitpunkt setzen
   letzte_ausgabe = millis();

   // Interrupt wieder aktivieren
   attachInterrupt(0, rpm_fan, FALLING);
 }
}


// Interrupt zaehlt den RPM-Counter hoch
void rpm_fan(){
 counter_rpm++;
}

[Obrazek: fan_schaltung.png]
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości