Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
sccp3.c
Go to the documentation of this file.
1
17/*
18© [2024] Microchip Technology Inc. and its subsidiaries.
19
20 Subject to your compliance with these terms, you may use Microchip
21 software and any derivatives exclusively with Microchip products.
22 You are responsible for complying with 3rd party license terms
23 applicable to your use of 3rd party software (including open source
24 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
25 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
26 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
27 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
28 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
29 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
30 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
31 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
32 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
33 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
34 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
35 THIS SOFTWARE.
36*/
37
38// Section: Included Files
39
40#include <xc.h>
41#include <stddef.h>
42#include "../sccp3.h"
43
44// Section: File specific functions
45
46static void (*SCCP3_PWMHandler)(void) = NULL;
47
48// Section: Driver Interface
49
50const struct PWM_INTERFACE FAN_PWM = {
52 .Deinitialize = &SCCP3_PWM_Deinitialize,
53 .Enable = &SCCP3_PWM_Enable,
54 .Disable = &SCCP3_PWM_Disable,
55 .PeriodSet = &SCCP3_PWM_PeriodSet,
56 .DutyCycleSet = &SCCP3_PWM_DutyCycleSet,
57 .SoftwareTriggerSet = &SCCP3_PWM_SoftwareTriggerSet,
58 .DeadTimeSet = NULL,
59 .OutputModeSet = NULL,
60 .CallbackRegister = &SCCP3_PWM_CallbackRegister,
61 .Tasks = &SCCP3_PWM_Tasks
62};
63
64// Section: SCCP3 Module APIs
65
67{
68 // MOD Dual Edge Compare, Buffered(PWM); CCSEL disabled; TMR32 16 Bit; TMRPS 1:1; CLKSEL FOSC/2; TMRSYNC disabled; CCPSLP disabled; CCPSIDL disabled; CCPON disabled;
69 CCP3CON1L = 0x5;
70 // SYNC None; ALTSYNC disabled; ONESHOT disabled; TRIGEN disabled; IOPS Each Time Base Period Match; RTRGEN disabled; OPSRC Timer Interrupt Event;
71 CCP3CON1H = 0x0;
72 // ASDG 0x0; SSDG disabled; ASDGM disabled; PWMRSEN disabled;
73 CCP3CON2L = 0x0;
74 // ICSEL ; AUXOUT Disabled; ICGSM Level-Sensitive mode; OCAEN enabled; OENSYNC disabled;
75 CCP3CON2H = 0x100;
76 // PSSACE Tri-state; POLACE disabled; OSCNT None; OETRIG disabled;
77 CCP3CON3H = 0x0;
78 // ICOV disabled; ICDIS disabled; SCEVT disabled; ASEVT disabled; TRCLR disabled; TRSET disabled; ICGARM disabled;
79 CCP3STATL = 0x0;
80 // TMRL 0x0000;
81 CCP3TMRL = 0x0;
82 // TMRH 0x0000;
83 CCP3TMRH = 0x0;
84 // PRL 5000;
85 CCP3PRL = 0x1388;
86 // PRH 0;
87 CCP3PRH = 0x0;
88 // CMPA 0;
89 CCP3RA = 0x0;
90 // CMPB 0;
91 CCP3RB = 0x0;
92 // BUFL 0x0000;
93 CCP3BUFL = 0x0;
94 // BUFH 0x0000;
95 CCP3BUFH = 0x0;
97
98 CCP3CON1Lbits.CCPON = 1; //Enable Module
99}
100
102{
103 CCP3CON1Lbits.CCPON = 0;
104
105 CCP3CON1L = 0x0;
106 CCP3CON1H = 0x0;
107 CCP3CON2L = 0x0;
108 CCP3CON2H = 0x100;
109 CCP3CON3H = 0x0;
110 CCP3STATL = 0x0;
111 CCP3TMRL = 0x0;
112 CCP3TMRH = 0x0;
113 CCP3PRL = 0xFFFF;
114 CCP3PRH = 0xFFFF;
115 CCP3RA = 0x0;
116 CCP3RB = 0x0;
117 CCP3BUFL = 0x0;
118 CCP3BUFH = 0x0;
119}
120
122{
123 CCP3CON1Lbits.CCPON = 1;
124}
125
126
128{
129 CCP3CON1Lbits.CCPON = 0;
130}
131
132void SCCP3_PWM_PeriodSet(size_t periodCount)
133{
134 CCP3PRL = periodCount;
135}
136
137void SCCP3_PWM_DutyCycleSet(size_t dutyCycleCount)
138{
139 CCP3RB = dutyCycleCount;
140}
141
143{
144 CCP3STATLbits.TRSET = 1;
145}
146
147void SCCP3_PWM_CallbackRegister(void (*handler)(void))
148{
149 if(NULL != handler)
150 {
151 SCCP3_PWMHandler = handler;
152 }
153}
154
155void __attribute__ ((weak)) SCCP3_PWM_Callback ( void )
156{
157
158}
159
160
161void SCCP3_PWM_Tasks( void )
162{
163 if(IFS2bits.CCT3IF == 1)
164 {
165 // SCCP3 callback function
166 if(NULL != SCCP3_PWMHandler)
167 {
168 (*SCCP3_PWMHandler)();
169 }
170 IFS2bits.CCT3IF = 0;
171 }
172}
void __attribute__((weak))
Definition sccp3.c:155
static void(* SCCP3_PWMHandler)(void)
Definition sccp3.c:46
void SCCP3_PWM_PeriodSet(size_t periodCount)
Sets the cycle width.
Definition sccp3.c:132
void SCCP3_PWM_Callback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
void SCCP3_PWM_Disable(void)
Disables the SCCP3 module.
Definition sccp3.c:127
void SCCP3_PWM_DutyCycleSet(size_t dutyCycleCount)
Sets the ON pulse width.
Definition sccp3.c:137
void SCCP3_PWM_Enable(void)
Enables the SCCP3 module.
Definition sccp3.c:121
void SCCP3_PWM_Deinitialize(void)
Deinitializes the SCCP3 to POR values.
Definition sccp3.c:101
void SCCP3_PWM_Initialize(void)
Initializes the SCCP3 Pulse driver. This function must be called before any other SCCP3 function is c...
Definition sccp3.c:66
void SCCP3_PWM_Tasks(void)
This function is used to implement the tasks for polled implementations.
Definition sccp3.c:161
void SCCP3_PWM_SoftwareTriggerSet(void)
This function sets the manual trigger.
Definition sccp3.c:142
const struct PWM_INTERFACE FAN_PWM
Structure object of type PWM_INTERFACE with the custom name given by the user in the Melody Driver Us...
Definition sccp3.c:50
void SCCP3_PWM_CallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for SCCP3 PWM ev...
Definition sccp3.c:147
Structure containing the function pointers of PWM generator driver.
void(* Initialize)(void)
Pointer to SCCPx_PWM_Initialize e.g. SCCP1_PWM_Initialize.