Rev 113 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#include "maindefs.h"#include "pwm.h"#include <pwm.h>void pwm_init() {// Configure pins RC5 and RC7 as outputsTRISCbits.TRISC0 = 0;TRISCbits.TRISC1 = 0;TRISCbits.TRISC2 = 0;LATCbits.LATC0 = 0;LATCbits.LATC1 = 0;LATCbits.LATC2 = 0;RPOR11 = 14; // Set RP11 to ECCP1 PWM Output Channel ARPOR12 = 15; // Set RP12 to ECCP1 PWM Output Channel BRPOR13 = 18; // Set RP13 to ECCP2 PWM Output}void pwm_IR_start() {OpenPWM1(0x3D); // 38kHz frequencySetDCPWM1(0x80); // 50% duty cycle// Wait for completion of a full PWM cycle before enabling output modewhile(!PIR1bits.TMR2IF);SetOutputPWM1(SINGLE_OUT, PWM_MODE_1);// Enable ECCP1 output channels A and BPSTR1CONbits.STRA = 1;PSTR1CONbits.STRB = 1;}void pwm_IR_stop() {ClosePWM1();}void pwm_LED_on() {OpenPWM2(0xFF); // Full period from timerSetDCPWM2(0x80); // 50% duty cyclePSTR2CONbits.STRA = 1; // Enable output channel APWM_LED_STATE = 1;}void pwm_LED_off() {ClosePWM2();PWM_LED_STATE = 0;}void pwm_LED_toggle() {if (PWM_LED_STATE) {pwm_LED_off();} else {pwm_LED_on();}}