// ******************************************************* // 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); } }
//***************************************************************************** // //! \brief adc api interrupt state and data get test. //! //! \return None. // //***************************************************************************** static void adcIntTest(void) { // // Set the length of converter // // ADCConverLenSet(ADC1_BASE, 1, 1); // // Test ADC configure API // // ADCSequenceIndexSet(ADC1_BASE, ulAdcSeqNo, ulAdcSeqNo); // ADCSampLenSet(ADC1_BASE, 14, ADC_SAMPTIME_7_5_CYCLE); // // A/D interrupt enable // ADCIntEnable(ADC_BASE, ADC_INT_END_CONVERSION); xIntEnable(INT_ADC); xADCIntCallbackInit(ADC_BASE, ADC0IntFucntion); // // A/D configure // ADCConfigure(ADC_BASE, ADC_INPUT_SINGLE, ADC_OP_CONTINUOUS, ADC_TRIGGER_PROCESSOR); ADCProcessorTrigger(ADC_BASE); TestAssertQBreak("T", "xadc interrupt function error!", 0xFFFFFFFF); }
/***************************************************** * 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; } }
unsigned int ReadWall_IR () { uint32_t resultRight, resultFront; int i; ADCProcessorTrigger(ADC0_BASE, 2); //Wait for ADC to finish converting. for ( i = 10000; i>0; i--); //delay a bit ADCSequenceDataGet(ADC0_BASE, 2, &resultRight); ADCSequenceDataGet(ADC0_BASE, 2, &resultFront); //Check if the front wall is close. if (resultFront > MAX_VAL_F){ front_wall_det = 1; } else { front_wall_det = 0; } //Check if the right wall is close. if (resultRight < MIN_VAL_R){ wall_det = 0; } else { wall_det = 1; } return resultRight; }
/** * 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 } }
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; }
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; }
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); }
long readRightIRSensor (void) { unsigned long ADCValue = 0; ADCProcessorTrigger(ADC_BASE, 2 ); while(!ADCIntStatus(ADC_BASE, 2, false)); ADCSequenceDataGet(ADC_BASE, 2, &ADCValue); return ADCValue; }
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 //} }
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 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 SysTickIntHandler(void) { // Initiate a conversion ADCProcessorTrigger(ADC0_BASE, 3); //Polls display on UART0 and Counter For interrupts g_ulSampCnt++; }
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]); }
void Init_ADC() { 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); }
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; }
//***************************************************************************** // //! Ininite the ADC //! //! \param None //! //! This function ininite the ADC including clock source and enable ADC //! //! \return none // //***************************************************************************** void ADConvert(void) { unsigned long ulAdcSeqNo[] = {0}; xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); xSysCtlDelay(10000); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA); // // configure GPIO pin as ADC function // xSPinTypeADC(ADC0, PA0); // // Reset ADC // xSysCtlPeripheralReset(xSYSCTL_PERIPH_ADC1); // // Set ADC clock source // xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_MAIN, 4); // // Enable ADC clock // xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC1); // // Set the length of converter // ADCConverLenSet(ADC1_BASE, 1, 1); // // Set the Index of converter Sequence // ADCSequenceIndexSet(ADC1_BASE, ulAdcSeqNo, ulAdcSeqNo); ADCSampLenSet(ADC1_BASE, 0, 128); // // A/D interrupt enable // ADCIntEnable(ADC1_BASE, ADC_INT_END_CONVERSION); xIntEnable(xINT_ADC0); xADCIntCallbackInit(ADC1_BASE, ADC0IntFucntion); // // Software trigger enable // ADCProcessorTrigger(ADC1_BASE); // // A/D configure // ADCRegularConfigure(ADC1_BASE, ADC_OP_SINGLE, ADC_TRIGGER_PROCESSOR); ADCDataRegularGet(ADC1_BASE, ADC_MODE_NORMAL); }
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); }
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 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; }
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); } }
extern "C" void ADC0IntHandler(void) // NOT started yet !!!! { uint32_t ui32ADC0Value[4]; //used for storing data from ADC FIFO, must be as large as the FIFO for sequencer in use. Sequencer 1 has FIFO depth of 4 //variables that cannot be optimized out by compiler ADCIntClear(ADC0_BASE, 1); //clear interrupt flag ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2) / 4; //calculate average ADCProcessorTrigger(ADC0_BASE, 1); }
float Board::getTemp() { float ulTemp_ValueC; unsigned long gt; ADCProcessorTrigger(ADC0_BASE, 3); ADCSequenceDataGet(ADC0_BASE, 3, >); // Berechnung ulTemp_ValueC = ((1475 * 1023) - (2250 * gt)) / 10230; return ulTemp_ValueC/10000; }
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); } }