long getADCValue(void) { unsigned long ADCValue = 0; ADCProcessorTrigger(ADC_BASE, 0 ); while(!ADCIntStatus(ADC_BASE, 0, false)); ADCSequenceDataGet(ADC_BASE, 0, &ADCValue); return ADCValue; }
long readRightIRSensor (void) { unsigned long ADCValue = 0; ADCProcessorTrigger(ADC_BASE, 2 ); while(!ADCIntStatus(ADC_BASE, 2, false)); ADCSequenceDataGet(ADC_BASE, 2, &ADCValue); return ADCValue; }
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); } }
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; } }
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; }
/***************************************************** * 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; } }
int setADC (void) { unsigned long ulValue; //char buffer[32] = ""; // // Trigger the sample sequence. // ADCProcessorTrigger(ADC0_BASE, 0); // // Wait until the sample sequence has completed. // while(!ADCIntStatus(ADC0_BASE, 0, false)) { } // // Read the value from the ADC. // ADCSequenceDataGet(ADC0_BASE, 0, &ulValue); /*debug show value RIT128x96x4StringDraw(" ", 90, 88, mainFULL_SCALE); itoa(ulValue, buffer, 10 ); RIT128x96x4StringDraw(buffer, 90, 88, mainFULL_SCALE); */ return ulValue; }
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 //} }
// ******************************************************* // Takes an ADC sample. This is the location of // the helicopter on the vertical axis. void heightSample(void) { //* we could just read ADC every time we call this //* not much need to use systick as with yaw?? //* could combine yaw and height ISRs in one. unsigned long ulValue[10]; //long ulCount = 0; // // Trigger the ADC conversion. ADCProcessorTrigger(ADC0_BASE, 3); // // Wait for conversion to be completed. while(!ADCIntStatus(ADC0_BASE, 3, false)) { } // Read ADC Value. //ulCount = ADCSequenceDataGet(ADC0_BASE, 3, ulValue); //Strange thing is happening, ADCSequecnceDataGet() // Regularly returns a value on the order of 10^9 // when the return value is 0 (false). if (ADCSequenceDataGet(ADC0_BASE, 3, ulValue) == 1) { g_height = ulValue[0]; writeCircBuf(&g_heightBuf, g_height); } // I'm not going to bother taking a new reading because // one sample is not significant since it is averaged. }
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); } }
/** * Do a processor A/D conversion sequence. */ static void scan_proc_adc(void) { int samples; /* * We occasionally get too many or too few samples because * the extra (missing) samples will show up on the next read * operation. Just do it again if this happens. */ for (samples = 0; samples != ADC_SAMPLES; ) { ADCSequenceEnable(ADC0_BASE, 0); ADCProcessorTrigger(ADC0_BASE, 0); /* * Wait until the sample sequence has completed. */ while(!ADCIntStatus(ADC0_BASE, 0, false)) ; /* * Read the values from the ADC. The whole sequence * gets converted and stored in one fell swoop. */ if (xSemaphoreTake(io_mutex, IO_TIMEOUT)) { samples = ADCSequenceDataGet(ADC0_BASE, 0, (unsigned long *)adc_val); xSemaphoreGive(io_mutex); } #if (DEBUG > 0) if (samples != ADC_SAMPLES) { lprintf("A/D samples: is %d, " "should be %d.\r\n", samples, ADC_SAMPLES); } #endif } }
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]; }
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]; }
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]); }
rt_uint32_t read_battert_adc_value() { uint32_t battertValue; ADCProcessorTrigger(ADC0_BASE, 3); while(!ADCIntStatus(ADC0_BASE, 3, false)); ADCSequenceDataGet(ADC0_BASE, 3, &battertValue); return battertValue; }
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); }
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); } }
// ADC采样序列0的中断函数 void ADC_Sequence_0_ISR(void) { unsigned long ulStatus; ulStatus = ADCIntStatus(ADC_BASE, 0, true); // 读取中断状态 ADCIntClear(ADC_BASE, 0); // 清除中断状态,重要,等待下次AD中断 semGive(the_lock); // if (ulStatus != 0) // 如果中断状态有效 // { // ADC_EndFlag = 1; // 置位ADC采样结束标志 // } }
//============================================================================// //== ADC中断函数 ==// //============================================================================// //==入口参数: 无 ==// //==出口参数: 无 ==// //==返回值: 无 ==// //============================================================================// void ADC_ISR(void) { unsigned long ulStatus; ulStatus = ADCIntStatus(ADC_BASE, 0, true); ADCIntClear(ADC_BASE, 0); if (ulStatus) { ADC_EndFlag = true; } }
void Handler2() { TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ADCProcessorTrigger(ADC_BASE, 0); while (!ADCIntStatus(ADC_BASE, 0, false)); ADCSequenceDataGet(ADC_BASE, 0, &ADC_resultValue); pwm = ((double) 400 / 1024) * ADC_resultValue; usnprintf(buffer, BUFFSIZE, "ADC : %d\n", (int)ADC_resultValue); UARTPrint0((unsigned char *) buffer); }
int main(void) { uint32_t ui32ADC0Value[4]; uint32_t ui32Period; SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //Configure ADC to read temperature values SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ADCHardwareOversampleConfigure(ADC0_BASE, 64); //ESpecify the sampler and configure its various stages 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); //Enable peripheral of UART SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ///Configure pins for UART GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); //Set period of timer interrupts ui32Period = (SysCtlClockGet() / 1) / 2; TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1); IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_A); while(1) { ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } //Update the value of temperature based on readings of ADC 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; } }
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); } }
void Init_ADC() { /**** ADC0 ***/ SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0); ADCSequenceEnable(ADC_BASE, 0); ADCProcessorTrigger(ADC_BASE, 0); //값읽기 ADCProcessorTrigger(ADC_BASE, 0); while (!ADCIntStatus(ADC_BASE, 0, false)) ; ADCSequenceDataGet(ADC_BASE, 0, &ADC_resultValue0); /**** ADC1 ***/ ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH1); ADCSequenceEnable(ADC_BASE, 1); ADCProcessorTrigger(ADC_BASE, 1); //값 읽기 ADCProcessorTrigger(ADC_BASE, 1); while (!ADCIntStatus(ADC_BASE, 1, false)) ; ADCSequenceDataGet(ADC_BASE, 1, &ADC_resultValue1); /**** ADC2 ***/ ADCSequenceConfigure(ADC_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC_BASE, 2, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH2); ADCSequenceEnable(ADC_BASE, 2); ADCProcessorTrigger(ADC_BASE, 2); //값 읽기 ADCProcessorTrigger(ADC_BASE, 2); while (!ADCIntStatus(ADC_BASE, 2, false)) ; ADCSequenceDataGet(ADC_BASE, 2, &ADC_resultValue2); }
uint32_t tempSensRead() { ADCProcessorTrigger(TEMP_SENS_ADC_BASE, TEMP_SENS_SEQ_NUM) ; while(!ADCIntStatus(TEMP_SENS_ADC_BASE, TEMP_SENS_SEQ_NUM, false)){ } ADCIntClear(TEMP_SENS_ADC_BASE, TEMP_SENS_SEQ_NUM) ; ADCSequenceDataGet(TEMP_SENS_ADC_BASE, TEMP_SENS_SEQ_NUM, tempSensor.ADCValues) ; // TEMP = 147.5 - ((75 * (VREFP - VREFN) × ADCCODE) / 4096) return (uint32_t)(147.5 - ((75.0 * 3.3 * (float)(tempSensor.ADCValues[0])) / 4096.0)) ; }
/** 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)); }
//--------------------------------------------------------------------------- // main() //--------------------------------------------------------------------------- void main(void) { char num [32] = {0}; uint32_t ADC_Raw_X[4],ADC_Raw_Y[4]; hardware_init(); // init hardware via Xware inituart(); delay(); delay(); while(1) // forever loop { ltoa(X,num); //UARTprintf(" The value of coordinate X = "); UARTprintf(num); UARTprintf("."); ltoa(Y,num); //UARTprintf(" The value of coordinate Y = "); UARTprintf(num); UARTprintf("\n"); ADCProcessorTrigger(ADC0_BASE, 1); ADCProcessorTrigger(ADC1_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false) && !ADCIntStatus(ADC1_BASE, 1, false)); { } ADCIntClear(ADC0_BASE, 1); ADCIntClear(ADC1_BASE, 1); ADCSequenceDataGet(ADC0_BASE, 1, ADC_Raw_Y); ADCSequenceDataGet(ADC1_BASE, 1, ADC_Raw_X); X = (ADC_Raw_X[0] + ADC_Raw_X[1] + ADC_Raw_X[2] + ADC_Raw_X[3])/4; Y = (ADC_Raw_Y[0] + ADC_Raw_Y[1] + ADC_Raw_Y[2] + ADC_Raw_Y[3])/4; SysCtlDelay(670000*3); } }
int main(void) { uint32_t ui32ADC0Value[4]; setup(); adc_init(); glcd_init(); glcd_cleardisplay(); while(1){ //clear interrupt flag glcd_cleardisplay(); ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); glcd_cleardisplay(); ui32JoyLR = (ui32ADC0Value[2] + ui32ADC0Value[3] + 1)/2; //ui32JoyLR = ui32JoyLR*100; display_image(one); glcd_cleardisplay(); SysCtlDelay(ui32JoyLR); display_image(two); glcd_cleardisplay(); SysCtlDelay(ui32JoyLR); display_image(three); SysCtlDelay(ui32JoyLR); glcd_cleardisplay(); display_image(four); SysCtlDelay(ui32JoyLR); glcd_cleardisplay(); display_image(five); SysCtlDelay(ui32JoyLR); glcd_cleardisplay(); display_image(six); SysCtlDelay(ui32JoyLR); glcd_cleardisplay(); display_image(seven); SysCtlDelay(ui32JoyLR); glcd_cleardisplay(); display_image(eight); SysCtlDelay(ui32JoyLR); glcd_cleardisplay(); } return 0; }
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); } }