Digital Power Starter Kit 3 Firmware
dsPIC33C Boost Converter Voltage Mode Control Example
p33c_timer.c
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 // Include standard header files
23 #include <xc.h> // include processor files - each processor file is guarded.
24 #include <stdint.h> // include standard integer data types
25 #include <stdbool.h> // include standard boolean data types
26 #include <stddef.h> // include standard definition data types
27 
28 #include "p33c_timer.h"
29 
30 /*********************************************************************************
31  * @ingroup lib-layer-pral-properties-private-timer
32  * @var tmrConfigDefault
33  * @brief Timer Register Set reset state template
34  *
35  * @details
36  * This P33C_TIMER_MODULE_s data object provides a template of register
37  * configuration values for the 16-bit Timer peripheral.
38  *
39  * Default configuration:
40  * - all options are reset to their default state
41  *
42  *********************************************************************************/
46  .TxCON.value = 0x0000, // Clear time configuration register
47  .PRx.value = 0xFFFF, // Set period register to maximum
48  };
49 
50 /*********************************************************************************
51  * @fn volatile struct P33C_TIMER_MODULE_s p33c_Timer_ConfigRead(void)
52  * @ingroup lib-layer-pral-functions-public-timer
53  * @brief Read the current configuration from the Timer special function registers
54  * @return Timer special function register data object of type struct P33C_TIMER_MODULE_s
55  *
56  * @details
57  * This function reads all Timer registers with their current configuration
58  * into a data structure of type P33C_TIMER_MODULE_s. Users can verify or
59  * modify the configuration of the Timer peripheral.
60  *
61  *********************************************************************************/
62 
63 volatile struct P33C_TIMER_MODULE_s p33c_Timer_ConfigRead(void)
64 {
65  volatile struct P33C_TIMER_MODULE_s* tmr;
66 
67  // Capture Handle: set pointer to memory address of desired PWM instance
68  tmr = p33c_TimerModule_GetHandle();
69 
70  return(*tmr);
71 }
72 
73 /********************************************************************************
74  * @fn volatile uint16_t p33c_Timer_ConfigWrite(volatile struct P33C_TIMER_MODULE_s ccpConfig)
75  * @ingroup lib-layer-pral-functions-public-timer
76  * @brief Writes a user-defined configuration to the Timer registers
77  * @param tmrConfig Timer special function register data object of type struct P33C_TIMER_MODULE_s
78  * @return 0 = failure, writing to Timer registers was not successful
79  * @return 1 = success, writing to Timer registers was successful
80  *
81  * @details
82  * This function writes a user-defined Timer configuration of type
83  * P33C_TIMER_MODULE_s to the Timer registers. The individual register
84  * configurations have to be set in user-code before calling this function.
85  * To simplify the configuration process of standard functions, this driver
86  * provides templates, which can be loaded and written directly.
87  *
88  *********************************************************************************/
89 
90 volatile uint16_t p33c_Timer_ConfigWrite(volatile struct P33C_TIMER_MODULE_s tmrConfig)
91 {
92  volatile uint16_t retval=1;
93  volatile struct P33C_TIMER_MODULE_s* tmr;
94 
95  // Set pointer to memory address of desired Timer
96  tmr = p33c_TimerModule_GetHandle();
97  *tmr = tmrConfig;
98 
99  return(retval);
100 
101 }
102 
103 // end of file
union P33C_TIMER_MODULE_s::@336 TxCON
volatile struct P33C_TIMER_MODULE_s tmrConfigDefault
Definition: p33c_timer.c:45