//***************************************************************************** // //! \brief ADC callback interrupt //! //! \param None //! //! \return none // //***************************************************************************** unsigned long ADCCallback(void *pvCBData, unsigned long ulEvent, unsigned long ulMsgParam,void *pvMsgData) { unsigned long ulValueLength; unsigned long ulData[10]; // // Read the convert value // ulValueLength = xADCDataGet(xADC0_BASE, ulData); return 0; }
//***************************************************************************** // //! \brief Get ADC value. //! //! \param ulInputChannel The analog input channel (0~3). //! //! Get one channel ADC convert value. //! //! \return None // //***************************************************************************** unsigned long ADCValueGet(unsigned char ucInputChannel) { unsigned long ulADCBuffer[4]; // // Check valid of ucInputChannel // xASSERT(ucInputChannel <= SENSOR_SHIELD_AI3); // // Get ADC value // xADCDataGet(sADC_BASE, ulADCBuffer); // // Return specified channel value // return(ulADCBuffer[ucInputChannel]); }
//***************************************************************************** // //! \brief Get the current channel voltage which is connected to the XYAxis. //! //! \param None. //! //! \return The data of channel Current voltage. // //***************************************************************************** tLPR5150ALData LPR5150ALXYAxisCurVoltageGet() { tLPR5150ALData XYAxisCurVoltage = {0, 0}; unsigned long ulXYADCData[2] = {0, 0}; // // Read the XAxis, YAxis ADC data // xADCDataGet(LPR5150AL_ADC_BASE, ulXYADCData); ulXYADCData[0] = ulXYADCData[0] & 0x00000FFF; ulXYADCData[1] = ulXYADCData[1] & 0x00000FFF; // // Convert ADC data to voltage // XYAxisCurVoltage.fXAxisData = (float)(ulXYADCData[0] * LPR5150AL_ADC_RESVOL); XYAxisCurVoltage.fYAxisData = (float)(ulXYADCData[1] * LPR5150AL_ADC_RESVOL); return XYAxisCurVoltage; }
int main() { unsigned long i; unsigned char ucRet = 0; unsigned long ulValueLength; unsigned long ulData[10]; xPWMotorControl(); HD44780Init(); // // Enable Peripheral SPI0 // xSysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); xSPinTypeADC(ADC0, sA0); // // ADC Channel0 convert once, Software tirgger. // xADCConfigure(xADC0_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR); // // Enable the channel0 // xADCStepConfigure(xADC0_BASE, 0, xADC_CTL_CH0); // // Enable the ADC end of conversion interrupt // //xADCIntEnable(xADC0_BASE, xADC_INT_END_CONVERSION); // // install the call back interrupt // //xADCIntCallbackInit(xADC0_BASE, ADCCallback); // // Enable the NVIC ADC interrupt // //xIntEnable(xINT_ADC0); // // Enable the adc // xADCEnable(xADC0_BASE); // // start ADC convert // xADCProcessorTrigger( xADC0_BASE ); HD44780LocationSet(0, 0); HD44780DisplayString("Hello Nuvoton!"); HD44780LocationSet(0, 1); HD44780DisplayString("Hello CooCox! "); SysCtlDelay(10000000); while(1) { SysCtlDelay(1000000); // // Read the convert value // ulValueLength = xADCDataGet(xADC0_BASE, ulData); if (ulData[0] < 0x30100) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("right"); SendData74HC595(0x60); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); } else if(ulData[0] < 0x30300) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("up"); ulDuty++; xPWMDutySet(xPWMB_BASE, xPWM_CHANNEL7, ulDuty); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); SysCtlDelay(100000); } else if(ulData[0] < 0x30600) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("dowm"); ulDuty--; xPWMDutySet(xPWMB_BASE, xPWM_CHANNEL7, ulDuty); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); SysCtlDelay(100000); } else if(ulData[0] < 0x30900) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("left"); SendData74HC595(0x18); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); } else if(ulData[0] < 0x30E00) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("select"); SendData74HC595(0x60); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); } else { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("Nothing"); xPWMStop(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinTypeGPIOOutput(sD11); xGPIOSPinTypeGPIOOutput(sD3); xGPIOSPinWrite(sD11, 0); xGPIOSPinWrite(sD3, 0); } if(ulDuty >= 99) { ulDuty = 99; } if(ulDuty <= 1) { ulDuty = 1; } } // // SD Card Init // ucRet = SDInit(); // // write a block to the card // ucRet = SDBlockWrite(pucBuf, 0); // // Re-init the test buffer to 0 // for(i = 0; i < 512; i++) { pucBuf[i] = 0; } // // Read 1 block from the card // ucRet = SDBlockRead(pucBuf, 0); while(1); }
void ADCValueGet(unsigned long ulChannel, unsigned long* pulVal) { xADCDataGet(xADC0_BASE, pulVal); }