From 5812e0c8c92ee782b9432dd2ac46a7e5818792f6 Mon Sep 17 00:00:00 2001 From: dimidxxx Date: Mon, 30 Sep 2019 19:41:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BD=D0=BE=D0=B6=D0=BA=D0=B8=20=D0=BF=D0=BE=D0=B4=20?= =?UTF-8?q?UART=20=D0=B4=D0=BB=D1=8F=20ModBus.=20=D0=9E=D0=B1=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C?= =?UTF-8?q?=20=D0=B4=D0=B8=D1=81=D0=BA=D1=80=D0=B5=D1=82=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=B2=D1=85=D0=BE=D0=B4=D0=BE=D0=B2/=D0=B2=D1=8B=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Vinclude/SM_CmdLogic.h | 6 +- Vinclude/SM_Protect.h | 2 +- Vinclude/V_DIO.h | 171 +++++++++++++++++++++++---------------- Vinclude/main.h | 1 + Vsrc/SM_Sys.c | 7 +- Vsrc/V_DIO.c | 148 +++++++++++++++++---------------- Vsrc/V_ModBus.c | 2 +- Vsrc/main.c | 1 + src/GpioPeripheralInit.c | 8 +- 9 files changed, 193 insertions(+), 153 deletions(-) diff --git a/Vinclude/SM_CmdLogic.h b/Vinclude/SM_CmdLogic.h index 3849a2e..b3dc2e4 100644 --- a/Vinclude/SM_CmdLogic.h +++ b/Vinclude/SM_CmdLogic.h @@ -41,9 +41,9 @@ extern "C" #if defined (HW_MCB3) //Äëÿ óïðàâëåíèÿ êîíòðîëëåðîì ìû èñïîëüçóåì âíåøíèå äèñêðåòíûå âõîäû ñ èñïîëüçîâàíèåì ôèëüòðàöèè (ñì. V_DIO) -#define STARTBUTTON (BIT_IS_SET(input_vect, 0) ? 1 : 0) //Ïðîâåðêà íà óñòàâêó áèòà â âåêòîðå äèñêðåòíûõ âõîäîâ -#define STOPBUTTON (BIT_IS_SET(input_vect, 1) ? 1 : 0) //Ïðîâåðêà íà óñòàâêó áèòà â âåêòîðå äèñêðåòíûõ âõîäîâ -#define RESETBUTTON (BIT_IS_SET(input_vect, 2) ? 1 : 0) //Ïðîâåðêà íà óñòàâêó áèòà â âåêòîðå äèñêðåòíûõ âõîäîâ +#define STARTBUTTON (dio.in_bit.n0) //Ïðîâåðêà íà óñòàâêó áèòà â âåêòîðå äèñêðåòíûõ âõîäîâ +#define STOPBUTTON (dio.in_bit.n1) //Ïðîâåðêà íà óñòàâêó áèòà â âåêòîðå äèñêðåòíûõ âõîäîâ +#define RESETBUTTON (dio.in_bit.n2) //Ïðîâåðêà íà óñòàâêó áèòà â âåêòîðå äèñêðåòíûõ âõîäîâ #elif defined (HW_MCB3_SIMULATOR) #define STARTBUTTON 0 #define STOPBUTTON 0 diff --git a/Vinclude/SM_Protect.h b/Vinclude/SM_Protect.h index ee0fd13..b2bbd70 100644 --- a/Vinclude/SM_Protect.h +++ b/Vinclude/SM_Protect.h @@ -47,7 +47,7 @@ extern "C" #define DRV_FAULT3 (GPIOD->DATA & (1 << 4)) //Àâàðèÿ êëþ÷à A2 #define DRV_FAULT4 (GPIOD->DATA & (1 << 5)) //Àâàðèÿ êëþ÷à B0 èëè B1 èëè B2 //Äëÿ ñáðîñà àïïàðàòíîé àâàðèè â äàííîì êîíòðîëëåðå èñïîëüçóååòñÿ âíåøíèé äèñêðåòíûé ïîðò ââîäà -#define RESET_FAULT_BUTTON (BIT_IS_SET(input_vect, 2) ? 1 : 0) //Åñëè óñòàíîâëåí 3-é áèò â âåêòîðå äèñêðåòíûõ âõîäîâ +#define RESET_FAULT_BUTTON (dio.in_bit.n2) //Äèñêðåòíûé âõîä äëÿ êíîïêè ñáðîñà àâàðèè #elif defined (HW_MCB3_SIMULATOR) #define DRV_FAULT 0 #define DRV_FAULT1 0 diff --git a/Vinclude/V_DIO.h b/Vinclude/V_DIO.h index 2f35895..28e4046 100644 --- a/Vinclude/V_DIO.h +++ b/Vinclude/V_DIO.h @@ -16,7 +16,7 @@ \file V_DIO.h \brief Ìîäóëü äèñêðåòíûõ âõîäîâ/âûõîäîâ \author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru - \version v 1.0 25/08/2017 + \version v 2.0 25/09/2019 \addtogroup @{*/ @@ -30,84 +30,115 @@ extern "C" { #endif -// Ìàêðîñ óñòàíîâêè â '1' çàäàííîãî áèòà -// var - öåëåâàß ïåðåìåííàß -// index - èíäåêñ (ñìåùåíèå) óñòàíàâëèâàåìîãî áèòà -#define SET_BIT(var, index) var |= (1 << index); - -// Ìàêðîñ ñáðîñà â '0' çàäàííîãî áèòà -// var - öåëåâàß ïåðåìåííàß -// index - èíäåêñ (ñìåùåíèå) î÷èùàåìîãî áèòà -#define CLEAR_BIT(var, index) var &= (~(1 << index)); - -// Ìàêðîñ ïðîâåðêè íåíóëåâîãî ñîñòîßíèÿ çàäàííîãî áèòà -// var - öåëåâàß ïåðåìåííàß -// index - èíäåêñ (ñìåùåíèå) ïðîâåðßåìîãî áèòà -#define BIT_IS_SET(var, index) ((var & (1 << index)) != 0) - -// Ìàêðîñ ïðîâåðêè íóëåâîãî ñîñòîßíèÿ çàäàííîãî áèòà -// var - öåëåâàß ïåðåìåííàß -// index - èíäåêñ (ñìåùåíèå) ïðîâåðßåìîãî áèòà -#define BIT_IS_CLEAR(var, index) ((var & (1 << index)) == 0) -// Äåôàéíèì äèñêðåòíûå âõîäû -#ifdef HW_MCB3 -//TODO ïåðåäåëàòü -#define D_IN1 ((GPIOM->DATA & (1 << 13)) == 0) //M13 Ñòàðò -#define D_IN2 ((GPIOM->DATA & (1 << 11)) == 0) //M11 Ñòîï -#define D_IN3 ((GPIOM->DATA & (1 << 10)) == 0) //M10 Ñáðîñ àâàðèé -#else -#define D_IN1 0 -#define D_IN2 0 -#define D_IN3 0 -#endif +typedef struct SDIO { -// Äåôàéíèì äèñêðåòíûå âûõîäû -#ifdef HW_MCB3 -#define D_OUT1_ON GPIOD->DATAOUTSET = GPIO_PIN_1 -#define D_OUT1_OFF GPIOD->DATAOUTCLR = GPIO_PIN_1 -#define D_OUT2_ON GPIOD->DATAOUTSET = GPIO_PIN_2 -#define D_OUT2_OFF GPIOD->DATAOUTCLR = GPIO_PIN_2 -#define D_OUT3_ON GPIOM->DATAOUTSET = GPIO_PIN_14 -#define D_OUT3_OFF GPIOM->DATAOUTCLR = GPIO_PIN_14 -#else -#define D_OUT1_ON -#define D_OUT1_OFF -#define D_OUT2_ON -#define D_OUT2_OFF -#define D_OUT3_ON -#define D_OUT3_OFF -#endif + union { //!<Âåêòîð óïðàâëåíèÿ äèñêðåòíûìè âûõîäàìè + Uint16 out; + struct { + Uint16 n0:1; + Uint16 n1:1; + Uint16 n2:1; + Uint16 n3:1; + Uint16 n4:1; + Uint16 n5:1; + Uint16 n6:1; + Uint16 n7:1; + Uint16 n8:1; + Uint16 n9:1; + Uint16 n10:1; + Uint16 n11:1; + Uint16 n12:1; + Uint16 n13:1; + Uint16 n14:1; + Uint16 n15:1; + }out_bit; + }; + + union { //!<Âåêòîð ñîñòîÿíèÿ äèñêðåòíûõ âõîäîâ ñ ó÷åòîì èíâåðñèè ìàñêè + Uint16 in; + struct { + Uint16 n0:1; + Uint16 n1:1; + Uint16 n2:1; + Uint16 n3:1; + Uint16 n4:1; + Uint16 n5:1; + Uint16 n6:1; + Uint16 n7:1; + Uint16 n8:1; + Uint16 n9:1; + Uint16 n10:1; + Uint16 n11:1; + Uint16 n12:1; + Uint16 n13:1; + Uint16 n14:1; + Uint16 n15:1; + }in_bit; + }; + + _iq inputKf; //!<Êîýôôèöèåíò ôèëüòðàöèè äèñêðåòíûõ âõîäîâ Kf = 0.001/Tô (Tô - ïîñòîßííàß âðåìåíè ôèëüòðà, ñåê) + _iq inputOff; //!<Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå OFF (0) + _iq inputOn; //!<Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå ON (1) + + // Ôèëüòðû äèñêðåòíûõ âõîäîâ + TFilter fIn0; + TFilter fIn1; + TFilter fIn2; + TFilter fIn3; + TFilter fIn4; + TFilter fIn5; + TFilter fIn6; + TFilter fIn7; + TFilter fIn8; + TFilter fIn9; + TFilter fIn10; + TFilter fIn11; + TFilter fIn12; + TFilter fIn13; + TFilter fIn14; + TFilter fIn15; + + void (*init)(struct SDIO*); + void (*slow_calc)(struct SDIO*); + void (*ms_calc)(struct SDIO*); +}TDIO; -// Âåêòîð ñîñòîßíèß äèñêðåòíûõ âûõîäîâ -extern volatile Uint16 output_vect; -// Ìàñêà èíâåðòèðîâàíèß âåêòîðà ñîñòîßíèß äèñêðåòíûõ âûõîäîâ -extern volatile Uint16 output_mask; -// Âåêòîð ñîñòîßíèß äèñêðåòíûõ âõîäîâ -extern volatile Uint16 input_vect; -// Ìàñêà èíâåðòèðîâàíèß âåêòîðà ñîñòîßíèß äèñêðåòíûõ âõîäîâ -extern volatile Uint16 input_mask; - -// Êîýôôèöèåíò ôèëüòðàöèè äèñêðåòíûõ âõîäîâ Kf = 0.0001/Tô -// (Tô - ïîñòîßííàß âðåìåíè ôèëüòðà, ñåê) -extern volatile _iq inputKf; -#define in_Kf inputKf // ïñåâäîíèì äëß óæå èìåþùåéñÿ ïåðåìåííîé â ñëîâàðå CANopen - -// Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå OFF (0) -extern volatile _iq inputOff; -// Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå ON (1) -extern volatile _iq inputOn; +//!Èíèöèàëèçàòîð ïî-óìîë÷àíèþ. +#define DIO_DEFAULTS { .out = 0, .in = 0, \ + .inputKf = 0, .inputOff = 0, .inputOn = 0, \ + .fIn0 = FILTER_DEFAULTS, \ + .fIn1 = FILTER_DEFAULTS, \ + .fIn2 = FILTER_DEFAULTS, \ + .fIn3 = FILTER_DEFAULTS, \ + .fIn4 = FILTER_DEFAULTS, \ + .fIn5 = FILTER_DEFAULTS, \ + .fIn6 = FILTER_DEFAULTS, \ + .fIn7 = FILTER_DEFAULTS, \ + .fIn8 = FILTER_DEFAULTS, \ + .fIn9 = FILTER_DEFAULTS, \ + .fIn10 = FILTER_DEFAULTS, \ + .fIn11 = FILTER_DEFAULTS, \ + .fIn12 = FILTER_DEFAULTS, \ + .fIn13 = FILTER_DEFAULTS, \ + .fIn14 = FILTER_DEFAULTS, \ + .fIn15 = FILTER_DEFAULTS, \ + .init = DIO_init, \ + .slow_calc = DIO_slow_calc, \ + .ms_calc = DIO_ms_calc, \ +} -void DIO_Init(); - -void DIO_slow_calc(); // âûçûâàòü â ôîíîâîé ïðîãðàììå - -void DIO_fast_calc(); // âûçûâàòü ñ ÷àñòîòîé 1êÃö èëè 10 êÃö +//! \memberof TDIO +void DIO_init(TDIO* p); +//! \memberof TDIO +void DIO_slow_calc(TDIO* p); +//! \memberof TDIO +void DIO_ms_calc(TDIO* p); #ifdef __cplusplus diff --git a/Vinclude/main.h b/Vinclude/main.h index 895fb2f..fb56e77 100644 --- a/Vinclude/main.h +++ b/Vinclude/main.h @@ -134,6 +134,7 @@ extern Texcitation pwm_ex; extern TDrvInterface drv_interface; extern TLogger FaultLog; extern TGlobalTime global_time; +extern TDIO dio; extern TUdControl udControl; extern TFanControl FanControl; extern TTMU tmu; diff --git a/Vsrc/SM_Sys.c b/Vsrc/SM_Sys.c index a171d63..65a81a2 100644 --- a/Vsrc/SM_Sys.c +++ b/Vsrc/SM_Sys.c @@ -54,10 +54,10 @@ void SM_Sys_Init(TSM_Sys *p) { cur_par.init(&cur_par); //Ðàñ÷åò òåêóùèõ ïîêàçàòåëåé ïðèâîäà leds.init(&leds);//ñâåòîäèîäû udControl.init(&udControl); //ïëàâíàÿ çàðÿäêà ÇÏÒ ÷åðåç òåðìèñòîðû - DIO_Init(); //äèñêðåòíûå âõîäû/âûõîäû FanControl.init(&FanControl); //âåíòèëÿòîð //ãëîáàëüíîå âðåìß (âíåøíèå èëè âíóòð. ÷àñû) global_time.init(&global_time); + dio.init(&dio); //äèñêðåòíûå âõîäû/âûõîäû if (drv_params.sens_type == POS_SENSOR_TYPE_HALL){ // òèïå äàò÷èêà âûáðàí ÄÏÐ íà ýëåìåíòàõ Õîëëà DPReCAP.Init(&DPReCAP); //ÄÏÐ èíèö. } @@ -251,8 +251,7 @@ void SM_Sys_ms_Calc(TSM_Sys* p) { DPReCAP.ms_calc(&DPReCAP); } global_time.ms_calc(&global_time); - - DIO_fast_calc(); //äèñêðåòíûå âõîäû/âûõîäû + dio.ms_calc(&dio); //äèñêðåòíûå âõîäû/âûõîäû } //!Ìåäëåííûé ðàñ÷åò (ôîíîâûé). @@ -275,7 +274,7 @@ void SM_Sys_Slow_Calc(TSM_Sys *p) { AutoOffset.slow_calc(&AutoOffset); posspeedEqep.slow_calc(&posspeedEqep);//èíèöèàëèçàöèÿ ìîäóëÿ ýíêîäåðà RotorObserver.slow_calc(&RotorObserver);//íàáëþäàòåëü ïîòîêà ðîòîðà ÀÄ - DIO_slow_calc(); //äèñêðåòíûå âõîäû/âûõîäû + dio.slow_calc(&dio); //äèñêðåòíûå âõîäû/âûõîäû FanControl.slow_calc(&FanControl);//âåíòèëÿòîð diff --git a/Vsrc/V_DIO.c b/Vsrc/V_DIO.c index 8f153ca..9fe7809 100644 --- a/Vsrc/V_DIO.c +++ b/Vsrc/V_DIO.c @@ -16,7 +16,7 @@ \file V_DIO.c \brief Ìîäóëü äèñêðåòíûõ âõîäîâ/âûõîäîâ \author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru - \version v 1.0 25/08/2017 + \version v 2.0 25/09/2019 \addtogroup @{*/ @@ -27,90 +27,98 @@ #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 -// Âåêòîð ñîñòîßíèß äèñêðåòíûõ âûõîäîâ -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; +// Äåôàéíèì äèñêðåòíûå âûõîäû +#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() + +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() +void DIO_slow_calc(TDIO* p) { - - // Ïîëó÷àåì âåêòîð ñîñòîßíèß äèñêðåòíûõ âûõîäîâ ñ ó÷¸òîì ìàñêè èíâåðòèðîâàíèß - 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; - + p->fIn0.T = p->inputKf; + p->fIn1.T = p->inputKf; + p->fIn2.T = p->inputKf; } -void DIO_fast_calc() +void DIO_ms_calc(TDIO* p) { + + //------------------------Îáðàáîòêà âõîäîâ------------------------------// + + // Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 0 + p->fIn0.input = (D_IN0 == 1) ? _IQ(1.0) : 0; + p->fIn0.calc(&(p->fIn0)); // Èíåðöèîííûé ôèëüòð äèñêðåòíîãî Âõîäà 1 - fIn1.input = (D_IN1 == 1) ? _IQ(1.0) : 0; - fIn1.calc(&fIn1); + p->fIn1.input = (D_IN1 == 1) ? _IQ(1.0) : 0; + p->fIn1.calc(&(p->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); + 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; } /*@}*/ diff --git a/Vsrc/V_ModBus.c b/Vsrc/V_ModBus.c index 508dd67..ad5ff8d 100644 --- a/Vsrc/V_ModBus.c +++ b/Vsrc/V_ModBus.c @@ -69,7 +69,7 @@ void ModBus_RS_Init(TModBus *p) { - p->MBInternals.NT_UART = UART2; //Èñïîëüçóåìûé â äðàéâåðå íîìåð UART (1,2,3) + p->MBInternals.NT_UART = UART3; //Èñïîëüçóåìûé â äðàéâåðå íîìåð UART (1,2,3) p->MBInternals.NT_UART->CR_bit.UARTEN = 1; // Ðàçðåøèòü ðàáîòó UART //Òåêóùàÿ ðåàëèçàöèÿ äðàéâåðà íå èñïîëüçóåò FIFO, îáðàáàòûâàåò äàííûå ïî îäíîìó áàéòó diff --git a/Vsrc/main.c b/Vsrc/main.c index ee9a90e..a9b0e65 100644 --- a/Vsrc/main.c +++ b/Vsrc/main.c @@ -74,6 +74,7 @@ TMBVarsConv MBVarsConv = MBVARSCONV_DEFAULTS;//!< TDrvInterface drv_interface = DRV_INTERFACE_DEFAULTS; //!<Èíòåðôåéñ äëß ðàáîòû ñ áàíêàìè àâàðèé, ñîáûòèé è ò.ï. TLogger FaultLog = LOGGER_DEFAULTS; //!<Ïðîòîêîëèðîâàíèå àâàðèé TGlobalTime global_time = GLOBAL_TIME_DEFAULTS; //!<Ðàáîòà ñ ÷àñàìè +TDIO dio = DIO_DEFAULTS; //!<Ìîäóëü ðàáîòû ñ äèñêðåòíûìè âõîäàìè/âûõîäàìè TUdControl udControl = UD_CONTROL_DEFAULTS; //!<Ïëàâíàÿ çàðÿäêà ÇÏÒ ÷åðåç òåðìèñòîðû TFanControl FanControl = FAN_CONTROL_DEFAULTS; //!<Âåíòèëÿòîð TTMU tmu = TMU_DEFAULTS; //!<Áëîê òðèãîíîìåòè÷åñêèõ ïðåîáðàçîâàíèé diff --git a/src/GpioPeripheralInit.c b/src/GpioPeripheralInit.c index c88fe66..6aa11b6 100644 --- a/src/GpioPeripheralInit.c +++ b/src/GpioPeripheralInit.c @@ -92,10 +92,10 @@ void gpioPeripheralInit (void) { #endif #ifdef MODBUS_ENA - // UART2: K10 / K11 + M2 (modbus tx/rx) - GPIOK->ALTFUNCNUM1_bit.PIN10 = 4; // UART2_RX - GPIOK->ALTFUNCNUM1_bit.PIN11 = 4; // UART2_TX - GPIOK->ALTFUNCSET = GPIO_PIN_10 | GPIO_PIN_11; + // UART3: E8 / E9 + M2 (modbus rx/tx) + GPIOE->ALTFUNCNUM1_bit.PIN8 = 4; // UART3_RX + GPIOE->ALTFUNCNUM1_bit.PIN9 = 4; // UART3_TX + GPIOE->ALTFUNCSET = GPIO_PIN_8 | GPIO_PIN_9; GPIOM->ALTFUNCCLR = GPIO_PIN_2; GPIOM->OUTENSET = GPIO_PIN_2;