示例#1
0
文件: main.c 项目: ctapang/v0_70_01b
int main(void)
{
    /* Disable JTAG to free up PORTA pins */
    DDPCONbits.JTAGEN = 0;

    /* Set the lower 8 bits of PORTA as output (for Explorer-16 LEDs),
       clear the bits to ensure there is no mismatch when they are toggled */
    PLIB_PORTS_DirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_A, (PORTS_DATA_MASK)0x00FF);
    PLIB_PORTS_Clear(PORTS_ID_0, PORT_CHANNEL_A, (PORTS_DATA_MASK)0x00FF);

    /* Enable the DMA module */
    PLIB_DMA_Enable(DMA_ID_0);

    /* Channel is continuously enabled */
    PLIB_DMA_ChannelXAutoEnable(DMA_ID_0, DMA_CHANNEL_0);

    /* Set the source and destinaton addresses (addresses are converted from virtual to physical) */
    PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)LED_pattern);
    PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&LATA);

    /* Set the source and destination sizes */
    PLIB_DMA_ChannelXSourceSizeSet(DMA_ID_0, DMA_CHANNEL_0, sizeof(LED_pattern));
    PLIB_DMA_ChannelXDestinationSizeSet(DMA_ID_0, DMA_CHANNEL_0, 1);

    /* Set the number of bytes per transfer */
    PLIB_DMA_ChannelXCellSizeSet(DMA_ID_0, DMA_CHANNEL_0, 1);

    /* DMA transfer to start on Timer 1 interrupt */
    PLIB_DMA_ChannelXTriggerEnable(DMA_ID_0, DMA_CHANNEL_0, DMA_CHANNEL_TRIGGER_TRANSFER_START);
    PLIB_DMA_ChannelXStartIRQSet(DMA_ID_0, DMA_CHANNEL_0, DMA_TRIGGER_TIMER_1);

    /* Setup Timer 1 to trigger an interrupt 10 times a second */
    PLIB_TMR_ClockSourceSelect(TMR_ID_1, TMR_CLOCK_SOURCE_PERIPHERAL_CLOCK);
    PLIB_TMR_PrescaleSelect(TMR_ID_1, TMR_PRESCALE_VALUE_256);
    PLIB_TMR_Counter16BitClear(TMR_ID_1);
    PLIB_TMR_Period16BitSet(TMR_ID_1, 3906);

    /* Enable the Timer 1 interrupt source, set its priority level to 2, set
       its subpriority level to 0 */
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_TIMER_1);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_T1, INT_PRIORITY_LEVEL2);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_T1, INT_SUBPRIORITY_LEVEL0);

    /* Enable multi-vectored interrupts, enable the generation of interrupts to the CPU */
    PLIB_INT_MultiVectorSelect(INT_ID_0);
    PLIB_INT_Enable(INT_ID_0);

    /* Enable DMA channel 0 */
    PLIB_DMA_ChannelXEnable(DMA_ID_0, DMA_CHANNEL_0);

    /* Start Timer 1 */
    PLIB_TMR_Start(TMR_ID_1);

    /* Stuck in this loop, waiting for interrupts to occur */
    while (1);

    /* Program should not go here during normal operation */
    return EXIT_FAILURE;
}
示例#2
0
 // *****************************************************************************
// *****************************************************************************
// Section: Instance 0 static driver functions
// *****************************************************************************
// *****************************************************************************
void DRV_TMR0_Initialize(void)
{	
    /* Initialize Timer Instance0 */
    /* Disable Timer */
    PLIB_TMR_Stop(TMR_ID_2);
    /* Select clock source */
    PLIB_TMR_ClockSourceSelect(TMR_ID_2, TMR_CLOCK_SOURCE_PERIPHERAL_CLOCK);
    /* Select prescalar value */
    PLIB_TMR_PrescaleSelect(TMR_ID_2, TMR_PRESCALE_VALUE_1);
    /* Enable 16 bit mode */
    PLIB_TMR_Mode16BitEnable(TMR_ID_2);
    /* Clear counter */	
    PLIB_TMR_Counter16BitClear(TMR_ID_2);
    /*Set period */	
    PLIB_TMR_Period16BitSet(TMR_ID_2, 2104);

}
 // *****************************************************************************
// *****************************************************************************
// Section: Instance 0 static driver functions
// *****************************************************************************
// *****************************************************************************
void DRV_TMR0_Initialize(void)
{	
    /* Initialize Timer Instance0 */
    /* Disable Timer */
    PLIB_TMR_Stop(TMR_ID_1);
    /* Select clock source */
    PLIB_TMR_ClockSourceSelect(TMR_ID_1, TMR_CLOCK_SOURCE_PERIPHERAL_CLOCK);
    /* Select prescalar value */
    PLIB_TMR_PrescaleSelect(TMR_ID_1, TMR_PRESCALE_VALUE_256);
    /* Enable 32 bit mode */
    PLIB_TMR_Mode32BitEnable(TMR_ID_1);
    /* Clear counter */
    PLIB_TMR_Counter32BitClear(TMR_ID_1);
    /*Set period */	
    PLIB_TMR_Period32BitSet(TMR_ID_1, 1);

    /* Setup Interrupt */   
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_TIMER_1);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_T1, INT_PRIORITY_LEVEL1);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_T1, INT_SUBPRIORITY_LEVEL0);          
}
 // *****************************************************************************
// *****************************************************************************
// Section: Instance 0 static driver functions
// *****************************************************************************
// *****************************************************************************
void DRV_TMR0_Initialize(void)
{	
    /* Initialize Timer Instance0 */
    /* Disable Timer */
    PLIB_TMR_Stop(TMR_ID_3);
    /* Select clock source */
    PLIB_TMR_ClockSourceSelect(TMR_ID_3, TMR_CLOCK_SOURCE_EXTERNAL_INPUT_PIN);
    /* Select prescalar value */
    PLIB_TMR_PrescaleSelect(TMR_ID_3, TMR_PRESCALE_VALUE_1);
    /* Enable 16 bit mode */
    PLIB_TMR_Mode16BitEnable(TMR_ID_3);
    /* Clear counter */	
    PLIB_TMR_Counter16BitClear(TMR_ID_3);
    /*Set period */	
    PLIB_TMR_Period16BitSet(TMR_ID_3, 5);

    /* Setup Interrupt */   
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_TIMER_3);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_T3, INT_PRIORITY_LEVEL1);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_T3, INT_SUBPRIORITY_LEVEL0);          
}
示例#5
0
文件: main.c 项目: ctapang/v0_70_01b
int main(void)
{
    /* PBclk as the timer source, prescaler is 256 (PBclk / 256), enable timer 23
       (timer 2 + timer 3, 32 bit time), clear the counter, set timer period */
    PLIB_TMR_ClockSourceSelect(TMR_ID_2, TMR_CLOCK_SOURCE_PERIPHERAL_CLOCK);
    PLIB_TMR_PrescaleSelect(TMR_ID_2, TMR_PRESCALE_VALUE_256);
    PLIB_TMR_Mode32BitEnable(TMR_ID_2);
    PLIB_TMR_Counter32BitClear(TMR_ID_2);
    PLIB_TMR_Period32BitSet(TMR_ID_2, PERIOD);

    /* Setup input capture to capture only rising edges, captures start
       on first rising edge, use timer 2, use a 32 bit buffer for storing
       the captured timer value, enable the input capture 1 module */
    PLIB_IC_ModeSelect(IC_ID_1, IC_INPUT_CAPTURE_RISING_EDGE_MODE);
    PLIB_IC_FirstCaptureEdgeSelect(IC_ID_1, IC_EDGE_RISING);
    PLIB_IC_TimerSelect(IC_ID_1, IC_TIMER_TMR2);
    PLIB_IC_BufferSizeSelect(IC_ID_1, IC_BUFFER_SIZE_32BIT);
    PLIB_IC_Enable(IC_ID_1);

    /* Enable the input capture 1 interrupt source, set its priority level to 2,
       set its subpriority level to 0 */
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_INPUT_CAPTURE_1);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_IC1, INT_PRIORITY_LEVEL2);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_IC1, INT_SUBPRIORITY_LEVEL0);

    /* Enable multi-vectored interrupts, enable the generation of interrupts to the CPU */
    PLIB_INT_MultiVectorSelect(INT_ID_0);
    PLIB_INT_Enable(INT_ID_0);

    /* Start the timer */
    PLIB_TMR_Start(TMR_ID_2);

    /* Waiting for input capture event (stuck in this loop) */
    while (1);

    /* Program should not go here during normal operation */
    return EXIT_FAILURE;
}
示例#6
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;
    } 
}
示例#7
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
}
示例#8
0
文件: app.c 项目: fokane/LPFgit
void APP_Tasks ( void )
{

    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            tmrInterruptHandle = DRV_TMR_Open(DRV_TMR_INDEX_0, DRV_IO_INTENT_EXCLUSIVE);
            
            if (DRV_HANDLE_INVALID == tmrInterruptHandle)
            {
                // Unable to open the driver
                while(1);
            }
            
            
            
            // based on 80MHz Tpb and 256 PS should be 8192Hz frequency
            DRV_TMR_AlarmRegister(tmrInterruptHandle, 38, true, 0, TimerInterruptCallback);
           
           
            // change state
            appData.state = APP_STATE_SETUP_OC;
            break;
        }

        case APP_STATE_SETUP_OC:
        {
            DRV_OC0_Enable();
            DRV_OC0_Start();
            
            // setup the Timer for OC1 module
            PLIB_TMR_PrescaleSelect(TMR_ID_2, TMR_PRESCALE_VALUE_1);
            PLIB_TMR_Period16BitSet(TMR_ID_2, 9765);
            // start Timer
            DRV_TMR_Start(tmrInterruptHandle);
            PLIB_TMR_Start(TMR_ID_2);
            
            // change state
            appData.state = APP_STATE_IDLE;
            break;
        }
        case APP_STATE_IDLE:
        {
        
            break;
        }

        /* TODO: implement your application state machine.*/
        

        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}