motorcontroldemo_028/Vsrc/V_DIO.c

126 lines
3.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_DIO.c
\brief Ìîäóëü äèñêðåòíûõ âõîäîâ/âûõîäîâ
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 2.0 25/09/2019
\addtogroup
@{*/
#include "main.h"
#include "filter.h"
// Äåôàéíèì äèñêðåòíûå âõîäû
#ifdef HW_MCB3
#define D_IN0 ((GPIOM->DATA & (1 << 13)) == 0) //M13 Ñòàðò
#define D_IN1 ((GPIOM->DATA & (1 << 11)) == 0) //M11 Ñòîï
#define D_IN2 ((GPIOM->DATA & (1 << 10)) == 0) //M10 Ñáðîñ àâàðèé
#else
#define D_IN0 0
#define D_IN1 0
#define D_IN2 0
#endif
// Äåôàéíèì äèñêðåòíûå âûõîäû
#ifdef HW_MCB3
#define D_OUT0_ON GPIOD->DATAOUTSET = GPIO_PIN_1
#define D_OUT0_OFF GPIOD->DATAOUTCLR = GPIO_PIN_1
#define D_OUT1_ON GPIOD->DATAOUTSET = GPIO_PIN_2
#define D_OUT1_OFF GPIOD->DATAOUTCLR = GPIO_PIN_2
#define D_OUT2_ON GPIOM->DATAOUTSET = GPIO_PIN_14
#define D_OUT2_OFF GPIOM->DATAOUTCLR = GPIO_PIN_14
#else
#define D_OUT0_ON
#define D_OUT0_OFF
#define D_OUT1_ON
#define D_OUT1_OFF
#define D_OUT2_ON
#define D_OUT2_OFF
#endif
void DIO_init(TDIO* p)
{
//Íàñòðîéêà êîýôôèöèåíòîâ ôèëüòðàöèè è ïîðîãîâ ñðàáàòûâàíèÿ äëÿ äèñêðåòíûõ âõîäîâ
p->inputKf = _IQ(0.03);
p->inputOff = _IQ(0.2);
p->inputOn = _IQ(0.8);
//Âðåìÿ âêëþ÷åíèÿ/îòêëþ÷åíèÿ ïðè êîýôôèöèåíòàõ inputKf=_IQ(0.2), inputOn = _IQ(0.8), inputKf = _IQ(0.03) áóäåò ñîñòàâëÿòü ïðèìåðíî 60 ìñ (ôèëüòðû ñ÷èòàþòñÿ â 1êÃö ïðåðûâàíèè)
}
void DIO_slow_calc(TDIO* p)
{
// Îáíîâëßåì êîýôôèöèåíòû ôèëüòðàöèè äèñêðåòíûõ âõîäîâ
p->fIn0.T = p->inputKf;
p->fIn1.T = p->inputKf;
p->fIn2.T = p->inputKf;
}
void DIO_ms_calc(TDIO* p)
{
//------------------------Îáðàáîòêà âõîäîâ------------------------------//
// Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 0
p->fIn0.input = (D_IN0 == 1) ? _IQ(1.0) : 0;
p->fIn0.calc(&(p->fIn0));
// Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 1
p->fIn1.input = (D_IN1 == 1) ? _IQ(1.0) : 0;
p->fIn1.calc(&(p->fIn1));
// Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 2
p->fIn2.input = (D_IN2 == 1) ? _IQ(1.0) : 0;
p->fIn2.calc(&(p->fIn2));
// Ïîëó÷àåì ñîñòîßíèå Âõîäà 0 ñ ó÷¸òîì ôèëüòðàöèè
if (p->fIn0.output > p->inputOn) p->in_bit.n0 = 1;
if (p->fIn0.output < p->inputOff) p->in_bit.n0 = 0;
// Ïîëó÷àåì ñîñòîßíèå Âõîäà 1 ñ ó÷¸òîì ôèëüòðàöèè
if (p->fIn1.output > p->inputOn) p->in_bit.n1 = 1;
if (p->fIn1.output < p->inputOff) p->in_bit.n1 = 0;
// Ïîëó÷àåì ñîñòîßíèå Âõîäà 2 ñ ó÷¸òîì ôèëüòðàöèè
if (p->fIn2.output > p->inputOn) p->in_bit.n2 = 1;
if (p->fIn2.output < p->inputOff) p->in_bit.n2 = 0;
//------------------------Îáðàáîòêà âûõîäîâ------------------------------//
// Âûâîäèì óïðàâëßþùåå âîçäåéñòâèå ïî Âûõîäó 0
if (p->out_bit.n0 == 1)
D_OUT0_ON;
else
D_OUT0_OFF;
// Âûâîäèì óïðàâëßþùåå âîçäåéñòâèå ïî Âûõîäó 1
if (p->out_bit.n1 == 1)
D_OUT1_ON;
else
D_OUT1_OFF;
// Âûâîäèì óïðàâëßþùåå âîçäåéñòâèå ïî Âûõîäó 2
if (p->out_bit.n2 == 1)
D_OUT2_ON;
else
D_OUT2_OFF;
}
/*@}*/