leg.h 3.87 KB
Newer Older
1
/*
2
 * Copyright (c) 2020-2022 LAAS-CNRS
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: LGLPV2.1
 */


/**
 * @defgroup    owntech_modules_leg OwnTech's leg module
 * @ingroup     owntech_modules
 * @brief       OwnTech PWM management layer by inverter leg
 *
 * @file
 * @brief   PWM management layer by inverter leg interface definitions
28
 * @date    2022
29
 * @author  Hugues Larrive <hugues.larrive@laas.fr>
30
 * @author  Antoine Boche <antoine.boche@laas.fr>
31
 * @author  Luiz Villa <luiz.villa@laas.fr>
Ayoub Farah Hassan's avatar
Ayoub Farah Hassan committed
32
 * @author  Ayoub Farah Hassan <ayoub.farah-hassan@laas.fr>
33
34
 */

35
36
#ifndef LEG_H_
#define LEG_H_
37
38

#include <assert.h>
39
40
41
#include <stdint.h>

#include <zephyr.h>
42
43
44
45
46
47
48

#include "hrtim.h"

#ifdef __cplusplus
extern "C" {
#endif

49
50
51
#define LEG_DEFAULT_DT  (100U)      /**< dead-time in ns */
#define LEG_FREQ        KHZ(200U)   /**< frequency in Hz*/

52
53
54
55
56
57
58
59
60
61
62
/**
 * @brief   Inverter leg configuration data structure
 */
typedef struct {
    hrtim_t hrtim;              /**< HRTIM device */
    hrtim_tu_t timing_unit;     /**< Timing unit */
    uint16_t dead_time;         /**< Dead time */
    uint16_t pulse_width;       /**< Pulse width */
} leg_conf_t;

/**
63
64
 * @brief   Initializes all the configured devices with the chosen switch convention
 *
65
66
 * @param[in]   leg1_upper_switch_convention    Choice of the switch convention for leg 1
 * @param[in]   leg2_upper_switch_convention    Choice of the switch convention for leg 2 
67
 *
68
 * @return                      HRTIM period
69
 */
70
uint16_t leg_init(bool leg1_upper_switch_convention, bool leg2_upper_switch_convention);
71

Ayoub Farah Hassan's avatar
Ayoub Farah Hassan committed
72
73
74
75
76
77
78
79
80
81
/**
 * @brief   Initializes all the configured devices with up-down mode and the chosen switch convention
 *
 * @param[in]   leg1_upper_switch_convention    Choice of the switch convention for leg 1
 * @param[in]   leg2_upper_switch_convention    Choice of the switch convention for leg 2 
 *
 * @return                      HRTIM period
 */
uint16_t leg_init_center_aligned(bool leg1_upper_switch_convention, bool leg2_upper_switch_convention);

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
 * @brief   Set the PWM pulse width for a given leg device
 *
 * @param[in]   timing_unit     timing_unit from TIMA to TIMF
 * @param[in]   pulse_width     pulse width to set
 * @param[in]   phase_shift     phase shift
 */
void leg_set(hrtim_tu_t timing_unit, uint16_t pulse_width, uint16_t phase_shift);

/**
 * @brief   Stop the leg (its 2 outputs goes low)
 *
 * @param[in]   timing_unit     timing_unit from TIMA to TIMF
 */
void leg_stop(hrtim_tu_t timing_unit);

98
99
100
101
102
103
104
/**
 * @brief   Start the leg (its 2 outputs goes low)
 *
 * @param[in]   timing_unit     timing_unit from TIMA to TIMF
 */
void leg_start(hrtim_tu_t timing_unit); 

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
 * @brief   period getter
 *
 * @return                      period value returned by leg_init()
 */
uint16_t leg_period(void);

/**
 * @brief   LEG_NUMOF getter
 *
 * @return                      number of configured leg devices
 */
uint8_t leg_numof(void);

/**
 * @brief   leg_config getter
 *
 * @param[in]   leg             leg from 0 to LEG_NUMOF
 *
 * @return                      the leg configuration data structure
 */
leg_conf_t leg_get_conf(uint8_t leg);

/**
 * @brief   LEG_FREQ getter
 *
 * @return                      value of LEG_FREQ in KHz
 */
uint16_t leg_get_freq(void);

#ifdef __cplusplus
}
#endif

139
#endif // LEG_H_