Example #1
0
// *****************************************************************************
// *****************************************************************************
// Section: Instance 0 static driver functions
// *****************************************************************************
// *****************************************************************************
void DRV_OC0_Initialize(void)
{	
    /* Setup OC0 Instance */
    PLIB_OC_ModeSelect(OC_ID_1, OC_COMPARE_PWM_MODE_WITH_FAULT_PROTECTION);
    PLIB_OC_BufferSizeSelect(OC_ID_1, OC_BUFFER_SIZE_16BIT);
    PLIB_OC_TimerSelect(OC_ID_1, OC_TIMER_16BIT_TMR2);
    PLIB_OC_FaultInputSelect(OC_ID_1, OC_FAULT_DISABLE);
    PLIB_OC_Buffer16BitSet(OC_ID_1, 0);
    PLIB_OC_PulseWidth16BitSet(OC_ID_1, 200);
}
Example #2
0
// *****************************************************************************
// *****************************************************************************
// Section: Instance 8 static driver functions
// *****************************************************************************
// *****************************************************************************
void DRV_OC8_Initialize(void)
{
    /* Setup OC0 Instance */
    PLIB_OC_ModeSelect(OC_ID_9, OC_COMPARE_TURN_OFF_MODE);
    PLIB_OC_BufferSizeSelect(OC_ID_9, OC_BUFFER_SIZE_16BIT);
    PLIB_OC_TimerSelect(OC_ID_9, OC_TIMER_16BIT_TMR2);
    PLIB_OC_FaultInputSelect(OC_ID_9, OC_FAULT_DISABLE);
    PLIB_OC_Buffer16BitSet(OC_ID_9, 0);
    PLIB_OC_PulseWidth16BitSet(OC_ID_9, 10);
}
Example #3
0
void PWM_Initialize(void) {
    // Timer Init
    // Stop the timers
    PLIB_TMR_Stop(APP_PWM_TMR_ID);
#ifdef APP_PWM2_OC1_ID
    PLIB_TMR_Stop(APP_PWM2_TMR_ID);
#endif //ifdef APP_PWM2_OC1_ID
    // Disable OC's
    PLIB_OC_Disable(APP_PWM_OC1_ID);
#ifdef APP_PWM_OC2_ID
    PLIB_OC_Disable(APP_PWM_OC2_ID);
#endif // ifdef APP_PWM_OC2_ID
#ifdef APP_PWM_OC3_ID
    PLIB_OC_Disable(APP_PWM_OC3_ID);
#endif // ifdef APP_PWM_OC3_ID
#ifdef APP_PWM_OC4_ID
    PLIB_OC_Disable(APP_PWM_OC4_ID);
#endif // ifdef APP_PWM_OC4_ID
#ifdef APP_PWM2_OC1_ID
    PLIB_OC_Disable(APP_PWM2_OC1_ID);
#endif // ifdef APP_PWM2_OC1_ID
#ifdef APP_PWM2_OC2_ID
    PLIB_OC_Disable(APP_PWM2_OC2_ID);
#endif // ifdef APP_PWM2_OC2_ID
    // Set the prescaler, and set the clock source as internal
    PLIB_TMR_ClockSourceSelect(APP_PWM_TMR_ID, TMR_CLOCK_SOURCE_PERIPHERAL_CLOCK);
    PLIB_TMR_PrescaleSelect(APP_PWM_TMR_ID, APP_PWM_TMR_PRESCALE);
    PWM_PreScale = APP_PWM_TMR_PRESCALE;
    // Clear the timer
    PLIB_TMR_Counter16BitClear(APP_PWM_TMR_ID);
    // Load the period register
    PLIB_TMR_Period16BitSet(APP_PWM_TMR_ID, APP_PWM_TMR_INIT);
    PWM_Cycle = APP_PWM_TMR_INIT;
#ifdef APP_PWM2_OC1_ID
    PLIB_TMR_ClockSourceSelect(APP_PWM2_TMR_ID, TMR_CLOCK_SOURCE_PERIPHERAL_CLOCK);
    PLIB_TMR_PrescaleSelect(APP_PWM2_TMR_ID, APP_PWM2_TMR_PRESCALE);
    PWM2_PreScale = APP_PWM2_TMR_PRESCALE;
    // Clear the timer
    PLIB_TMR_Counter16BitClear(APP_PWM2_TMR_ID);
    // Load the period register
    PLIB_TMR_Period16BitSet(APP_PWM2_TMR_ID, APP_PWM2_TMR_INIT);
    PWM2_Cycle = APP_PWM2_TMR_INIT;
#endif // ifdef APP_PWM2_OC1_ID
    // OC1 Init
    // port inits
    PLIB_PORTS_PinClear(APP_PWM_OC1_PORTS_ID, APP_PWM_OC1_PORT_CHANNEL, APP_PWM_OC1_PIN);
    PLIB_PORTS_PinDirectionOutputSet(APP_PWM_OC1_PORTS_ID, APP_PWM_OC1_PORT_CHANNEL, APP_PWM_OC1_PIN);
    APP_PWM_OC1_Mode;
    PLIB_PORTS_RemapOutput(APP_PWM_OC1_PORTS_ID, APP_PWM_OC1_Function, APP_PWM_OC1_PPSOut);
    //Select timer base 
    PLIB_OC_TimerSelect(APP_PWM_OC1_ID, APP_PWM_OC_TMR_BASE);
    // Select compare mode 
    PLIB_OC_ModeSelect(APP_PWM_OC1_ID, OC_DUAL_COMPARE_CONTINUOUS_PULSE_MODE);
    // Set buffer size to 16-bits
    PLIB_OC_BufferSizeSelect(APP_PWM_OC1_ID, OC_BUFFER_SIZE_16BIT);
    // Set buffer(primary compare) value
    PLIB_OC_Buffer16BitSet(APP_PWM_OC1_ID, APP_PWM_OC1_On);
    PWM_Start1 = APP_PWM_OC1_On;
    // Set pulse width(secondary compare) value
    PLIB_OC_PulseWidth16BitSet(APP_PWM_OC1_ID, APP_PWM_OC1_Off);
    PWM_Stop1 = APP_PWM_OC1_Off;
#ifdef APP_PWM_OC2_ID
    // OC2 Init
    // port inits
    PLIB_PORTS_PinClear(APP_PWM_OC2_PORTS_ID, APP_PWM_OC2_PORT_CHANNEL, APP_PWM_OC2_PIN);
    PLIB_PORTS_PinDirectionOutputSet(APP_PWM_OC2_PORTS_ID, APP_PWM_OC2_PORT_CHANNEL, APP_PWM_OC2_PIN);
    APP_PWM_OC2_Mode;
    PLIB_PORTS_RemapOutput(APP_PWM_OC2_PORTS_ID, APP_PWM_OC2_Function, APP_PWM_OC2_PPSOut);
    //Select timer base 
    PLIB_OC_TimerSelect(APP_PWM_OC2_ID, APP_PWM_OC_TMR_BASE);
    // Select compare mode
    PLIB_OC_ModeSelect(APP_PWM_OC2_ID, OC_DUAL_COMPARE_CONTINUOUS_PULSE_MODE);
    // Set buffer size to 16-bits
    PLIB_OC_BufferSizeSelect(APP_PWM_OC2_ID, OC_BUFFER_SIZE_16BIT);
    // Set buffer(primary compare) value
    PLIB_OC_Buffer16BitSet(APP_PWM_OC2_ID, APP_PWM_OC2_On);
    PWM_Start2 = APP_PWM_OC2_On;
    // Set pulse width(secondary compare) value
    PLIB_OC_PulseWidth16BitSet(APP_PWM_OC2_ID, APP_PWM_OC2_Off);
    PWM_Stop2 = APP_PWM_OC2_Off;
#endif // ifdef APP_PWM_OC2_ID
#ifdef APP_PWM_OC3_ID
    // OC3 Init
    // port inits
    PLIB_PORTS_PinClear(APP_PWM_OC3_PORTS_ID, APP_PWM_OC3_PORT_CHANNEL, APP_PWM_OC3_PIN);
    PLIB_PORTS_PinDirectionOutputSet(APP_PWM_OC3_PORTS_ID, APP_PWM_OC3_PORT_CHANNEL, APP_PWM_OC3_PIN);
    APP_PWM_OC3_Mode;
    PLIB_PORTS_RemapOutput(APP_PWM_OC3_PORTS_ID, APP_PWM_OC3_Function, APP_PWM_OC3_PPSOut);
    //Select timer base 
    PLIB_OC_TimerSelect(APP_PWM_OC3_ID, APP_PWM_OC_TMR_BASE);
    // Select compare mode
    PLIB_OC_ModeSelect(APP_PWM_OC3_ID, OC_DUAL_COMPARE_CONTINUOUS_PULSE_MODE);
    // Set buffer size to 16-bits
    PLIB_OC_BufferSizeSelect(APP_PWM_OC3_ID, OC_BUFFER_SIZE_16BIT);
    // Set buffer(primary compare) value
    PLIB_OC_Buffer16BitSet(APP_PWM_OC3_ID, APP_PWM_OC3_On);
    PWM_Start3 = APP_PWM_OC3_On;
    // Set pulse width(secondary compare) value
    PLIB_OC_PulseWidth16BitSet(APP_PWM_OC3_ID, APP_PWM_OC3_Off);
    PWM_Stop3 = APP_PWM_OC3_Off;
#endif // ifdef APP_PWM_OC3_ID
#ifdef APP_PWM_OC4_ID
    // OC4 Init
    // port inits
    PLIB_PORTS_PinClear(APP_PWM_OC4_PORTS_ID, APP_PWM_OC4_PORT_CHANNEL, APP_PWM_OC4_PIN);
    PLIB_PORTS_PinDirectionOutputSet(APP_PWM_OC4_PORTS_ID, APP_PWM_OC4_PORT_CHANNEL, APP_PWM_OC4_PIN);
    APP_PWM_OC4_Mode;
    PLIB_PORTS_RemapOutput(APP_PWM_OC4_PORTS_ID, APP_PWM_OC4_Function, APP_PWM_OC4_PPSOut);
    //Select timer base 
    PLIB_OC_TimerSelect(APP_PWM_OC4_ID, APP_PWM_OC_TMR_BASE);
    // Select compare mode
    PLIB_OC_ModeSelect(APP_PWM_OC4_ID, OC_DUAL_COMPARE_CONTINUOUS_PULSE_MODE);
    // Set buffer size to 16-bits
    PLIB_OC_BufferSizeSelect(APP_PWM_OC4_ID, OC_BUFFER_SIZE_16BIT);
    // Set buffer(primary compare) value
    PLIB_OC_Buffer16BitSet(APP_PWM_OC4_ID, APP_PWM_OC4_On);
    PWM_Start4 = APP_PWM_OC4_On;
    // Set pulse width(secondary compare) value
    PLIB_OC_PulseWidth16BitSet(APP_PWM_OC4_ID, APP_PWM_OC4_Off);
    PWM_Stop4 = APP_PWM_OC4_Off;
#endif // ifdef APP_PWM_OC4_ID
#ifdef APP_PWM2_OC1_ID
    // PWM2 / OC1 Init
    // port inits
    PLIB_PORTS_PinClear(APP_PWM2_OC1_PORTS_ID, APP_PWM2_OC1_PORT_CHANNEL, APP_PWM2_OC1_PIN);
    PLIB_PORTS_PinDirectionOutputSet(APP_PWM2_OC1_PORTS_ID, APP_PWM2_OC1_PORT_CHANNEL, APP_PWM2_OC1_PIN);
    APP_PWM2_OC1_Mode;
    PLIB_PORTS_RemapOutput(APP_PWM2_OC1_PORTS_ID, APP_PWM2_OC1_Function, APP_PWM2_OC1_PPSOut);
    //Select timer base 
    PLIB_OC_TimerSelect(APP_PWM2_OC1_ID, APP_PWM2_OC_TMR_BASE);
    // Select compare mode
    PLIB_OC_ModeSelect(APP_PWM2_OC1_ID, OC_DUAL_COMPARE_CONTINUOUS_PULSE_MODE);
    // Set buffer size to 16-bits
    PLIB_OC_BufferSizeSelect(APP_PWM2_OC1_ID, OC_BUFFER_SIZE_16BIT);
    // Set buffer(primary compare) value
    PLIB_OC_Buffer16BitSet(APP_PWM2_OC1_ID, APP_PWM2_OC1_On);
    PWM2_Start1 = APP_PWM2_OC1_On;
    // Set pulse width(secondary compare) value
    PLIB_OC_PulseWidth16BitSet(APP_PWM2_OC1_ID, APP_PWM2_OC1_Off);
    PWM2_Stop1 = APP_PWM2_OC1_Off;
#endif // ifdef APP_PWM2_OC1_ID
#ifdef APP_PWM2_OC2_ID
    // PWM2 / OC2 Init
    // port inits
    PLIB_PORTS_PinClear(APP_PWM2_OC2_PORTS_ID, APP_PWM2_OC2_PORT_CHANNEL, APP_PWM2_OC2_PIN);
    PLIB_PORTS_PinDirectionOutputSet(APP_PWM2_OC2_PORTS_ID, APP_PWM2_OC2_PORT_CHANNEL, APP_PWM2_OC2_PIN);
    APP_PWM2_OC2_Mode;
    PLIB_PORTS_RemapOutput(APP_PWM2_OC2_PORTS_ID, APP_PWM2_OC2_Function, APP_PWM2_OC2_PPSOut);
    //Select timer base 
    PLIB_OC_TimerSelect(APP_PWM2_OC1_ID, APP_PWM2_OC_TMR_BASE);
    // Select compare mode
    PLIB_OC_ModeSelect(APP_PWM2_OC2_ID, OC_DUAL_COMPARE_CONTINUOUS_PULSE_MODE);
    // Set buffer size to 16-bits
    PLIB_OC_BufferSizeSelect(APP_PWM2_OC2_ID, OC_BUFFER_SIZE_16BIT);
    // Set buffer(primary compare) value
    PLIB_OC_Buffer16BitSet(APP_PWM2_OC2_ID, APP_PWM2_OC2_On);
    PWM2_Start2 = APP_PWM2_OC2_On;
    // Set pulse width(secondary compare) value
    PLIB_OC_PulseWidth16BitSet(APP_PWM2_OC2_ID, APP_PWM2_OC2_Off);
    PWM2_Stop2 = APP_PWM2_OC2_Off;
#endif // ifdef APP_PWM2_OC2_ID
}