XMC42_800WPSU_LLC
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HRPWM0_CSG2.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Infineon Technologies AG
3  * <br>All rights reserved.
4  * <br>Redistribution and use in source and binary forms, with or without
5  * modification,are permitted provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the documentation
10  * and/or other materials provided with the distribution.
11  * - Neither the name of the copyright holders nor the names of its contributors
12  * may be used to endorse or promote products derived from this software without
13  * specific prior written permission.
14  * .
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  * <br>To improve the quality of the software, users are encouraged to share
27  * modifications, enhancements or bug fixes with Infineon Technologies AG
28  * dave@infineon.com).
29  */
30 
42 /***********************************************************************************************************************
43  * HEADER FILES
44  **********************************************************************************************************************/
45 
46 #include <XMC4200.h> //SFR declarations of the selected device
47 
48 //#include <xmc_gpio.h>
49 #include <xmc_hrpwm.h>
50 //#include <xmc_ccu8.h>
51 #include "hrpwm0_csg2.h"
52 
53 
54 /**********************************************************************************************************************
55 * DATA STRUCTURES
56 **********************************************************************************************************************/
57 
63 const XMC_HRPWM_CSG_CONFIG_t csg2_init_config =
64 {
65  .cmp_config =
66  {
67  .cmp_input_sel = XMC_HRPWM_CSG_CMP_INPUT_CINA,
68  .cmp_input_sw = XMC_HRPWM_CSG_LVL_SEL_DISABLED,
69  .cmp_ext_sw_enable = XMC_HRPWM_FUNC_STATUS_DISABLE,
70  .cmp_out_inv = XMC_HRPWM_FUNC_STATUS_DISABLE,
71  .blanking_mode = XMC_HRPWM_CSG_EDGE_SEL_DISABLED,
72  .blank_ext_enable = XMC_HRPWM_FUNC_STATUS_DISABLE,
73  .blanking_val = 0,
74  .filter_enable = XMC_HRPWM_FUNC_STATUS_ENABLE,
75  .filter_window = 2,
76  .filter_control = 0,
77  .clamp_ctrl_lvl = XMC_HRPWM_CSG_LVL_SEL_DISABLED,
78  .clamp_level = 0,
79  .clamp_exit_sw_config = 0,
80  .clamp_enter_config = 0,
81  .clamp_exit_config = 0
82  },
83  .dac_config =
84  {
85  /* DSV1 is used as initial value and initial conversion trigger is generated */
86  .start_mode = XMC_HRPWM_CSG_SWSM_DSV1_W_TRIGGER, /* Part of SC register (SC.SWSM) */
87  .dac_dsv1 = 758, //816/0x330(28A) //758/0x2F6(26A) //700/0x2BC(24A) //641/0x281(22A) --> 2.07V/3V3*2^10 //583/0x247(20A) --> 1.88V/3V3*2^10 //145/0x91(5A) --> 0.47V/3V3*2^10 //291/0x123(10A) --> 0.94V/3V3*2^10
88  .dac_dsv2 = 0x1
89  },
90  .sgen_config =
91  {
92  /* Start of CSGySC resgister definition --> Slope Control */
93  .ctrl_mode = XMC_HRPWM_CSG_SLOPE_CTRL_MODE_STATIC,
94  .prescaler_ext_start_mode = XMC_HRPWM_CSG_PRESCALER_EXT_START_IGNORE,
95  .prescaler_ext_stop_mode = XMC_HRPWM_CSG_PRESCALER_EXT_STOP_IGNORE,
96  .fixed_prescaler_enable = 1,
97  .prescaler = 3U,
98  .ext_start_mode = XMC_HRPWM_CSG_SLOPE_EXT_START_IGNORE,
99  .ext_stop_mode = XMC_HRPWM_CSG_SLOPE_EXT_STOP_IGNORE,
100  .slope_ref_val_mode = 0U,
101  .step_gain = 0,
102  .static_mode_ist_enable = XMC_HRPWM_FUNC_STATUS_DISABLE,
103  .pulse_swallow_enable = XMC_HRPWM_FUNC_STATUS_ENABLE,
104  .pulse_swallow_win_mode = 2U,
105  /* End of CSGySC register definition */
106 
107  .pulse_swallow_val = 6,
108  }
109 };
113 /**********************************************************************************************************************
114 * API IMPLEMENTATION
115 ***********************************************************************************************************************/
123 void HRPWM0_CSG_Init(void)
124 {
125  /*
126  * CSG2 configuration
127  */
128  /* CSG slice initialization */
129  XMC_HRPWM_CSG_Init(HRPWM0_CSG2, &csg2_init_config);
130  XMC_HRPWM_EnableComparatorShadowTransfer(HRPWM0, XMC_HRPWM_SHADOW_TX_DAC2);
131 
132  /* Start HRPWM CSG, DAC and Comparator*/
133  XMC_HRPWM_StartDac(HRPWM0, XMC_HRPWM_CSG_RUN_BIT_DAC2);
134  XMC_HRPWM_StartComparator(HRPWM0, XMC_HRPWM_CSG_RUN_BIT_CMP2);
135  XMC_HRPWM_StartSlopeGeneration(HRPWM0,(XMC_HRPWM_CSG_SLOPE_START_DAC2|XMC_HRPWM_CSG_PRESCALER_START_CSG2));
136 
137  /* Set event request SR3 when the comparator rises up */
138  XMC_HRPWM_CSG_EnableEvent(HRPWM0_CSG2, XMC_HRPWM_CSG_IRQ_ID_CRSE);
139  XMC_HRPWM_CSG_SetSRNode(HRPWM0_CSG2,XMC_HRPWM_CSG_IRQ_ID_CRSE,XMC_HRPWM_CSG_IRQ_SR_LINE_3);
140 
141  /* Configure interrupt for SR3: COMP_OUT rise edge */
142  NVIC_SetPriority(HRPWM_3_IRQn,0);
143 }