Exemplo n.º 1
0
/*---------------------------------------------------------------------------------------------------------*/
void DACFunctionTest(void)
{

    printf("\n");
    printf("+----------------------------------------------------------------------+\n");
    printf("|                      DAC software trigger test                       |\n");
    printf("+----------------------------------------------------------------------+\n");

    printf("\n\nPlease hit any key to start DAC output\n");
    getchar();

    /* Set the software trigger, enable DAC even trigger mode and enable D/A converter */
    DAC_Open(DAC, 0, DAC_SOFTWARE_TRIGGER);

    /* The DAC conversion settling time is 8us */
    DAC_SetDelayTime(DAC, 8);

    /* Set DAC 12-bit holding data */
    DAC_WRITE_DATA(DAC, 0, sine[index]);

    /* Clear the DAC conversion complete finish flag for safe */
    DAC_CLR_INT_FLAG(DAC, 0);

    /* Enable the DAC interrupt */
    DAC_ENABLE_INT(DAC, 0);
    NVIC_EnableIRQ(DAC_IRQn);

    /* Start A/D conversion */
    DAC_START_CONV(DAC);

    printf("\nHit any key to quit!\n");

    while(1)
    {
        /* Start A/D conversion */
        DAC_START_CONV(DAC);

        if((DEBUG_PORT->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk) != 0)
            continue;
        else
            break;
    }

    return;
}
Exemplo n.º 2
0
int32_t main (void)
{

    /* Init System, IP clock and multi-function I/O
       In the end of SYS_Init() will issue SYS_LockReg()
       to lock protected register. If user want to write
       protected register, please issue SYS_UnlockReg()
       to unlock protected register if necessary */
    SYS_Init();

    /* Init UART0 for printf */
    UART_Open(UART0, 115200);

    printf("\nThis sample code demonstrate Timer 0 trigger DAC channel 0 function.\n");

    // Enable DAC channel 0, trigger by Timer 0.
    DAC_Open(DAC, 0, DAC_TIMER0_TRIGGER);


    // Enable DAC0 interrupt. Enable interrupt for one channel is sufficient in group mode.
    DAC_ENABLE_INT(DAC, 0);
    NVIC_EnableIRQ(DAC_IRQn);

    // Wait 'til both channels are ready
    while(DAC_IS_BUSY(DAC, 0) == 1);

    // Set timer frequency
    TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 100);

    // Enable Timer timeout event trigger DAC
    TIMER_SetTriggerTarget(TIMER0, TIMER_CTL_DAC_TEEN_Msk);

    // Write first data out. timer will 0 will trigger DAC update
    DAC_WRITE_DATA(DAC, 0, a16Sine[index0]);
    index0 = (index0 + 1) % SINE_ARRAY_SIZE;

    // Start Timer 0
    TIMER_Start(TIMER0);

    while(1);

}