Details |
Last modification |
View Log
| RSS feed
| Rev |
Author |
Line No. |
Line |
| 119 |
Kevin |
1 |
#include "maindefs.h"
|
|
|
2 |
#include "pwm.h"
|
|
|
3 |
#include <pwm.h>
|
|
|
4 |
|
|
|
5 |
void pwm_init() {
|
|
|
6 |
// Configure pins RC5 and RC7 as outputs
|
|
|
7 |
TRISCbits.TRISC0 = 0;
|
|
|
8 |
TRISCbits.TRISC1 = 0;
|
|
|
9 |
LATCbits.LATC0 = 0;
|
|
|
10 |
LATCbits.LATC1 = 0;
|
|
|
11 |
|
|
|
12 |
RPOR11 = 14; // Set RP11 to ECCP1 PWM Output Channel A
|
|
|
13 |
RPOR12 = 15; // Set RP12 to ECCP1 PWM Output Channel B
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
void pwm_start() {
|
|
|
17 |
OpenEPWM1(0xFF, ECCP_1_SEL_TMR12); // 38kHz Frequency
|
|
|
18 |
SetDCEPWM1(512); // 50% Duty Cycle
|
|
|
19 |
|
|
|
20 |
// Wait for completion of a full PWM cycle before enabling output mode
|
|
|
21 |
while(!PIR1bits.TMR2IF);
|
|
|
22 |
SetOutputEPWM1(SINGLE_OUT, PWM_MODE_1);
|
|
|
23 |
|
|
|
24 |
// Enable ECCP1 output channels A and B
|
|
|
25 |
PSTR1CONbits.STRA = 1;
|
|
|
26 |
PSTR1CONbits.STRB = 1;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
void pwm_stop() {
|
|
|
30 |
CloseEPWM1();
|
|
|
31 |
}
|