Digital Power Starter Kit 3 Firmware
dsPIC33C Boost Converter Voltage Mode Control Example
p33c_ccp.c
1 #include <xc.h> // include processor files - each processor file is guarded.
2 #include <stdint.h> // include standard integer data types
3 #include <stdbool.h> // include standard boolean data types
4 #include <stddef.h> // include standard definition data types
5 
6 #include "p33c_ccp.h"
7 
8 // Private arrays of register set start addresses
9 #if defined (CCP9CON1L)
10 volatile uint16_t* p33c_CcpInstance_Handles[9]={
11  &CCP1CON1L, &CCP2CON1L, &CCP3CON1L, &CCP4CON1L,
12  &CCP5CON1L, &CCP6CON1L, &CCP7CON1L, &CCP8CON1L,
13  &CCP9CON1L
14 };
15 #elif defined (CCP8CON1L)
16 volatile uint16_t* p33c_CcpInstance_Handles[8]={
17  &CCP1CON1L, &CCP2CON1L, &CCP3CON1L, &CCP4CON1L,
18  &CCP5CON1L, &CCP6CON1L, &CCP7CON1L, &CCP8CON1L
19 };
20 #elif defined (CCP7CON1L)
21 volatile uint16_t* p33c_CcpInstance_Handles[7]={
22  &CCP1CON1L, &CCP2CON1L, &CCP3CON1L, &CCP4CON1L,
23  &CCP5CON1L, &CCP6CON1L, &CCP7CON1L
24 };
25 #elif defined (CCP6CON1L)
26 volatile uint16_t* p33c_CcpInstance_Handles[6]={
27  &CCP1CON1L, &CCP2CON1L, &CCP3CON1L, &CCP4CON1L,
28  &CCP5CON1L, &CCP6CON1L
29 };
30 #elif defined (CCP5CON1L)
31 volatile uint16_t* p33c_CcpInstance_Handles[5]={
32  &CCP1CON1L, &CCP2CON1L, &CCP3CON1L, &CCP4CON1L,
33  &CCP5CON1L
34 };
35 #elif defined (CCP4CON1L)
36 volatile uint16_t* p33c_CcpInstance_Handles[4]={
37  &CCP1CON1L, &CCP2CON1L, &CCP3CON1L, &CCP4CON1L
38 };
39 #elif defined (CCP3CON1L)
40 volatile uint16_t* p33c_CcpInstance_Handles[3]={
41  &CCP1CON1L, &CCP2CON1L, &CCP3CON1L
42 };
43 #elif defined (CCP2CON1L)
44 volatile uint16_t* p33c_CcpInstance_Handles[2]={
45  &CCP1CON1L, &CCP2CON1L
46 };
47 #elif defined (CCP1CON1L)
48 volatile uint16_t* p33c_CcpInstance_Handles[1]={
49  &CCP1CON1L
50 };
51 #else
52 #pragma message "selected device has no supported PWM generators"
53 #endif
54 
55 
56 
57 /*********************************************************************************
58  * @ingroup lib-layer-pral-properties-private-ccp
59  * @var ccpConfigDefault
60  * @brief CCP Register Set reset state template
61  *
62  * @details
63  * This P33C_CCP_MODULE_SFRSET_s data object provides a template of register
64  * configuration values for a CCP peripheral instance.
65  *
66  * Default configuration:
67  * - all options are reset to their default state
68  *
69  *********************************************************************************/
73 
74  .CCPxTMRL.value = 0,
75  .CCPxTMRH.value = 0,
76  .CCPxBUFH.value = 0,
77  .CCPxBUFL.value = 0,
78  .CCPxPRH.value = 0,
79  .CCPxPRL.value = 0,
80  .CCPxRAL.value = 0,
81  .CCPxRBL.value = 0,
82  .CCPxCON1H.value= 0,
83  .CCPxCON1L.value = 0x0000,
84  .CCPxCON2H.value = 0,
85  .CCPxCON2L.value = 0,
86  .CCPxCON3H.value= 0,
87  .CCPxSTATL.value= 0
88 
89  };
90 
91 /* PRIVATE FUNCTION CALL PROTOTYPES*/
92 // (none)
93 
94 
95 /*********************************************************************************
96  * @fn volatile struct P33C_CCP_INSTANCE_s p33c_CcpInstance_ConfigRead(volatile uint16_t ccpInstance)
97  * @ingroup lib-layer-pral-functions-public-ccp
98  * @brief Read the current configuration from the CCP instance registers
99  * @param ccpInstance Index of the Capture/Compare peripheral instance of type unsinged integer
100  * @return SCCP/MCCP instance special function register data object of type struct P33C_CCP_INSTANCE_s
101  *
102  * @details
103  * This function reads all registers with their current configuration into
104  * a data structure of type P33C_CCP_MODULE_SFRSET_s. Users can read and
105  * verify of modify the configuration to write it back to any other CCP
106  * peripheral instance.
107  *
108  *********************************************************************************/
109 
110 volatile struct P33C_CCP_INSTANCE_s p33c_CcpInstance_ConfigRead(volatile uint16_t ccpInstance){
111 
112  volatile struct P33C_CCP_INSTANCE_s* ccp;
113 
114  // Capture Handle: set pointer to memory address of desired PWM instance
115  ccp = p33c_CcpInstance_GetHandle(ccpInstance);
116 
117  return(*ccp);
118 }
119 
120 /********************************************************************************
121  * @fn volatile uint16_t p33c_CcpInstance_ConfigWrite(volatile uint16_t ccpInstance, volatile struct P33C_CCP_INSTANCE_s ccpConfig)
122  * @ingroup lib-layer-pral-functions-public-ccp
123  * @brief Writes a user-defined configuration to the CCP instance registers
124  * @param ccpInstance Index of the Capture/Compare peripheral instance of type unsinged integer
125  * @param ccpConfig SCCP/MCCP instance special function register data object of type struct P33C_CCP_INSTANCE_s
126  * @return 0 = failure, writing to CCP instance was not successful
127  * @return 1 = success, writing to CCP instance was successful
128  *
129  * @details
130  * This function writes a user-defined CCP instance configuration of type
131  * P33C_CCP_MODULE_SFRSET_s to the CCP instance registers. The
132  * individual register configurations have to be set in user-code
133  * before calling this function. To simplify the configuration process
134  * of standard functions, this driver provides templates, which can be
135  * loaded and written directly
136  *
137  *********************************************************************************/
138 
139 volatile uint16_t p33c_CcpInstance_ConfigWrite(volatile uint16_t ccpInstance,
140  volatile struct P33C_CCP_INSTANCE_s ccpConfig)
141 {
142  volatile uint16_t retval=1;
143  volatile struct P33C_CCP_INSTANCE_s* ccp;
144 
145  // Set pointer to memory address of desired CCP instance
146  ccp = p33c_CcpInstance_GetHandle(ccpInstance);
147  *ccp = ccpConfig;
148 
149  return(retval);
150 
151 }
152 
153 // end of file
union P33C_CCP_INSTANCE_s::@6 CCPxTMRL
volatile struct P33C_CCP_INSTANCE_s ccpConfigDefault
Definition: p33c_ccp.c:72
uint16_t value
Definition: p33c_ccp.h:42