motorcontroldemo_028/Vsrc/V_Fan.c

88 lines
2.5 KiB
C

/*!
Copyright 2017 ÀÎ "ÍÈÈÝÒ" è ÎÎÎ "ÍÏÔ ÂÅÊÒÎÐ"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\file V_Fan.c
\brief Ìîäóëü ðàáîòû âåíòèëÿòîðà
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 1.0 25/08/2017
\addtogroup
@{*/
#include "main.h"
//! \memberof TFanControl
void FanControl_init(TFanControl *p)
{
#if defined (HW_MCB3)
p->Enabled = 1; //Âêëþ÷àåì áëîê âåíòèëÿòîðà
//Ïðîèíèòèì âûõîä äëÿ óïðàâëåíèÿ âåíòèëÿòîðîì â GpioPeripheralInit
#endif
}
//! \memberof TFanControl
void FanControl_slow_calc(TFanControl *p) {
if (p->Enabled){//åñëè åñòü âåíòèëÿòîð
//ñ÷èòàåì äèñêðåòíûé àâòîìàò
p->state_shadow = p->state;
p->state_prev = p->state_shadow;
switch (p->state_shadow) {
case FAN_CONTROL_STATE_OFF: //âåíòèëÿòîð íå ðàáîòàåò, òåìïåðàòóðà èíâåðòîðà ìåíüøå T_on
{
FAN_OFF; //
p->StateOn = 0; //
if (adc.T_meas > p->T_on) //
p->state = FAN_CONTROL_STATE_ON; //
break;
}
case FAN_CONTROL_STATE_ON: //âêëþ÷åíèå âåíòèëÿòîðà, òåìïåðàòóðà áîëüøå T_on è ìåíüøå T_alarm
{
FAN_ON; //âêëþ÷èòü âåíòèëÿòîð
p->StateOn = 1; //ñîñòîÿíèå ðàáîòû
if (adc.T_meas > p->T_alarm) //åñëè òåìïåðàòóðà ïîäíÿëàñü åùå áîëüøå, ïåðåõîäèì â ðåæèì ïåðåãðåâà
p->state = FAN_CONTROL_STATE_OVERHEAT;
if (adc.T_meas < p->T_off) //åñëè òåìïåðàòóðà îïóñòèëàñü íèæå çàäàííîãî óðîâíÿ, ïåðåõîäèì â îáû÷íûé ðåæèì
p->state = FAN_CONTROL_STATE_OFF;
break;
}
case FAN_CONTROL_STATE_OVERHEAT: //òåìïåðàòóðà áîëüøå T_alarm, âåíòèëÿòîð ðàáîòàåò, âûâîäèòñÿ ïðåäóïðåæäåíèå î ïåðåãðåâå
{
FAN_ON; //âêëþ÷èòü âåíòèëÿòîð
p->StateOn = 1; //ñîñòîÿíèå ðàáîòû
drv_status.bit.overheat = 1; //âûâîä ïðåäóïðåæäåíèÿ î ïåðåãðåâå
if (adc.T_meas < p->T_alarm) { //åñëè òåìïåðàòóðà îïóñòèëàñü íèæå çàäàííîãî óðîâíÿ, ïåðåõîäèì â îáû÷íûé ðåæèì
drv_status.bit.overheat = 0; //ñáðîñ ïðåäóïðåæäåíèÿ î ïåðåãðåâå
p->state = FAN_CONTROL_STATE_ON;
}
break;
}
}
}
}
/*@}*/