считывание и регулеровка скорости вращения кулера
- Войдите на сайт для отправки комментариев
Пнд, 26/12/2016 - 12:59
Приветствую!
Нужно считывать обороты с трехпроводного кулера и регулировать обороты. Считывать обороты получается, регулировать получается, но все по отдельности. Если все совместить и регулировать обороты резистором, показатель оборотов не реально скачет в терминале. Реально обороты кулера нормально регулируются.

volatile int val;
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin; // Analog output pin that the LED is attached to
int FAN = 9;
//int FAN_pwm = 100; // PWM 0..255
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
TCCR1B = TCCR1B & B11111000 | B00000001; // set timer 1 divisor to 1 for PWM frequency of 31372.55 Hz - D9-D10
//TCCR2B = TCCR2B & B11111000 | B00000001; // set timer 2 divisor to 1 for PWM frequency of 31372.55 Hz - D3, D11
//TCCR0B = TCCR0B & B11111000 | B00000001;
pinMode(FAN, OUTPUT);
Serial.begin(9600);
attachInterrupt(0, rpm, CHANGE);
}
void loop() {
analogread();
val = 0; // сбрасываем счетчик и ждем.
delay(500); // так как прерывание CHANGE, срабатывает два раза
// то и считываем каждые пол секунды.
Serial.print((val*60)/2); // количество импульсов на 60 секунд
// и делим на количество импульсов на оборот
Serial.print(" rpm ");
Serial.print(val);
Serial.println(" val");
Serial.println();
// read the analog in value:
}
void analogread(){
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
analogWrite(FAN, outputValue);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
// delay(2);
}
http://arduino.ru/forum/programmirovanie/schityvanie-oborotov-komp-kulera