|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
dev_iso_voltage_sense.h
1/* Microchip Technology Inc. and its subsidiaries. You may use this software
2 * and any derivatives exclusively with Microchip products.
3 *
4 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9 *
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17 *
18 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19 * TERMS.
20 */
21
29// This is a guard condition so that contents of this file are not included
30// more than once.
31#ifndef DEV_ISO_VOLTAGE_SENSE_H
32#define DEV_ISO_VOLTAGE_SENSE_H
33
34#include <xc.h> // include processor files - each processor file is guarded.
35#include <stdint.h>
36#include <stdlib.h>
37
38
43#include "input_capture/sccp2.h"
44
45#define InputCapture_CallbackRegister SCCP2_InputCapture_CallbackRegister
46#define InputCapture_bufferoverflow SCCP2_InputCapture_HasBufferOverflowed
47#define InputCapture_BufferEmpty SCCP2_InputCapture_IsBufferEmpty
48#define CCP_TIMER_HIGH_REG CCP2TMRH
49#define CCP_TIMER_LOW_REG CCP2TMRL
50#define CCP_INTERRUPT_FLAG IFS1bits.CCP2IF
51#define CCP_BUF_L CCP2BUFL
52#define CCP_INPUT_CAPTURE_BUFFER 4
// end of dev-vin-sccp-abstraction-macros
54
55
61//#define MAX_AVG_SHIFTING 6
62//#define MAX_NUM_SAMPLES (1<<(MAX_AVG_SHIFTING))
63
64#define MAX_NUM_SAMPLES_ISO_BUFFER 128
65#define MAX_NUM_SAMPLES_ISO_BUFFER_AS_EXP_OF_TWO 7
// end of dev-vin-sccp-avg-buffer-define-macros
67
68
85#define OV_THRESHOLD_VOLT 900
86#define OV_THRESHOLD_SCALING 0.282
87#define OV_THRESHOLD_RAW (OV_THRESHOLD_VOLT / OV_THRESHOLD_SCALING )
88
89#define OV_THRESHOLD_HYST 140
90#define OV_THRESHOLD_HYST_HALF (OV_THRESHOLD_HYST/2)
91
92#define OV_UPPER_THRESHOLD_WITH_HYST OV_THRESHOLD_RAW + OV_THRESHOLD_HYST_HALF
93//#define OV_THRESHOLD_HYST 140
94#define OV_LOWER_THRESHOLD_WITH_HYST OV_THRESHOLD_RAW - OV_THRESHOLD_HYST_HALF
95
96#define UV_THRESHOLD_VOLT 500
97#define UV_THRESHOLD_SCALING 0.282
98#define UV_THRESHOLD_RAW (UV_THRESHOLD_VOLT / UV_THRESHOLD_SCALING)
99
100#define UV_THRESHOLD_HYST 140
101#define UV_THRESHOLD_HYST_HALF (OV_THRESHOLD_HYST/2)
102
103#define UV_UPPER_THRESHOLD_WITH_HYST UV_THRESHOLD_RAW + UV_THRESHOLD_HYST_HALF
104//#define UV_THRESHOLD_HYST 140
105#define UV_LOWER_THRESHOLD_WITH_HYST UV_THRESHOLD_RAW - UV_THRESHOLD_HYST_HALF
106
// end of dev-vin-sccp-sys-spec-macros
108
109
117#define INTERRUPT_COUNTS_MIN 6
118#define INTERRUPT_COUNTS_MAX 9
119#define FAULT_PERSISTENCE_COUNT 8
// end of dev-vin-sccp-fault-counts-macros
121
122
128 typedef struct iso_voltage {
129 uint8_t error_flag;
130 uint8_t over_voltage_flag;
131 uint8_t under_voltage_flag;
132 uint8_t no_signal_flag;
133 uint16_t voltage_raw;
134 uint16_t voltage_averaged;
135 uint16_t voltage_buffer[MAX_NUM_SAMPLES_ISO_BUFFER];
136 uint16_t voltage_buffer_idx;
137 uint8_t buffer_full;
138 uint8_t reset_buffer;
139} dev_iso_voltage_data_t;
140
141
149extern dev_iso_voltage_data_t* dev_iso_voltage_data_ptr;
150
151
155void Dev_Iso_Voltage_Sens_Init(void);
156void Dev_Iso_Voltage_Task_1ms(void);
157uint16_t Dev_Get_Iso_Voltage(void);
158uint16_t Dev_Get_Iso_Voltage_avg(void);
159uint8_t Dev_Iso_Voltage_Is_OV (void);
160uint8_t Dev_Iso_Voltage_Is_UV (void);
161void Dev_Reset_Average_Buffer(void);
162
163#endif /* DEV_ISO_VOLTAGE_SENSE_H */
164
165
166//inline uint16_t Dev_Get_Iso_Voltage_avg_inline (void) {
167// //if (dev_iso_voltage_data_ptr->buffer_full)
168// //{
169// uint16_t index = 0;
170// uint32_t sum = 0;
171// for (index = 0; index <MAX_NUM_SAMPLES; index++)
172// sum +=dev_iso_voltage_data_ptr->voltage_buffer[index];
173// return (sum >> MAX_NUM_SAMPLES_AS_EXP_OF_TWO);
174// //}
175// //else
176// // return 0;
177//}
178
179//inline uint16_t Dev_Get_Iso_Voltage_avg_inline (void){
180// if (dev_iso_voltage_data_ptr->buffer_full)
181// return Iso_Calculate_Average(dev_iso_voltage_data_ptr->voltage_buffer, MAX_NUM_SAMPLES);
182// else
183// return 0;
184//}
iso_voltage
Definition dev_iso_voltage_sense.h:128
iso_voltage::reset_buffer
uint8_t reset_buffer
reset voltage_buffer
Definition dev_iso_voltage_sense.h:138
iso_voltage::no_signal_flag
uint8_t no_signal_flag
if no signal is present
Definition dev_iso_voltage_sense.h:132
iso_voltage::voltage_buffer_idx
uint16_t voltage_buffer_idx
current index of averaging buffer
Definition dev_iso_voltage_sense.h:136
iso_voltage::under_voltage_flag
uint8_t under_voltage_flag
under voltage flag
Definition dev_iso_voltage_sense.h:131
iso_voltage::voltage_buffer
uint16_t voltage_buffer[MAX_NUM_SAMPLES_ISO_BUFFER]
buffer for averaging
Definition dev_iso_voltage_sense.h:135
iso_voltage::buffer_full
uint8_t buffer_full
flag to monitor if full then allow averaging.
Definition dev_iso_voltage_sense.h:137
iso_voltage::over_voltage_flag
uint8_t over_voltage_flag
Over voltage flag.
Definition dev_iso_voltage_sense.h:130
iso_voltage::voltage_averaged
uint16_t voltage_averaged
voltage averaged raw
Definition dev_iso_voltage_sense.h:134
iso_voltage::voltage_raw
uint16_t voltage_raw
voltage value raw
Definition dev_iso_voltage_sense.h:133
iso_voltage::error_flag
uint8_t error_flag
error_flag
Definition dev_iso_voltage_sense.h:129
dev_iso_voltage_data_t
a custom data type for isolated voltage measurement