예제 #1
0
파일: acquire.c 프로젝트: pi19404/Embedded
//*****************************************************************************
//
// This function initializes the ADC hardware in preparation for data
// acquisition.
//
//*****************************************************************************
void
AcquireInit(void)
{
    unsigned long ulChan;

    //
    // Enable the ADC peripherals and the associated GPIO port
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);

    ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);

    ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |GPIO_PIN_7 | GPIO_PIN_3);
    ROM_GPIOPinTypeADC(GPIO_PORTP_BASE, GPIO_PIN_0);

//    ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
    //ROM_ADCR

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    HWREG(GPIO_PORTB_BASE + GPIO_O_AMSEL) |= GPIO_PIN_6;
    ADCSequenceDisable(ADC0_BASE,SEQUENCER);

    ROM_ADCSequenceConfigure(ADC0_BASE, SEQUENCER, ADC_TRIGGER_TIMER, 0);

    for(ulChan = 0; ulChan < 2; ulChan++)
    {
        unsigned long ulChCtl;


        if (ulChan ==1)
        {

            ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH1|ADC_CTL_IE | ADC_CTL_END);
        }
        else if(ulChan==0)
        {
        	ulChCtl = ADC_CTL_CH0;
        	ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH0);
        }


    }

    ADCHardwareOversampleConfigure(ADC0_BASE, 1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER );

    //100 micro
    unsigned long freq=SAMPLING_FREQUENCY;
    unsigned long period=(2*ROM_SysCtlClockGet()/(freq));

    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A,period);
    ROM_TimerControlTrigger(TIMER0_BASE, TIMER_A, true);

    //ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
    //ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() /2);




    CFAL96x64x16Init();
    GrContextInit(&sDisplayContext, &g_sCFAL96x64x16);
    sRect1.sXMin = 0;
    sRect1.sYMin = 0;
    sRect1.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1;
    sRect1.sYMax = 23;

    sRect2.sXMin = 0;
    sRect2.sYMin = 23;
    sRect2.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1;
    sRect2.sYMax = GrContextDpyHeightGet(&sDisplayContext) - 1;


	snprintf(text,sizeof(text),"STart");


    GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect1);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    //GrRectDraw(&sDisplayContext, &sRect1);
    GrContextFontSet(&sDisplayContext, g_pFontCm12);
    GrStringDrawCentered(&sDisplayContext,text, -1,
                         GrContextDpyWidthGet(&sDisplayContext) / 2, 10, 0);

    //GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    //GrRectFill(&sDisplayContext, &sRect1);
    //GrContextForegroundSet(&sDisplayContext, ClrWhite);
    //GrRectDraw(&sDisplayContext, &sRect1);

    /*GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect2);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    GrRectDraw(&sDisplayContext, &sRect2);
*/
    compute_filter();
    maxi1=0;
    maxi2=0;
    max1=0;
    max2=0;
    res=0;
    res1=0;
    g_ulADCCount=0;
    buffer_index=0;
    ulLastADCCount=0;

}
예제 #2
0
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC sample sequence 3
//! - Timer 1 subtimer A
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(void)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ulTSState = TS_STATE_INIT;

    //
    // Determine which calibration parameter set we will be using.
    //
    g_plParmSet = g_lTouchParameters[SET_NORMAL];
    if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
    {
        //
        // If the SRAM/Flash daughter board is present, select the appropriate
        // calibration parameters and reading threshold value.
        //
        g_plParmSet = g_lTouchParameters[SET_SRAM_FLASH];
        g_sTouchMin = 40;
    }
    else if(g_eDaughterType == DAUGHTER_FPGA)
    {
        //
        // If the FPGA daughter board is present, select the appropriate
        // calibration parameters and reading threshold value.
        //
        g_plParmSet = g_lTouchParameters[SET_FPGA];
        g_sTouchMin = 70;
    }

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(TS_P_PERIPH);
    ROM_SysCtlPeripheralEnable(TS_N_PERIPH);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
    ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4);
    ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                             ADC_CTL_CH_YP | ADC_CTL_END | ADC_CTL_IE);
    ROM_ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
    ROM_ADCIntEnable(ADC0_BASE, 3);
    ROM_IntEnable(INT_ADC0SS3);

    //
    // Configure the GPIOs used to drive the touch screen layers.
    //
    ROM_GPIOPinTypeGPIOOutput(TS_P_BASE, TS_XP_PIN | TS_YP_PIN);

    //
    // If no daughter board or one which does not rewire the touchscreen
    // interface is installed, set up GPIOs to drive the XN and YN signals.
    //
    if((g_eDaughterType != DAUGHTER_SRAM_FLASH) &&
       (g_eDaughterType != DAUGHTER_FPGA))
    {
        ROM_GPIOPinTypeGPIOOutput(TS_N_BASE, TS_XN_PIN | TS_YN_PIN);
    }

    ROM_GPIOPinWrite(TS_P_BASE, TS_XP_PIN | TS_YP_PIN, 0x00);

    if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
    {
        HWREGB(LCD_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN;
    }
    else if(g_eDaughterType == DAUGHTER_FPGA)
    {
        HWREGH(LCD_FPGA_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN;
    }
    else
    {
        ROM_GPIOPinWrite(TS_N_BASE, TS_XN_PIN | TS_YN_PIN, 0x00);
    }

    //
    // See if the ADC trigger timer has been configured, and configure it only
    // if it has not been configured yet.
    //
    if((HWREG(TIMER1_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0)
    {
        //
        // Configure the timer to trigger the sampling of the touch screen
        // every millisecond.
        //
        ROM_TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR |
                           TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC));
        ROM_TimerLoadSet(TIMER1_BASE, TIMER_A,
                         (ROM_SysCtlClockGet() / 1000) - 1);
        ROM_TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

        //
        // Enable the timer.  At this point, the touch screen state machine
        // will sample and run once per millisecond.
        //
        ROM_TimerEnable(TIMER1_BASE, TIMER_A);
    }
}
예제 #3
0
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC sample sequence 3
//! - Timer 1 subtimer A
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(void)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ulTSState = TS_STATE_INIT;

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(TS_P_PERIPH);
    ROM_SysCtlPeripheralEnable(TS_N_PERIPH);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
    ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4);
    ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                                 ADC_CTL_CH_YP | ADC_CTL_END | ADC_CTL_IE);
    ROM_ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
    ROM_ADCIntEnable(ADC0_BASE, 3);
    ROM_IntEnable(INT_ADC0SS3);

    //
    // Configure the GPIOs used to drive the touch screen layers.
    //
    ROM_GPIOPinTypeGPIOOutput(TS_P_BASE, TS_XP_PIN | TS_YP_PIN);
    ROM_GPIOPinTypeGPIOOutput(TS_N_BASE, TS_XN_PIN | TS_YN_PIN);
    ROM_GPIOPinWrite(TS_P_BASE, TS_XP_PIN | TS_YP_PIN, 0x00);
    ROM_GPIOPinWrite(TS_N_BASE, TS_XN_PIN | TS_YN_PIN, 0x00);

    //
    // See if the ADC trigger timer has been configured, and configure it only
    // if it has not been configured yet.
    //
    if((HWREG(TIMER1_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0)
    {
        //
        // Configure the timer to trigger the sampling of the touch screen
        // every millisecond.
        //
        ROM_TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR |
                           TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC));
        ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, (SysCtlClockGet() / 1000) - 1);
        ROM_TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

        //
        // Enable the timer.  At this point, the touch screen state machine
        // will sample and run once per millisecond.
        //
        ROM_TimerEnable(TIMER1_BASE, TIMER_A);
    }
}