136 lines
3.8 KiB
C
136 lines
3.8 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 SMCmdLogic.c
|
|
\brief Îáðàáîòêà êîìàíä è çàäàíèé, ïîñòóïàþùèõ èç ðàçëè÷íûõ èñòî÷íèêîâ. (ñì. TSM_CmdLogic)
|
|
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
|
|
\version v 2.0 25/03/2016
|
|
|
|
\addtogroup SMCmdLogic
|
|
@{*/
|
|
|
|
#include "DSP.h"
|
|
#include "V_IQmath.h"
|
|
#include "main.h"
|
|
|
|
//!Èíèöèàëèçàöèÿ
|
|
|
|
//!Âñÿêèå îáíóëåíèÿ...
|
|
//! \memberof TSM_CmdLogic
|
|
void SM_CmdLogicInit(TSM_CmdLogic *p) {
|
|
p->state = 0;
|
|
p->state_prev = 0xFF;
|
|
cmd.all = 0;
|
|
}
|
|
|
|
//!Ìåäëåííûé ðàñ÷åò
|
|
|
|
//! \memberof TSM_CmdLogic
|
|
void SM_CmdLogicSlow_Calc(TSM_CmdLogic *p) {
|
|
|
|
}
|
|
|
|
//!1êÃö ðàñ÷åò
|
|
|
|
//!Îáðàáîòêà ðàçëè÷íûõ èñòî÷íèêîâ êîìàíä è ðàñ÷åò ÄÀ,
|
|
//!êîòîðûé ïåðåêëþ÷àåò ãëîáàëüíî ðåæèìû ÐÀÁÎÒÀ è ÎÑÒÀÍÎÂ.
|
|
//! \memberof TSM_CmdLogic
|
|
void SM_CmdLogicms_Calc(TSM_CmdLogic *p) {
|
|
p->StartButton = STARTBUTTON; //îáðàáîòêà íîæêè ñòàðòà
|
|
p->StopButton = STOPBUTTON; //îáðàáîòêà íîæêè ñòîïà
|
|
p->ResetButton = RESETBUTTON;
|
|
|
|
//Ñòàíäàðòíàÿ îáðàáîòêà äèñêðåòíîãî àâòîìàòà
|
|
if (p->state_prev != p->state)
|
|
p->E = 1;
|
|
else
|
|
p->E = 0;
|
|
p->state_prev = p->state;
|
|
|
|
#if defined (HW_MCB3)
|
|
if ((p->StartButton==1) && (p->StartButtonPrev==0)){
|
|
cmd.bit.start=1;//êîìàíäà íà çàïóñê. Îíà æå ñòàâèòñÿ ÷åðåç CAN
|
|
}
|
|
if ((p->StopButton==1) && (p->StopButtonPrev==0)){
|
|
cmd.bit.stop=1;
|
|
}
|
|
p->StartButtonPrev=p->StartButton;
|
|
p->StopButtonPrev=p->StopButton;
|
|
p->ResetButtonPrev = p->ResetButton;
|
|
#endif
|
|
|
|
//îïðåäåëÿåì ðåæèì ðàáîòû
|
|
switch (p->state) {
|
|
case CMD_LOGIC_TURNED_OFF: { //ñîñòîÿíèå 0- ÎÒÊËÞ×ÅÍ
|
|
if (p->E == 1) {
|
|
/*ENTRY*/
|
|
sm_ctrl.state = CTRL_STOP;
|
|
drv_status.bit.ready = 1;
|
|
drv_status.bit.running = 0;
|
|
}
|
|
|
|
if (sm_prot.state == PROT_ON_OK) {//åñëè ÄÀ çàùèò âêëþ÷èëñÿ, îáðàáàòûâàåì êîìàíäû âêëþ÷åíèÿ
|
|
if ((cmd.bit.start == 1) && (sm_sys.state == SYS_READY)) {//åñòü áèòîâàÿ êîìàíäà ñòàðòà
|
|
if (udControl.Enabled == 0) { //Åñëè öåïü ïëàâíîãî çàðÿäà ÇÏÒ îòêëþ÷åíà, òî ïåðåõîäèì ê ïóñêó
|
|
p->state = CMD_LOGIC_TURNED_ON; //ïîåõàëè
|
|
}
|
|
else {
|
|
if (udControl.StateOn == 1) { //Åñëè öåïü ïëàâíîãî çàðÿäà ÇÏÒ âêëþ÷åíà, æäåì ñðàáàòûâàíèÿ ðåëå, à ïîòîì çàïóñêàåì
|
|
p->state = CMD_LOGIC_TURNED_ON; //ïîåõàëè
|
|
}
|
|
else {
|
|
udControl.fault_start = 1; //åñëè ïûòàåìñÿ ïóñòèòñÿ ïðè íåçàøóíòèðîâàííîì ðåëå, ïîïàäàåì â àâàðèþ
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//äèñêðåòíûé àâòîìàò ñî ñòðóêòóðàìè óïðàâëåíèÿ â ÑÒÎÏå âñåãäà òîæå ïðèíóäèòåëüíî ïåðåâîäèì â ñòîï
|
|
sm_ctrl.state = CTRL_STOP;
|
|
//âñåãäà ñáðàñûâàåì áèòîâûå êîìàíäû óïðàâëåíèÿ
|
|
cmd.bit.stop = 0;
|
|
cmd.bit.start = 0;
|
|
break;
|
|
}
|
|
|
|
case CMD_LOGIC_TURNED_ON: { //ñîñòîÿíèå - ÐÀÁÎÒÀ
|
|
if (p->E == 1) {
|
|
/*ENTRY*/
|
|
drv_status.bit.ready = 1;
|
|
drv_status.bit.running = 1;
|
|
sm_ctrl.state = CTRL_RUN;//ïîåõàëè
|
|
}
|
|
//åñëè ÀÂÀÐÈÿ èëè ÊÎÌÀÍÄÀ ÑÒÎÏ òî ñîñòîÿíèå ñòîï
|
|
if ((sm_prot.state == PROT_FAIL) || (cmd.bit.stop == 1)
|
|
|| (sm_ctrl.state == CTRL_STOP)){
|
|
p->state = CMD_LOGIC_TURNED_OFF;
|
|
}
|
|
|
|
//âñåãäà ñáðàñûâàåì êîìàíäó óïðàâëåíèÿ
|
|
cmd.bit.stop = 0;
|
|
cmd.bit.start = 0;
|
|
break;
|
|
}
|
|
|
|
default: { //íà âñÿêèé ñëó÷àé äåëàåì ðåæèì ïî-óìîë÷àíèþ "âûêëþ÷åí"
|
|
p->state = CMD_LOGIC_TURNED_OFF;
|
|
break;
|
|
}
|
|
|
|
} // êîíåö switch(p->state)
|
|
}
|
|
|
|
/*@}*/
|