void SampleLightCO(void){ unsigned long ulADC0_Value[1]; SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); ADCIntClear(ADC0_BASE, 3); while(1){ ADCProcessorTrigger(ADC0_BASE, 3); while(!ADCIntStatus(ADC0_BASE, 3, false)){ } ADCIntClear(ADC0_BASE, 3); ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value); Log("Breath Level = "); LogD(ulADC0_Value[0]); Log("\r"); SysCtlDelay(SysCtlClockGet() / 12); } }
unsigned long ADC_In(unsigned int channelNum){ unsigned long config; unsigned long data; // Configuring ADC to start by processor call instead of interrupt ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); // Determine input channel switch(channelNum){ case 0: config = ADC_CTL_CH0; break; case 1: config = ADC_CTL_CH1; break; case 2: config = ADC_CTL_CH2; break; case 3: config = ADC_CTL_CH3; break; } // Enable ADC interrupt and last step of sequence config |= ADC_CTL_IE | ADC_CTL_END; ADCSequenceStepConfigure(ADC0_BASE, 3, 0, config); ADCSequenceEnable(ADC0_BASE, 3); ADCIntClear(ADC0_BASE, 3); // Start ADC conversion ADCProcessorTrigger(ADC0_BASE, 3); // Wait for ADC conversion to finish while(!ADCIntStatus(ADC0_BASE, 3, false)){} // Clear interrupt flag and read conversion data ADCIntClear(ADC0_BASE, 3); ADCSequenceDataGet(ADC0_BASE, 3, &data); return data; }
int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5); ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH8); ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH11 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 2); ADCIntClear(ADC0_BASE, 2); while(1) { ADCProcessorTrigger(ADC0_BASE, 2); while(!ADCIntStatus(ADC0_BASE, 2, false)); ADCIntClear(ADC0_BASE, 2); ADCSequenceDataGet(ADC0_BASE, 2, adcValue); SysCtlDelay(SysCtlClockGet() / 12); } }
//--------------------------------------------------------------------------- // hardware_init() // // inits GPIO pins for toggling the LED //--------------------------------------------------------------------------- void hardware_init(void) { //Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Removing Locks From Switch LOCK_F=0x4C4F434B; CR_F=GPIO_PIN_0|GPIO_PIN_4; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0); // Configuring PD0 as ADC input (channel 1) CH7 ADC0 GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceConfigure(ADC1_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH7); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH7); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH7); ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH7 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceStepConfigure(ADC1_BASE, 1, 0, ADC_CTL_CH6); ADCSequenceStepConfigure(ADC1_BASE, 1, 1, ADC_CTL_CH6); ADCSequenceStepConfigure(ADC1_BASE, 1, 2, ADC_CTL_CH6); ADCSequenceStepConfigure(ADC1_BASE, 1, 3, ADC_CTL_CH6 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); ADCSequenceEnable(ADC1_BASE, 1); ADCIntClear(ADC0_BASE, 1); ADCIntClear(ADC1_BASE, 1); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_6); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_3); GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); //GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,0x10); }
void CapacitorTask(void* pvParameter) { unsigned long ulValue=0; int i=0; cqueue = xQueueCreate(100,sizeof(unsigned long)); //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_OD); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x02);//Setting the Pin 0 to "high" //Initialize the ADC using functions from the Stellaris API //SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_IE|ADC_CTL_END|ADC_CTL_CH1); ADCSequenceEnable(ADC0_BASE, 1); //ADCIntEnable(ADC0_BASE, 1); ADCIntClear(ADC0_BASE, 1); //Trigger from the Processor while(true) { if(flagcap==1) { GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);//Setting the Pin 0 to "high" vTaskDelay(TICK_R*0.5); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x02);//Setting the Pin 0 to "high" i=0; flagcap = 0; //ADCIntClear(ADC0_BASE, 1); while(i<100) { ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, &ulValue);//Enable ADC sequence 0 ADCIntClear(ADC0_BASE, 1); xQueueSend(cqueue, &ulValue, 0); i++; vTaskDelay(TICK_R*1.0) ; } flagUART = 1; } vTaskDelay(TICK_R*10); } }
/** Reads the current sense amplifier output using the Analog to Digital Converter (ADC). Current sense resistor is 0.2 ohms, amplifier multiplies voltage drop by 50. Therefore, every mA of current translates into 10mV measured by the microcontroller @note Current sense input is on PE5 on Stellaris LaunchPad @pre Current sense shunt is installed on the BoosterPack @return Current in mA multiplied by 10 (e.g. return value of 713 = 71.3mA) @see StellarisWare/examples/peripherals/adc/single_ended.c */ uint16_t getCurrentSensor() { /* This array is used for storing the data read from the ADC FIFO. It must be as large as the FIFO for the sequencer in use. This example uses sequence 3 which has a FIFO depth of 1. */ uint32_t ulADC0_Value[1]; /* Enable sample sequence 3 with a processor signal trigger. Sequence 3 will do a single sample when the processor sends a signal to start the conversion. */ ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); /* Configure step 0 on sequence 3. Sample channel 8 (ADC_CTL_CH8) in single-ended mode * (default) and configure the interrupt flag (ADC_CTL_IE) to be set when the sample is done. * Tell the ADC logic that this is the last conversion on sequence 3 (ADC_CTL_END). */ ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END); // Since sample sequence 3 is now configured, it must be enabled. ADCSequenceEnable(ADC0_BASE, 3); // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before we sample. ADCIntClear(ADC0_BASE, 3); // // Now the setup is done, let's actually measure something! // // Trigger the ADC conversion. ADCProcessorTrigger(ADC0_BASE, 3); // Wait for conversion to be completed. while(!ADCIntStatus(ADC0_BASE, 3, false)) { } // Clear the ADC interrupt flag. ADCIntClear(ADC0_BASE, 3); // Read ADC Value into ulADC0_Value ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value); // This part does not have a separate voltage reference // Therefore we have to measure with reference to what we think VCC is, 3.30V #define REFERENCE_VOLTAGE_MV (3300l) uint32_t temp = (ulADC0_Value[0] * REFERENCE_VOLTAGE_MV); #define NUMBER_OF_STEPS_12_BIT_RESOLUTION (4096l) return ((uint16_t) (temp / NUMBER_OF_STEPS_12_BIT_RESOLUTION)); }
void joyTask(void *pvParameters) { //initialize queues for communication and user feedback dataBuffer = xQueueCreate(5, sizeof(unsigned long)); feedBack = xQueueCreate(5, sizeof(unsigned long)); //Enable ADC peripheral for joystick (left and right only) SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Set ADC to trigger from software, high priority ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); //configure adc to have an interrupt, to throw it at the end of the step sequence ADCSequenceStepConfigure(ADC0_BASE, 0, 0,(ADC_CTL_END|ADC_CTL_CH0|ADC_CTL_IE)); //Enable the configured sequence ADCSequenceEnable(ADC0_BASE, 0); //clear the interrupt ADCIntClear(ADC0_BASE, 0); //temporary variable to catch adc vals, since queue docs are full of lies unsigned long temp; while(true) { // Trigger the sample sequence. ADCProcessorTrigger(ADC0_BASE, 0); // Block until the sampling completes (fcn returns 0 until interrupt is thrown) while(!ADCIntStatus(ADC0_BASE, 0, false)){} // Read the value from the ADC into a temporary var ADCSequenceDataGet(ADC0_BASE, 0, &temp); //clear the interrupt ADCIntClear(ADC0_BASE, 0); //write temp value to queue xQueueSend(dataBuffer, (void*) &temp, 0); //send ADC value to the OLDE for display xQueueSend(feedBack, (void*) &temp, 0); //return control to Task scheduler vTaskDelay(100*ONE_MS); } }
//****************************************************************************** // The handler for the ADC conversion (height) complete interrupt. // Writes to the circular buffer. //***************************************************************************** void HeightIntHandler(void) { unsigned long ulValue; static int counter = 0; //Keeping track of the buffer count for the initialRead int current; int sum = 0; int i; // Clean up, clearing the interrupt ADCIntClear(ADC0_BASE, 3); // Get the single sample from ADC0. (Yes, I know, I just did what you did sir :p) ADCSequenceDataGet(ADC0_BASE, 3, &ulValue); // Place it in the circular buffer (advancing write index) g_inBuffer.data[g_inBuffer.windex] = (int) ulValue; g_inBuffer.windex++; if (g_inBuffer.windex >= g_inBuffer.size) g_inBuffer.windex = 0; if (counter < BUF_SIZE) { counter++; if (counter == BUF_SIZE) { for (i = 0; i < BUF_SIZE; i++) { current = ulValue; sum = sum + current; } //Average voltage to calibrate the minimum height of the helicopter initialRead = ADC_TO_MILLIS(sum/BUF_SIZE); } } }
void ADC0IntHandler() { unsigned long adc0Value; // Holds the ADC result char adc0String[5]; // Holds the string-converted ADC result // 清ADC0中断标志. // ADCIntClear (unsigned long ulBase, unsigned long ulSequenceNum) ADCIntClear(ADC0_BASE, 0); //从SSO读出转换结果 (FIFO0),本例中只有一个采样.如果要使用多个转换源,需要使用数组做为参数传递给API函数,保存FIFO转换结果. // long ADCSequenceDataGet (unsigned long ulBase,unsigned long ulSequenceNum,unsigned long *pulBuffer) ADCSequenceDataGet(ADC0_BASE, 0, &adc0Value); adc0Value= ((59960 - (adc0Value * 100)) / 356); // 在OLED上显示当前温度 usprintf(adc0String, "%d", adc0Value); IntMasterDisable(); RIT128x96x4StringDraw("Current temp : ", 6, 48, 15); RIT128x96x4StringDraw(adc0String, 94, 48, 15); IntMasterEnable(); // ADC模块空闲,可以进行下一次转换 adc_busy=0; }
void adc_init_and_run(void){ // Тактирование выбранного модуля АЦП. SysCtlPeripheralEnable(SYSCTL_PERIPH_ADCx); // Ожидание готовности выбранного модуля АЦП к настройке. while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADCx)) { } ADCHardwareOversampleConfigure(ADCx_BASE, 4); // Установка триггера выбранного буфера АЦП. ADCSequenceConfigure(ADCx_BASE, SSy, ADC_TRIGGER, 0); ADCSequenceStepConfigure(ADCx_BASE, SSy, 0, ADC_CTL_CH0); ADCSequenceStepConfigure( ADCx_BASE, SSy, 1, ADC_CTL_CH1|ADC_CTL_IE|ADC_CTL_END ); ADCIntClear(ADCx_BASE, SSy); IntEnable(INT_ADCxSSy); IntPrioritySet(INT_ADCxSSy, 1); ADCSequenceEnable(ADCx_BASE, SSy); ADCProcessorTrigger(ADCx_BASE, SSy); }
int main(void) { uint32_t ui32ADC0Value[4]; volatile uint32_t ui32TempAvg; volatile uint32_t ui32TempValueC; volatile uint32_t ui32TempValueF; setup(); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); while(1) { ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4; ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10; ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; } }
/***************************************************** * Function: checkIntTempSensor * Description: Reads internal temperature sensor * Input: NONE * Output: ui32TempAvg, ui32TempValueC, ui32TempValueF *****************************************************/ void checkIntTempSensor(void) { // Clear flag ADCIntClear(ADC0_BASE, 0); // Trigger processor ADCProcessorTrigger(ADC0_BASE, 0); // Wait for ADC status to be set while(!ADCIntStatus(ADC0_BASE, 0, false)){} // Get data and convert to useful values // Read all four steps of sequence into ui32ADC0Value ADCSequenceDataGet(ADC0_BASE, 0, ui32ADC0Value); ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4; ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10; ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; // Shutdown if device is getting too hot if(ui32TempValueF >= SHUTDOWN_TEMP) { mode = SYSTEM_SHUTDOWN; } }
void UARTIntHandler() { uint32_t ui32Status; uint32_t ui32ADC0Value[4]; // ADC FIFO volatile uint32_t ui32TempAvg; // Store average volatile uint32_t ui32TempValueC; // Temp in C volatile uint32_t ui32TempValueF; // Temp in F ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts ADCIntClear(ADC0_BASE, 2); // Clear ADC0 interrupt flag. ADCProcessorTrigger(ADC0_BASE, 2); // Trigger ADC conversion. while (!ADCIntStatus(ADC0_BASE, 2, false)) ; // wait for conversion to complete. ADCSequenceDataGet(ADC0_BASE, 2, ui32ADC0Value); // get converted data. // Average read values, and round. // Each Value in the array is the result of the mean of 64 samples. ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2) / 4; ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096) / 10; // calc temp in C ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; //while(UARTCharsAvail(UART0_BASE)) //loop while there are chars //{ // UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //echo character GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED //} }
/* * 初始化ADC引脚和配置 * 其中ADC0的输入引脚配置为CH1,ADC1的输入引脚配置为CH2 */ void Init_ADC() { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); ADCIntClear(ADC0_BASE, 3); ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC1_BASE, 3); ADCIntClear(ADC1_BASE, 3); }
// Control the major or minor cycle in main function void pirates(void* taskDataPtr) { pirateDataStruct* dataPtr = (pirateDataStruct*) taskDataPtr; unsigned short* pirateProximityPtr = dataPtr->pirateProximity; while (1) { // Start of ADC2 //removed to free up ADC lines // static unsigned long adc2Reading[4] = {0}; // interrupt flag is cleared before we sample. ADCIntClear(ADC0_BASE, 2); // Trigger the ADC conversion. ADCProcessorTrigger(ADC0_BASE, 2); // Wait for conversion to be completed. while(!ADCIntStatus(ADC0_BASE, 2, false)) { } // Clear the ADC interrupt flag. ADCIntClear(ADC0_BASE, 2); // Read ADC Value. ADCSequenceDataGet(ADC0_BASE, 2, adc2Reading); converted = (double) (1023 - adc2Reading[2]) * (200.0 / 1023) * 2; *pirateProximityPtr = (unsigned short) converted; //disable phasor and photon GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_5, 0x00); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0x00); if(*pirateProximityPtr>100) { //disable phasor and photon GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_5, 0x00); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0x00); //xTaskSuspend(piratesHandle); } else if(*pirateProximityPtr<30) { //fire phasors fault pin GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0xFF); } if(*pirateProximityPtr<5) { //fire photons PD5 GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_5, 0xFF); } vTaskDelay(100); } }
long getADCValues(int port) { unsigned long ADCValue[4] = {0,0,0,0}; ADCIntClear(ADC_BASE, port); ADCProcessorTrigger(ADC_BASE, port); while(!ADCIntStatus(ADC_BASE, port, false)); ADCSequenceDataGet(ADC_BASE, port, ADCValue); return ADCValue[0]; }
long sampleAdcPort(int port) { unsigned long ADCValues[4] = {0}; ADCProcessorTrigger(ADC_BASE, 0 ); while(!ADCIntStatus(ADC_BASE, 0, false)); ADCSequenceDataGet(ADC_BASE, 0, ADCValues); ADCIntClear(ADC_BASE, 0); return ADCValues[port]; }
void InitializeInterrupts() { //Enable and clear all configured interrupts before starting main loop IntEnable(INT_ADC3); IntEnable(INT_TIMER1A); IntMasterEnable(); ADCIntClear(ADC0_BASE, 3); }
//***************************************************************************** // //! \brief ADC0 Interrupt Handler. //! //! If users want to user the ADC0 Callback feature, Users should promise //! that the ADC0 Handle in the vector table is ADCIntHandler. //! //! \return None. // //***************************************************************************** unsigned long ADC0IntFucntion(void *pvCBData, unsigned long ulEvent, unsigned long ulMsgParam, void *pvMsgData) { ADCIntClear(ADC1_BASE, ADC_INT_END_CONVERSION); return 0; }
void mode1() //Obtain samples from ADC { ADCProcessorTrigger(ADC0_BASE, 2); // Start Sampling while(!ADCIntStatus(ADC0_BASE, 2, false)); // Wait until sampling is done ADCIntClear(ADC0_BASE, 2); //Clear Interrupt ADCSequenceDataGet(ADC0_BASE, 2, adcValue); //Obtain the sample ssdset(adcValue[0]); }
//triggers when it's got all the channels read void adc_interrupt(void) { unsigned long temp[4]; unsigned long i; ADCIntClear(ADC0_BASE, 1); ADCSequenceDataGet(ADC0_BASE, 1, temp); ADCIntClear(ADC0_BASE, 1); for ( i = 0; i < 4; i++ ) { temp[i] = temp[i] >> 5; // 7-bit number (128 steps) if ( temp[i] != adcValues[i] ) UARTprintf("ADC[%d]: %d\n", i, temp[i] ); adcValues[i] = (unsigned char)temp[i]; } }
void ADC0_Handler(void){ // Clear flag ADCIntClear(ADC0_BASE, 0); ADCSequenceDataGet(ADC0_BASE, 0, Buffer); Status = TRUE; }
void get_temp(void){ ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4; ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10; }
void adc_read() { ADCProcessorTrigger(ADC0_BASE, 0); while(!ADCIntStatus(ADC0_BASE, 0, false)); ADCIntClear(ADC0_BASE, 0); ADCSequenceDataGet(ADC0_BASE, 0, ulADC0_Value); ADCSequenceEnable(ADC0_BASE, 0); }
void ADCIntHandler(void) { while(!ADCIntStatus(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM, false)); ADCIntClear(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM); xSemaphoreTakeFromISR(adc_mutex, pdFALSE); ADCSequenceDataGet(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM, adc_vals); xSemaphoreGiveFromISR(adc_mutex, pdTRUE); ADCProcessorTrigger(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM); }
/* * This function is the implementation of the ADC0 interrupt handler. */ interrupt void ADC0IntHandler(void) { //Clear the ADC interrupt flags ADCIntClear(ADC0_BASE, 3); //Get data from ADC0 sequence 3 ADCSequenceDataGet(ADC0_BASE, 3, ulCurrent); UARTprintf("Current: %u ", ulCurrent[0]); }
/* * This function is the implementation of the ADC1 interrupt handler. */ interrupt void ADC1IntHandler(void) { //Clear the ADC interrupt flags ADCIntClear(ADC1_BASE, 3); //Get data from ADC0 sequence 3 ADCSequenceDataGet(ADC1_BASE, 3, ulLVDT); UARTprintf("LVDT: %u\n", ulLVDT[0]); }
// ******************************************************* // Initializes the ADC pins and their ISRs. void heightInit(void) { // using code from WEEK-2_ADC, my_adc.c written by Dr. Steve Weddell //SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | // SYSCTL_XTAL_8MHZ); // // The ADC0 peripheral must be enabled for use. SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // // For this example ADC0 is used with AIN0 on port B1. This // was given by the LM3S1968 data sheet. // Therefore, GPIO port B needs to be enabled // so these pins can be used. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Select the analog ADC function for these pins. // The LM3S1968 data sheet was consulted to see which functions are // allocated per pin. GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_1); // Enable sample sequence 3 with a processor signal trigger. Sequence 3 // will do a single sample when the processor sends a signal to start the // conversion. Each ADC module has 4 programmable sequences, sequence 0 // to sequence 3. This example is arbitrarily using sequence 3. ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); // // Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in // single-ended mode (default) and configure the interrupt flag // (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic // that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence // 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and // sequence 0 has 8 programmable steps. Since we are only doing a single // conversion using sequence 3 we will only configure step 0. For more // information on the ADC sequences and steps, reference the datasheet. ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); // // Since sample sequence 3 is now configured, it must be enabled. ADCSequenceEnable(ADC0_BASE, 3); // // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before we sample. ADCIntClear(ADC0_BASE, 3); initCircBuf (&g_heightBuf, CIRCBUF_SIZE); }
void RMBD01Init( void ) { // // Configure the ADC for Pitch and Roll // sequence 3 means a single sample // sequence 1, 2 means up to 4 samples // sequence 0 means up to 8 samples // we use sequence 1 // if (SysCtlPeripheralPresent(SYSCTL_PERIPH_ADC0)) { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_TIMER, 0); // 1 captures up to 4 samples // // Select the external reference for greatest accuracy. // ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ENCODER_CHANNEL_PITCH); // sample pitch ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ENCODER_CHANNEL_ROLL | ADC_CTL_IE | ADC_CTL_END); // sample roll ADCIntRegister(ADC0_BASE,1,ADCIntHandler); ADCSequenceEnable(ADC0_BASE, 1); ADCIntEnable(ADC0_BASE, 1); // // Setup timer for ADC_TRIGGER_TIMER // SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // // Configure the second timer to generate triggers to the ADC // TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER); TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet() / 1000); // 2 ms TimerControlStall(TIMER1_BASE, TIMER_A, true); TimerControlTrigger(TIMER1_BASE, TIMER_A, true); // // Enable the timers. // TimerEnable(TIMER1_BASE, TIMER_A); new_adc = false; // } // // Clear outstanding ADC interrupt and enable // ADCIntClear(ADC0_BASE, 1); IntEnable(INT_ADC0); } // InitADC
int main(void) { settemp = 25; uint32_t ui32ADC0Value[4]; SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); IntMasterEnable(); IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); while(1){ ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4; ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10; ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; char m[] = "Current Temperature is *C, Set Temperature is *C"; m[23]=(ui32TempValueC/10 % 10) + '0'; m[24]=(ui32TempValueC%10) + '0'; m[49]=(settemp/10 % 10) + '0'; m[50]=(settemp%10) + '0'; int i; for(i=0;m[i];i++){ UARTCharPut(UART0_BASE, m[i]); } if(ui32TempValueC < settemp){ GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,8); } else{ GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,2); } UARTCharPut(UART0_BASE, '\r'); UARTCharPut(UART0_BASE, '\n'); SysCtlDelay(1000000); } }