Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
vac_monitor.h
Go to the documentation of this file.
1
12/*
13 (c) 2022 Microchip Technology Inc. and its subsidiaries. You may use this
14 software and any derivatives exclusively with Microchip products.
15
16 THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
17 EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
18 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
19 PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
20 WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
21
22 IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
23 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
24 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
25 BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
26 FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
27 ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28 THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29
30 MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
31 TERMS.
32*/
33
34// This is a guard condition so that contents of this file are not included
35// more than once.
36#ifndef VAC_MONITOR_H
37#define VAC_MONITOR_H
38
39#include <xc.h> // include processor files - each processor file is guarded.
40#include "vac_monitor_typedef.h"
41#include "../../../revision.h"
42#include "../sources_common/Totempole_Application_Setup.h"
43
44
51#define rnd(a) ((uint16_t)((a)+((a)<0?-0.5:0.5)))
52
53
60#define min(a,b) ((uint16_t)(((a)>(b)) ? (b):(a)))
61
62
69#define max(a,b) ((uint16_t)(((a)>(b)) ? (a):(b)))
70
71
84#define FCALL_AC_MONITOR (1.0/10.0e-6)
85
86
95#if HIGH_VOLTAGE == 1 // defined in revision.h
96#define AC_SENSE_GAIN (3.771e-3)
97#else
98#define AC_SENSE_GAIN (37.585e-3)
99#endif // #if HIGH_VOLTAGE == 1
100
101
108#define FIN_MIN (40.0)
109
110
117#define FIN_MAX (65.0)
118
119
128#if HIGH_VOLTAGE == 1
129#define UV_TRIG 10//<<<(60.0)
130#else
131#define UV_TRIG (8.0)
132#endif // #if HIGH_VOLTAGE == '1'
133
134
142#define UV_HYS (2.0)
143
144
153#if HIGH_VOLTAGE == 1
154#define OV_TRIG 350//<<<(240.0)
155#else
156#define OV_TRIG (80.0)
157#endif // #if HIGH_VOLTAGE == '1'
158
159
167#define OV_HYS (2.0)
168
169
176// ZC_TIMEOUT:
177#define ZC_TIMEOUT (2.0e-3)
178
179
187#define ZC_TMIN (100.0e-6)
188
189
199#define AC_DROP_TIMEOUT (25.0e-3)
200
201//------------------------------------------------------------------------------
202// convert values above from SI units to integers for use by the firmware
203// these macros should not need to be modified by the end user
204//------------------------------------------------------------------------------
205
206
216#define DC_ACCEPTANCE_PERIOD_TICKS (rnd(FCALL_AC_MONITOR * 40.0e-3))
217
218
225#define FIN_MIN_TICKS (rnd(FCALL_AC_MONITOR / FIN_MIN))
226
227
234#define FIN_MAX_TICKS (rnd(FCALL_AC_MONITOR / FIN_MAX))
235
236
241#define ZC_TIMEOUT_TICKS (rnd(FCALL_AC_MONITOR * ZC_TIMEOUT))
242
243
248#define ZC_TMIN_TICKS (rnd(FCALL_AC_MONITOR * ZC_TMIN))
249
250
255#define AC_DROP_TIMEOUT_TICKS (rnd(FCALL_AC_MONITOR * AC_DROP_TIMEOUT))
256
257// ADC thresholds corresponding to UV and OV levels
258// these are compared to the averaged rectified AC values
259
260
261
268#define UV_TRIG_ADC (rnd((UV_TRIG*AC_SENSE_GAIN)/3.3*4096))
269
270
278#define UV_CLR_ADC (rnd(((UV_TRIG + UV_HYS)*AC_SENSE_GAIN)/3.3*4096))
279
280
287#define OV_TRIG_ADC (rnd((OV_TRIG*AC_SENSE_GAIN)/3.3*4096))
288
289
297#define OV_CLR_ADC (rnd(((OV_TRIG - OV_HYS)*AC_SENSE_GAIN)/3.3*4096))
298
299
300
306#if HIGH_VOLTAGE == 1
307#define HV_FLAG (1<<15)
308#else
309#define HV_FLAG (0<<15)
310#endif // #if HIGH_VOLTAGE == '1'
311
312// OP AMP Bias, ideal value
313#define OPAMP_BIAS_IDEAL ((uint16_t)(1.65/3.3*4096)) // in ADC codes
314
315// OPAMP_BIAS_HIGH_LIMIT and OPAMP_BIAS_LOW_LIMIT: measured op amp bias should be within 5% of ideal value
316#define OPAMP_BIAS_HIGH_LIMIT ((uint16_t)(OPAMP_BIAS_IDEAL*1.05)) // in ADC codes
317#define OPAMP_BIAS_LOW_LIMIT ((uint16_t)(OPAMP_BIAS_IDEAL*0.95)) // in ADC codes
318
319//------------------------------------------------------------------------------
320// function declarations
321//------------------------------------------------------------------------------
322void vacm_reset_phase_monitor_object(struct VACM_s* vacm_obj);
323void vacm_state_machine(struct VACM_s* vacm_obj);
324void vacm_reset_state_machine(struct VACM_s* vacm_obj);
325
326#ifdef __cplusplus
327extern "C" {
328#endif /* __cplusplus */
329
330 // TODO If C++ is being used, regular C code needs function names to have C
331 // linkage so the functions can be used by the c code.
332
333//------------------------------------------------------------------------------
334// compile time protection
335//------------------------------------------------------------------------------
336#ifndef HIGH_VOLTAGE
337#error HIGH_VOLTAGE must be defined as either 0 or 1 in revision.h
338#else
339#if HIGH_VOLTAGE != 0 && HIGH_VOLTAGE != 1
340#error HIGH_VOLTAGE must be defined as either 0 or 1 in revision.h
341#endif
342#endif
343
344//------------------------------------------------------------------------------
345// variables
346//------------------------------------------------------------------------------
347extern VACM_t phase1;
348extern VACM_t phase2;
349extern VACM_t phase3;
350
351#ifdef __cplusplus
352}
353#endif /* __cplusplus */
354
355#endif /* VAC_MONITOR_H */
VACM_t phase3
void vacm_state_machine(struct VACM_s *vacm_obj)
void vacm_reset_phase_monitor_object(struct VACM_s *vacm_obj)
Definition vac_monitor.c:85
VACM_t phase2
void vacm_reset_state_machine(struct VACM_s *vacm_obj)
VACM_t phase1
VAC Types define.
Main AC Monitor data object data type declaration.