| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

dspic33c_mcal.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
22 /*
23 * @file dppic33c_mcal.h
24 * Author: M91406
25 * @brief DPSK3 Hardware Descriptor header file
26 * Revision history:
27 */
28
29 // This is a guard condition so that contents of this file are not included
30 // more than once.
31 #ifndef DSPIC33C_MCU_ABSTRACTION_DESCRIPTOR_H
32 #define DSPIC33C_MCU_ABSTRACTION_DESCRIPTOR_H
33
34 #include <xc.h> // include processor files - each processor file is guarded.
35 #include <stdint.h> // include standard integer data types
36 #include <stdbool.h> // include standard boolean data types
37 #include <stddef.h> // include standard definition data types
38 #include <math.h> // include standard math functions library
39
40
41 /**************************************************************************************************
42 * @ingroup device-abstraction-settings
43 * @{
44 * @brief Fundamental microcontroller device settings
45 *
46 * @details
47 * This section is used to define device specific parameters like ADC reference and
48 * resolution, main execution clock frequency and peripheral time base settings.
49 * All parameters are defined using physical quantities.
50 *
51 **************************************************************************************************/
52 #define EXTOSC_FREQUENCY (float)8000000.0
53 #define FRCC_FREQUENCY (float)8000000.0
54 #define USE_EXTERNAL_CLOCK false
55
56 #define CPU_FREQUENCY (float)100000000.0
57 #define AUX_FREQUENCY (float)500000000.0
58
59 /*********************************************************************************
60 * @ingroup device-abstraction-settings
61 * @def FOSC_FREQUENCY
62 * @brief Macro selecting the main clock frequency value based on user selection of oscillator type
63 * @details
64 * This macro selects the main clock frequency value based on user selection
65 * of the oscillator type.
66 **********************************************************************************/
67 #if (USE_EXTERNAL_CLOCK == true)
68 #define FOSC_FREQUENCY EXTOSC_FREQUENCY
69 #else
70 #define FOSC_FREQUENCY FRCC_FREQUENCY
71 #endif
72
73 // ADC Reference and Resolution Settings
74 #define ADC_REFERENCE (float)3.300
75 #define ADC_RESOLUTION (float)12.00
76
77 // ADC Reference and Resolution Settings
78 #define DAC_REFERENCE (float)3.300
79 #define DAC_RESOLUTION (float)12.00
80
81 #define DAC_MINIMUM (float)0.165
82 #define DAC_MAXIMUM (float)3.135
83 #define DAC_TRANSITION_TIME (float)340.0e-9
84 #define DAC_STEADY_STATE_TIME (float)550.0e-9
85 #define DAC_LEADING_EDGE_PERIOD (float)120.0e-9
86
87 // PWM/ADC Clock Settings
88 #define PWM_CLOCK_HIGH_RESOLUTION true
89
90 #if (PWM_CLOCK_HIGH_RESOLUTION)
91 #define PWM_CLOCK_FREQUENCY (float)4.0e+9
92 #else
93 #define PWM_CLOCK_FREQUENCY (float)500.0e+6
94 #endif
95
96 #define AUX_PLL_CLOCK (float)(1.0 / AUX_FREQUENCY)
97 // end of group device-abstraction-settings
99
111 #define CPU_TCY (float)(1.0 / CPU_FREQUENCY)
112 #define ADC_VALUE_MAX (uint16_t)((0x0001 << (uint16_t)ADC_RESOLUTION) - 1.0) // DO NOT CHANGE
113 #define DAC_VALUE_MAX (uint16_t)((0x0001 << (uint16_t)ADC_RESOLUTION) - 1.0) // DO NOT CHANGE
114 #define ADC_GRANULARITY (float)(ADC_REFERENCE / (float)(ADC_VALUE_MAX + 1))
115 #define DAC_GRANULARITY (float)(DAC_REFERENCE / (float)(DAC_VALUE_MAX + 1))
116 #define PWM_CLOCK_PERIOD (float)(1.0 / PWM_CLOCK_FREQUENCY)
117 #define DAC_CLOCK_PERIOD (float)(2.0 / AUX_FREQUENCY)
118
119 #define DAC_MIN (uint16_t)(DAC_MINIMUM / DAC_GRANULARITY)
120 #define DAC_MAX (uint16_t)(DAC_MAXIMUM / DAC_GRANULARITY)
121 #define DAC_TMODTIME (uint16_t)((DAC_TRANSITION_TIME / AUX_PLL_CLOCK) / 2.0)
122 #define DAC_SSTIME (uint16_t)((DAC_STEADY_STATE_TIME / AUX_PLL_CLOCK) / 2.0)
123 #define DAC_TMCB (uint16_t)((DAC_LEADING_EDGE_PERIOD / AUX_PLL_CLOCK) / 2.0)
124
125 // end of group device-abstraction-macros
126
127 /**************************************************************************************************
128 * @ingroup state-machine-settings
129 * @{
130 * @brief Global state-machine user-settings
131 *
132 * @details
133 * This section is used to set, modify, enable or disable common state machine parameters
134 * and features.
135 *
136 * (Please see individual settings description for detail)
137 *
138 **************************************************************************************************/
139
140 #define MAIN_EXECUTION_PERIOD (float)100.0e-6
141
142 // end of group state-machine-settings ~~~~~~~~~~
143
155 #define MAIN_EXEC_PER (uint16_t)((CPU_FREQUENCY * MAIN_EXECUTION_PERIOD)-1) // DO NOT CHANGE
156 // end of group state-machine-macros ~~~~~~~~~~
158
169 #define _OsTimerInterrupt _T1Interrupt
170 #define _OSTIMER_IP _T1IP
171 #define _OSTIMER_IE _T1IE
172 #define _OSTIMER_IF _T1IF
173 #define _OSTIMER_PRIORITY 2
174 #define _OSTIMER_PER PR1
175 #define _OSTIMER_TMRCAP TMR1
176
177 #define _UartRxInterrupt _U1RXInterrupt
178 #define _UartRx_IP _U1RXIP
179 #define _UartRx_IE _U1RXIE
180 #define _UartRx_IF _U1RXIF
181
182 #define _UartTxInterrupt _U1TXInterrupt
183 #define _UartTx_IP _U1TXIP
184 #define _UartTx_IE _U1TXIE
185 #define _UartTx_IF _U1TXIF
186
187 #define _UartRxDmaInterrupt _DMA1Interrupt
188 #define _UartRxDma_IP _DMA1IP
189 #define _UartRxDma_IE _DMA1IE
190 #define _UartRxDma_IF _DMA1IF
191
192 #define _UartTxDmaInterrupt _DMA0Interrupt
193 #define _UartTxDma_IP _DMA0IP
194 #define _UartTxDma_IE _DMA0IE
195 #define _UartTxDma_IF _DMA0IF
196
197 #define _CRCxInterrupt _CRCInterrupt
198 #define _CRC_IP _CRCIP
199 #define _CRC_IE _CRCIE
200 #define _CRC_IF _CRCIF
201 #define _CRCFIFO_FULL _CRCFUL
202
203 #define UART_RX_ISR_PRIORITY 1
204 #define UART_TX_ISR_PRIORITY 1
205
206 // end of group state-machine-mcal ~~~~~~~~~~
207
208
209 #endif // end of DSPIC33C_MCU_ABSTRACTION_DESCRIPTOR_H