/*! 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_DIO.c \brief Ìîäóëü äèñêðåòíûõ âõîäîâ/âûõîäîâ \author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru \version v 1.0 25/08/2017 \addtogroup @{*/ #include "main.h" #include "filter.h" // Âåêòîð ñîñòîßíèß äèñêðåòíûõ âûõîäîâ volatile Uint16 output_vect = 0; // Ìàñêà èíâåðòèðîâàíèß âåêòîðà ñîñòîßíèß äèñêðåòíûõ âûõîäîâ volatile Uint16 output_mask = 0; // Âåêòîð ñîñòîßíèß äèñêðåòíûõ âõîäîâ volatile Uint16 input_vect = 0; // Ìàñêà èíâåðòèðîâàíèß âåêòîðà ñîñòîßíèß äèñêðåòíûõ âõîäîâ volatile Uint16 input_mask = 0; // Êîýôôèöèåíò ôèëüòðàöèè äèñêðåòíûõ âõîäîâ Kf = 0.001/Tô // (Tô - ïîñòîßííàß âðåìåíè ôèëüòðà, ñåê) volatile _iq inputKf = _IQ(0.03); //Âðåìÿ ñðàáàòûâàíèÿ ñîñòàâëÿåòñÿ 60ìñ ïðè inputKf=_IQ(0.03) è inputOn = _IQ(0.8) â 1êÃö ïðåðûâàíèè; // Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå OFF (0) volatile _iq inputOff = _IQ(0.3); // Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå ON (1) volatile _iq inputOn = _IQ(0.8); // Ïðîìåæóòî÷íûé âåêòîð ñîñòîßíèß äèñêðåòíûõ âõîäîâ (áåç ó÷¸òà ìàñêè èíâåðòèðîâàíèß) Uint16 input = 0; // Ôèëüòðû äèñêðåòíûõ âõîäîâ TFilter fIn1 = FILTER_DEFAULTS; TFilter fIn2 = FILTER_DEFAULTS; TFilter fIn3 = FILTER_DEFAULTS; void DIO_Init() { } void DIO_slow_calc() { // Ïîëó÷àåì âåêòîð ñîñòîßíèß äèñêðåòíûõ âûõîäîâ ñ ó÷¸òîì ìàñêè èíâåðòèðîâàíèß Uint16 output = output_vect ^ output_mask; // Âûâîäèì óïðàâëßþùåå âîçäåéñòâèå ïî Âûõîäó 1 if (BIT_IS_SET(output, 0)) D_OUT1_OFF; else D_OUT1_ON; // Âûâîäèì óïðàâëßþùåå âîçäåéñòâèå ïî Âûõîäó 2 if (BIT_IS_SET(output, 1)) D_OUT2_OFF; else D_OUT2_ON; // Âûâîäèì óïðàâëßþùåå âîçäåéñòâèå ïî Âûõîäó 3 if (BIT_IS_SET(output, 2)) D_OUT3_OFF; else D_OUT3_ON; // Îáíîâëßåì êîýôôèöèåíòû ôèëüòðàöèè äèñêðåòíûõ âõîäîâ fIn1.T = inputKf; fIn2.T = inputKf; fIn3.T = inputKf; // Ïîëó÷àåì ñîñòîßíèå Âõîäà 1 ñ ó÷¸òîì ôèëüòðàöèè if (fIn1.output > inputOn) SET_BIT(input, 0); if (fIn1.output < inputOff) CLEAR_BIT(input, 0); // Ïîëó÷àåì ñîñòîßíèå Âõîäà 2 ñ ó÷¸òîì ôèëüòðàöèè if (fIn2.output > inputOn) SET_BIT(input, 1); if (fIn2.output < inputOff) CLEAR_BIT(input, 1); // Ïîëó÷àåì ñîñòîßíèå Âõîäà 3 ñ ó÷¸òîì ôèëüòðàöèè if (fIn3.output > inputOn) SET_BIT(input, 2); if (fIn3.output < inputOff) CLEAR_BIT(input, 2); input_vect = input ^ input_mask; } void DIO_fast_calc() { // Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 1 fIn1.input = (D_IN1 == 1) ? _IQ(1.0) : 0; fIn1.calc(&fIn1); // Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 2 fIn2.input = (D_IN2 == 1) ? _IQ(1.0) : 0; fIn2.calc(&fIn2); // Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 3 fIn3.input = (D_IN3 == 1) ? _IQ(1.0) : 0; fIn3.calc(&fIn3); } /*@}*/