root/RF_BT_Tail/mcc_generated_files/pwm2.c

Revision 244, 4.5 kB (checked in by phil, 4 years ago)

added initial Tail Source Package

Line 
1 /**
2   PWM2 Generated Driver File
3
4   @Company
5     Microchip Technology Inc.
6
7   @File Name
8     pwm2.c
9
10   @Summary
11     This is the generated driver implementation file for the PWM2 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
12
13   @Description
14     This header file provides implementations for driver APIs for PWM2.
15     Generation Information :
16         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2
17         Device            :  PIC16F1579
18         Driver Version    :  2.01
19     The generated drivers are tested against the following:
20         Compiler          :  XC8 1.45 or later
21         MPLAB             :  MPLAB X 4.15
22 */
23
24 /*
25     (c) 2018 Microchip Technology Inc. and its subsidiaries.
26    
27     Subject to your compliance with these terms, you may use Microchip software and any
28     derivatives exclusively with Microchip products. It is your responsibility to comply with third party
29     license terms applicable to your use of third party software (including open source software) that
30     may accompany Microchip software.
31    
32     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
33     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
34     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
35     FOR A PARTICULAR PURPOSE.
36    
37     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
38     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
39     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
40     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
41     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
42     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
43     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
44     SOFTWARE.
45 */
46
47 /**
48   Section: Included Files
49 */
50
51 #include <xc.h>
52 #include "pwm2.h"
53
54 /**
55   Section: PWM2 APIs
56 */
57
58 void PWM2_Initialize(void)
59 {
60     // set the PWM2 to the options selected in the User Interface
61
62      //PHIE disabled; DCIE disabled; OFIE disabled; PRIE disabled;
63     PWM2INTE = 0x00;
64
65      //PHIF cleared; OFIF cleared; DCIF cleared; PRIF cleared;
66     PWM2INTF = 0x00;
67
68      //PS Divide_clock_src_by_4; CS FOSC;
69     PWM2CLKCON = 0x20;
70
71      //LDS LD1_trigger; LDT disabled; LDA do_not_load;
72     PWM2LDCON = 0x00;
73
74      //OFM independent_run; OFS OF1_match; OFO match_incrementing;
75     PWM2OFCON = 0x00;
76
77      //PWM2PHH 0;
78     PWM2PHH = 0x00;
79
80      //PWM2PHL 0;
81     PWM2PHL = 0x00;
82
83      //PWM2DCH 10;
84     PWM2DCH = 0x0A;
85
86      //PWM2DCL 240;
87     PWM2DCL = 0xF0;
88
89      //PWM2PRH 156;
90     PWM2PRH = 0x9C;
91
92      //PWM2PRL 63;
93     PWM2PRL = 0x3F;
94
95      //PWM2OFH 0;
96     PWM2OFH = 0x00;
97
98      //PWM2OFL 1;
99     PWM2OFL = 0x01;
100
101      //PWM2TMRH 0;
102     PWM2TMRH = 0x00;
103
104      //PWM2TMRL 0;
105     PWM2TMRL = 0x00;
106
107      //MODE standard_PWM; POL active_hi; EN enabled;
108     PWM2CON = 0x80;
109
110 }   
111
112
113 void PWM2_Start(void)
114 {
115     PWM2CONbits.EN = 1;         
116 }
117
118 void PWM2_Stop(void)
119 {
120     PWM2CONbits.EN = 0;         
121 }
122
123 bool PWM2_CheckOutputStatus(void)
124 {
125     return (PWM2CONbits.OUT);           
126 }
127
128 void PWM2_LoadBufferSet(void)
129 {
130     PWM2LDCONbits.LDA = 1;             
131 }
132
133 void PWM2_PhaseSet(uint16_t phaseCount)
134 {
135     PWM2PHH = (phaseCount>>8);        //writing 8 MSBs to PWMPHH register
136     PWM2PHL = (phaseCount);           //writing 8 LSBs to PWMPHL register
137 }
138
139 void PWM2_DutyCycleSet(uint16_t dutyCycleCount)
140 {
141     PWM2DCH = (dutyCycleCount>>8);      //writing 8 MSBs to PWMDCH register
142     PWM2DCL = (dutyCycleCount); //writing 8 LSBs to PWMDCL register             
143 }
144
145 void PWM2_PeriodSet(uint16_t periodCount)
146 {
147     PWM2PRH = (periodCount>>8); //writing 8 MSBs to PWMPRH register
148     PWM2PRL = (periodCount);    //writing 8 LSBs to PWMPRL register             
149 }
150
151 void PWM2_OffsetSet(uint16_t offsetCount)
152 {
153     PWM2OFH = (offsetCount>>8); //writing 8 MSBs to PWMOFH register
154     PWM2OFL = (offsetCount);    //writing 8 LSBs to PWMOFL register             
155 }
156
157 uint16_t PWM2_TimerCountGet(void)
158 {
159     return ((uint16_t)((PWM2TMRH<<8) | PWM2TMRL));                     
160 }
161
162 bool PWM2_IsOffsetMatchOccured(void)
163 {
164     return (PWM2INTFbits.OFIF);         
165 }
166
167 bool PWM2_IsPhaseMatchOccured(void)
168 {
169     return (PWM2INTFbits.PHIF);
170 }
171
172 bool PWM2_IsDutyCycleMatchOccured(void)
173 {
174     return (PWM2INTFbits.DCIF);         
175 }
176
177 bool PWM2_IsPeriodMatchOccured(void)
178 {
179     return (PWM2INTFbits.PRIF);         
180 }
181
182 /**
183  End of File
184 */
185
186
Note: See TracBrowser for help on using the browser.