Commit 66da6c04 authored by Oleg Nikulin's avatar Oleg Nikulin

Автономный режим по датчику температуры

parent b897dc99
#include "crc.h"
#include "functions.h"
#define STANDALONE_MODE
#define FAN_COUNT 6 //Количество вентиляторов
#define CONTROL_COUNT 3 //Количество групп управления
#define BAUDRATE 19200 //Скорость serial порта
......@@ -20,6 +23,7 @@
#define SOUND_PIN 10 //Номер пина пищалки
#define LED_PIN 13 //Номер пина светодиода
#define TEMP_SENSOR_PIN A7 //Номер пина датчика температуры
typedef int16_t temp_t;
......@@ -202,6 +206,7 @@ uint16_t get_avg_rpm(fan* fan_ptr) {
}
#ifdef STANDALONE_MODE
void process_command() {
uint8_t cmd_buffer[32] = {};
uint8_t cmd_length = 0;
......@@ -308,7 +313,7 @@ void process_command() {
response_length = add_crc(response_buffer, response_length);
Serial.write(response_buffer, response_length); //посылаем ответ
}
#endif
void rpm_control() {
......@@ -388,6 +393,27 @@ void set_duty_cycle(control &fanControl, int duty_cycle) {
}
#ifdef STANDALONE_MODE
temp_t measure_temperature()
{
uint32_t raw = analogRead(TEMP_SENSOR_PIN);
//при 0C напряжение 1.313 В = 268.6398 raw
//при 25C напряжение 2.5 В = 511.5 raw
//при 50C напряжение 3.542 В = 724.6932 raw
//при 75C напряжение 4.201 В = 859.5246 raw
//при 100C напряжение 4.562 В = 933.3852 raw
const float k1 = 0.000000000745;
const float k2 = -0.000001382666;
const float k3 = 0.000933335338;
const float k4 = -0.165828524805;
float temperature = k1*raw*raw*raw*raw + k2*raw*raw*raw + k3*raw*raw + k4*raw;
return (temp_t)round(temperature);
}
#endif
ISR(TIMER1_COMPA_vect) { //Функция, вызываемая при прерывании 1A
......@@ -454,6 +480,7 @@ ISR(TIMER2_OVF_vect) { //Функция, вызываемая при переп
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(SOUND_PIN, OUTPUT);
pinMode(TEMP_SENSOR_PIN, INPUT);
for (int i = 0; i < CONTROL_COUNT; i++) {
pinMode(controls[i].pin, OUTPUT);
......@@ -486,7 +513,31 @@ void setup() {
set_duty_cycle(controls[i], DEFAULT_PWM_DUTY_CYCLE);
}
#ifdef STANDALONE_MODE
control_a.target_temperature = 28;
control_b.target_temperature = 31;
control_c.target_temperature = 33;
control_a.overheat_temperature = 60;
control_b.overheat_temperature = 60;
control_c.overheat_temperature = 60;
control_a.copy_from = 255;
control_b.copy_from = 255;
control_c.copy_from = 255;
control_a.min_duty_cycle = 0;
control_b.min_duty_cycle = 0;
control_c.min_duty_cycle = 0;
control_a.max_duty_cycle = 255;
control_b.max_duty_cycle = 255;
control_c.max_duty_cycle = 255;
initialized = true;
#else
Serial.begin(BAUDRATE);
#endif
}
......@@ -494,10 +545,19 @@ void setup() {
void loop() {
#ifdef STANDALONE_MODE
temp_t temperature = measure_temperature();
control_a.temperature = temperature;
control_b.temperature = temperature;
control_c.temperature = temperature;
#else
if (Serial.available() > 0)
{
process_command();
}
#endif
if (initialized)
{
......@@ -506,10 +566,12 @@ void loop() {
}
}
#ifndef STANDALONE_MODE
if (pc_poll_interval_sec != -1 && uint32_t(millis() - last_poll_time) >= pc_poll_interval_sec * 2 * 1000) {
pc_respond = false;
}
#endif
if (control_a.temperature >= control_a.overheat_temperature || control_b.temperature >= control_b.overheat_temperature || control_c.temperature >= control_c.overheat_temperature ) { //Если перегрев, включается пищалка
if (millis() >= last_beep_time + BEEP_INTERVAL * 2) {
analogWrite(SOUND_PIN, BEEP_STRENGTH);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment