112 lines
3.5 KiB
C
112 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_UdControl.c
|
|
\brief Ìîäóëü ïëàâíîãî çàðÿäà ÇÏÒ
|
|
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
|
|
\version v 1.0 25/08/2017
|
|
|
|
\addtogroup
|
|
@{*/
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
//!Èíèöèàëèçàöèÿ.
|
|
|
|
//!Êîíôèãóðèðóåì íîæêó êîíòðîëëåðà, óïðàâëÿþùóþ öåïüþ çàðÿäà íà âûâîä.
|
|
|
|
//! \memberof TUdControl
|
|
void UdControl_init(TUdControl *p) {
|
|
p->Enabled = 1; //Âêëþ÷àåì áëîê çàðÿäà ÇÏÒ
|
|
UD_CONTROL_OFF; //ñíà÷àëà âûêëþ÷èì
|
|
p->state = UD_CONTROL_STATE_OFF; //è åùå â ñîñòîÿíèå "âûêëþ÷åíî"
|
|
p->StateOn = 0;
|
|
}
|
|
|
|
//!Ðàñ÷åò.
|
|
|
|
//!Äèñêðåòíûé àâòîìàò, óïðàâëÿþùèé öåïüþ çàðÿäà. Âûçûâàòü íàäî â êàêîì-íèáóäü
|
|
//!áûñòðîì ïðåðûâàíèè (íàïðèìåð 10êÃö). Ìîæåò, áóäåò ðàáîòàòü è â 1êÃö, íî
|
|
//!íå ïðîâåðÿëîñü. Èìååò òðè ñîñòîÿíèÿ: âûêëþ÷åíî, îæèäàíèå çàðÿäà è âêëþ÷åíî.
|
|
//!âñå ïåðåêëþ÷åíèÿ ïðîèñõîäÿò íà îñíîâå èçìåðÿåìîãî íàïðÿæåíèÿ íà ÇÏÒ.
|
|
|
|
//! \memberof TUdControl
|
|
void UdControl_calc(TUdControl *p) {
|
|
if (p->Enabled){//åñëè åñòü öåïü óïðàâëåíèÿ çàðÿäîì ÇÏÒ
|
|
p->fUdc.input = adc.Udc_meas; //íà âõîä ôèëüòðà - íàïðÿæåíèå ñ ÇÏÒ
|
|
p->fUdc.calc(&(p->fUdc));
|
|
//ñ÷èòàåì äèñêðåòíûé àâòîìàò
|
|
p->state_shadow = p->state;
|
|
if (p->state_prev != p->state_shadow)
|
|
p->E = 1; //ïåðâîå âõîæäåíèå
|
|
else
|
|
p->E = 0;
|
|
p->state_prev = p->state_shadow;
|
|
|
|
switch (p->state_shadow) {
|
|
case UD_CONTROL_STATE_OFF: //êëþ÷ âûêëþ÷åí
|
|
{
|
|
UD_CONTROL_OFF; //âûêëþ÷àåì êëþ÷
|
|
p->StateOn = 0; //ñîñòîÿíèå âûêëþ÷åíî
|
|
if (adc.Udc_meas > p->U_on) //íàïðÿæåíèå ïî÷òè âûñîêî
|
|
p->state = UD_CONTROL_STATE_WAIT; //ïåðåõîäèì â îæèäàíèå
|
|
break;
|
|
}
|
|
|
|
case UD_CONTROL_STATE_WAIT: //êëþ÷ âûêëþ÷åí, ãîòîâèìñÿ âêëþ÷èòü
|
|
{
|
|
if (p->E == 1) //ïåðâîå âõîæäåíèå
|
|
{
|
|
p->StateCounter = 0;
|
|
}
|
|
p->StateCounter += global_time.relative_time1.delta_millisecond;
|
|
UD_CONTROL_OFF; //âûêëþ÷àåì êëþ÷
|
|
p->StateOn = 0; //ñîñòîÿíèå âûêëþ÷åíî
|
|
if (adc.Udc_meas < p->U_off) //õîòåëè âðîäå âêëþ÷àòü, íî íàïðÿæåíèå ñíèçèëîñü...
|
|
p->state = UD_CONTROL_STATE_OFF;
|
|
|
|
if (global_time.relative_time1.delta_millisecond) { //åñëè ñòîèò áèò ìèëëèñåêóíäû
|
|
//ïðîèçâîäíàÿ íà ìèëëèñåêóíäå
|
|
p->deriv_time_ZPT = (labs(p->fUdc.output - p->fUdc_output_prev))<<11; //ïîäíèìåì çíà÷åíèå ïðîèçâîäíîé äëÿ ïîëó÷åíèÿ óðîâíÿ îêîëî 1
|
|
p->fUdc_output_prev = p->fUdc.output;
|
|
}
|
|
//òàéìàóò âêëþ÷åíèÿ è ïðîèçâîäíàÿ
|
|
if ((p->StateCounter >= p->Timeout_on) && (p->deriv_time_ZPT < p->deriv_const) && (adc.Udc_meas > p->U_off)) { //è ïðîèçâîäíàÿ ìåíüøå çàäàííîãî óðîâíÿ
|
|
p->state = UD_CONTROL_STATE_ON;
|
|
p->StateCounter = 0;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case UD_CONTROL_STATE_ON: {
|
|
if ((adc.Udc_meas < p->U_off) && (drv_status.bit.running == 0)) //ðàáîòàëè-ðàáîòàëè, à òóò íàïðÿæåíèå ñíèçèëîñü... Åñëè âäðóã íàïðÿæåíèå ñíèçèëîñü âî âðåìÿ ðàáîòû, òî ðàçìûêàòü íå äàåì
|
|
p->state = UD_CONTROL_STATE_OFF;
|
|
UD_CONTROL_ON; //âêëþ÷åì êëþ÷
|
|
p->StateOn = 1; //ñîñòîÿíèå âêëþ÷åíî
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/*@}*/
|
|
|