Exemplo n.º 1
0
// StartUp TMR/OC module of MCU
void PWM_StartUp(void) {
    // Enable OC 1
    PLIB_OC_Enable(APP_PWM_OC1_ID);
#ifdef APP_PWM_OC2_ID
    // Enable OC 2
    PLIB_OC_Enable(APP_PWM_OC2_ID);
#endif // ifdef APP_PWM_OC2_ID
#ifdef APP_PWM_OC3_ID
    // Enable OC 3
    PLIB_OC_Enable(APP_PWM_OC3_ID);
#endif // ifdef APP_PWM_OC3_ID
#ifdef APP_PWM_OC4_ID
    // Enable OC 4
    PLIB_OC_Enable(APP_PWM_OC4_ID);
#endif // ifdef APP_PWM_OC4_ID
    // Start the PWM timer
    PLIB_TMR_Start(APP_PWM_TMR_ID);
#ifdef APP_PWM2_OC1_ID
    // Enable PWM2 OC 1
    PLIB_OC_Enable(APP_PWM2_OC1_ID);
#ifdef APP_PWM2_OC2_ID
    // Enable PWM2 OC 2
    PLIB_OC_Enable(APP_PWM2_OC2_ID);
#endif // ifdef APP_PWM2_OC2_ID
    // Start the PWM2 timer
    PLIB_TMR_Start(APP_PWM2_TMR_ID);
#endif // ifdef APP_PWM2_OC1_ID
}
Exemplo n.º 2
0
void DRV_OC0_Start(void)
{
   PLIB_OC_Enable(OC_ID_1);
}
Exemplo n.º 3
0
void DRV_OC1_Start(void)
{
   PLIB_OC_Enable(OC_ID_2);
}
Exemplo n.º 4
0
void PWM2_SetValues(
    TMR_PRESCALE pwmPreScale
,   int pwmCycle
,   int pwmStart1
,   int pwmStop1
,   int pwmStart2
,   int pwmStop2
) {
    if ((pwmPreScale == TMR_PRESCALE_VALUE_1) & (pwmCycle < 400)) {
        PWM2_doInt = false;
    }
    if ((pwmPreScale != PWM2_PreScale) | !PWM2_doInt) {
        // total update
        // Disable Interrupt / Clear Flag
        PLIB_INT_SourceDisable(APP_INT_ID, APP_PWM2_TMR_INT_SOURCE);
        PLIB_INT_SourceFlagClear(APP_INT_ID, APP_PWM2_TMR_INT_SOURCE);
        // Stop the timer
        PLIB_TMR_Stop(APP_PWM2_TMR_ID);
        // Disable OC's
        PLIB_OC_Disable(APP_PWM2_OC1_ID);
#ifdef APP_PWM2_OC2_ID
        PLIB_OC_Disable(APP_PWM2_OC2_ID);
#endif // ifdef APP_PWM2_OC2_ID
        PWM2_PreScale = pwmPreScale;
        PWM2_Cycle = pwmCycle;
        PWM2_Start1 = pwmStart1;
        PWM2_Stop1 = pwmStop1;
        PWM2_Start2 = pwmStart2;
        PWM2_Stop2 = pwmStop2;
        // Set the prescaler, and set the clock source as internal
        PLIB_TMR_PrescaleSelect(APP_PWM2_TMR_ID, pwmPreScale);
        // Clear the timer
        PLIB_TMR_Counter16BitClear(APP_PWM2_TMR_ID);
        // Load the period register
        PLIB_TMR_Period16BitSet(APP_PWM2_TMR_ID, pwmCycle);
        // OC1 Init
        // Set buffer(primary compare) value
        PLIB_OC_Buffer16BitSet(APP_PWM2_OC1_ID, pwmStart1);
        // Set pulse width(secondary compare) value
        PLIB_OC_PulseWidth16BitSet(APP_PWM2_OC1_ID, pwmStop1);
#ifdef APP_PWM2_OC2_ID
        // OC2 Init
        // Set buffer(primary compare) value
        PLIB_OC_Buffer16BitSet(APP_PWM2_OC2_ID, pwmStart2);
        // Set pulse width(secondary compare) value
        PLIB_OC_PulseWidth16BitSet(APP_PWM2_OC2_ID, pwmStop2);
#endif // ifdef APP_PWM2_OC2_ID
        // Enable OC 1
        PLIB_OC_Enable(APP_PWM2_OC1_ID);
#ifdef APP_PWM2_OC2_ID
        // Enable OC 2
        PLIB_OC_Enable(APP_PWM2_OC2_ID);
#endif // ifdef APP_PWM2_OC2_ID
        if ((PWM2_PreScale == TMR_PRESCALE_VALUE_1) & (PWM2_Cycle < 400)) {
            PWM2_doInt = false;
        } else {
            PWM2_doInt = true;
            // Reenable Interrupt
            PLIB_INT_SourceEnable(APP_INT_ID, APP_PWM2_TMR_INT_SOURCE);
        }
        // Start the timer
        PLIB_TMR_Start(APP_PWM2_TMR_ID);
    } else {
        // continuos update
        PWM2_Cycle = pwmCycle;
        PWM2_Start1 = pwmStart1;
        PWM2_Stop1 = pwmStop1;
        PWM2_Start2 = pwmStart2;
        PWM2_Stop2 = pwmStop2;
    } 
}
Exemplo n.º 5
0
void DRV_OC8_Start(void)
{
    PLIB_OC_Enable(OC_ID_9);
}
Exemplo n.º 6
0
void DRV_OC2_Start(void)
{
   PLIB_OC_Enable(OC_ID_3);
}
Exemplo n.º 7
0
void DRV_OC7_Start(void)
{
    PLIB_OC_Enable(OC_ID_8);
}
Exemplo n.º 8
0
void DRV_OC6_Start(void)
{
    PLIB_OC_Enable(OC_ID_7);
}
Exemplo n.º 9
0
void DRV_OC5_Start(void)
{
    PLIB_OC_Enable(OC_ID_6);
}
Exemplo n.º 10
0
void DRV_OC4_Start(void)
{
    PLIB_OC_Enable(OC_ID_5);
}
Exemplo n.º 11
0
void DRV_OC3_Start(void)
{
    PLIB_OC_Enable(OC_ID_4);
}