Subversion Repositories Code-Repo

Rev

Rev 114 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
113 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
    TRISCbits.TRISC2 = 0;
10
    LATCbits.LATC0 = 0;
11
    LATCbits.LATC1 = 0;
12
    LATCbits.LATC2 = 0;
13
 
14
    RPOR11 = 14;    // Set RP11 to ECCP1 PWM Output Channel A
15
    RPOR12 = 15;    // Set RP12 to ECCP1 PWM Output Channel B
115 Kevin 16
#ifdef _REMOTE
113 Kevin 17
    RPOR13 = 18;    // Set RP13 to ECCP2 PWM Output
115 Kevin 18
#endif
113 Kevin 19
}
20
 
21
void pwm_IR_start() {
22
    OpenPWM1(0x3D);  // 38kHz frequency
23
    SetDCPWM1(0x80);  // 50% duty cycle
24
 
25
    // Wait for completion of a full PWM cycle before enabling output mode
26
    while(!PIR1bits.TMR2IF);
27
    SetOutputPWM1(SINGLE_OUT, PWM_MODE_1);
28
 
29
    // Enable ECCP1 output channels A and B
30
    PSTR1CONbits.STRA = 1;
31
    PSTR1CONbits.STRB = 1;
32
}
33
 
34
void pwm_IR_stop() {
35
    ClosePWM1();
36
}
37
 
114 Kevin 38
void pwm_LED_on() {
115 Kevin 39
#ifdef _REMOTE
113 Kevin 40
    OpenPWM2(0xFF);     // Full period from timer
41
    SetDCPWM2(0x80);    // 50% duty cycle
42
    PSTR2CONbits.STRA = 1;  // Enable output channel A
115 Kevin 43
#endif
44
#ifdef _BASE_STATION
45
    LATCbits.LATC2 = 1;
46
#endif
114 Kevin 47
    PWM_LED_STATE = 1;
113 Kevin 48
}
49
 
114 Kevin 50
void pwm_LED_off() {
115 Kevin 51
#ifdef _REMOTE
113 Kevin 52
    ClosePWM2();
115 Kevin 53
#endif
54
#ifdef _BASE_STATION
55
    LATCbits.LATC2 = 0;
56
#endif
114 Kevin 57
    PWM_LED_STATE = 0;
58
}
59
 
60
void pwm_LED_toggle() {
61
    if (PWM_LED_STATE) {
62
        pwm_LED_off();
63
    } else {
64
        pwm_LED_on();
65
    }
113 Kevin 66
}