Hello,
I have a code to read a single pin of the ADC0 peripheral and display it through UART. (I use putty) The program works fine. (Code attached below)
But now I have connected a 128 x 64 GLCD to the TIVA. Now, the ADC value is full (i.e. 4095 for the 12 bit ADC) even when my pin is disconnected (or shorted to ground). What is the problem?
I tried changing the ADC pins, but to no avail!
The Main Program :
#include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "driverlib/adc.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "inc/hw_gpio.h" #include "inc/hw_ints.h" #include "driverlib/sysctl.h" #include "driverlib/pin_map.h" #include "driverlib/rom_map.h" #include "KS0108.h" #include "KS0108.c" #include "KS0108-Stellaris.c" #include "skull.h" #include "driverlib/adc.h" #include "inc/hw_adc.h" #include "inc/hw_uart.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" void InitConsole(void) { // // Enable GPIO port A which is used for UART0 pins. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for UART0 functions on port A0 and A1. // This step is not necessary if your part does not support pin muxing. GPIOPinConfigure(0x00000001); GPIOPinConfigure(0x00000401); // // Enable UART0 so that we can configure the clock. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Use the internal 16MHz oscillator as the UART clock source. // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Select the alternate (UART) function for these pins. // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, 16000000); } int main(void) { uint32_t pui32ADC0Value[1]; unsigned int i,j; InitConsole(); SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //20 MHz clock // // Display the setup on the console. // UARTprintf("ADC ->\n"); UARTprintf(" Type: Single Ended\n"); UARTprintf(" Samples: One\n"); UARTprintf(" Update Rate: 250ms\n"); UARTprintf(" Input Pin: AIN0/PE3\n\n"); // // The ADC0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // // For this example ADC0 is used with AIN0 on port E7. // The actual port and pins used may be different on your part, consult // the data sheet for more information. GPIO port E needs to be enabled // so these pins can be used. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Select the analog ADC function for these pins. // Consult the data sheet to see which functions are allocated per pin. GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5); // // 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); // // Sample AIN0 forever. Display the value on the console. GLCD_Initalize(); GLCD_ClearScreen(); for(i=0;i<128;i++) {GLCD_SetPixel(i,32,0);} for(i=0;i<64;i++) GLCD_SetPixel(0,i,0); i=0; while(1) { // // 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. // ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value); UARTprintf("%4d", pui32ADC0Value[0]); UARTprintf("\n"); GLCD_SetPixel(i,pui32ADC0Value[0]/128,0); SysCtlDelay(SysCtlClockGet() / 12); } return 0; }