This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C123GXL: Tiva C series tm4c123g launchpad issues with adc not giving correct values for input sine wave from signal generator. Code attached

Part Number: EK-TM4C123GXL
Other Parts Discussed in Thread: TM4C123GH6PM

#include <stdint.h>
#include <stdio.h>
#include "E:\TivaWare\inc\tm4c123gh6pm.h"
#include "tm4c123gh6pm.h"
#include <string.h>
#include <stdlib.h>


void UART0Tx(char c);
void UART0_init(void);
void UART0_puts(char* s);
void delayMs(int n);

int main(void)
{
char buffer[16];
float res;

UART0_init();
/* enable clocks */
SYSCTL_RCGCGPIO_R|=0x10;
SYSCTL_RCGCADC_R |= 1; /* enable clock to ADC0 */

// SYSCTL_RCGCWTIMER_R |=1; //enable clock to wtimer
GPIO_PORTE_AFSEL_R |=8;
GPIO_PORTE_DEN_R &=~8;
GPIO_PORTE_AMSEL_R |=8;

/* initialize ADC0 */
ADC0_ACTSS_R &= ~8; /* disable SS3 during configuration */
ADC0_EMUX_R &= ~0xF000;
// ADC0_EMUX_R|=0x5000; //for timer trigger

ADC0_SSMUX3_R = 0; /* get input from channel 0 */
ADC0_SSCTL3_R |= 6; /* take chip temperature, set flag at 1st sample */

ADC0_ACTSS_R |= 8; /* enable ADC0 sequencer 3 */

// WTIMER0_CTL_R=0;
//WTIMER0_CFG_R=0x04;
//WTIMER0_TAMR_R=0x02; //periodic mode and down-counter
//WTIMER0_TAILR_R=1600;
//WTIMER0_CTL_R|=0x20;
//WTIMER0_CTL_R|=0x01;

while(1)
{
ADC0_PSSI_R |= 8; /* start a conversion sequence 3 */
while((ADC0_RIS_R & 8) == 0) ; /* wait for conversion complete */
res = ADC0_SSFIFO3_R;

ADC0_ISC_R = 8; /* clear completion flag */

res=(res*3.3)/4095;

sprintf(buffer, "%f\r\n", res);
UART0_puts(buffer);
delayMs(1000);

}

}

void UART0_init(void)
{
SYSCTL_RCGCUART_R |= 1; /* provide clock to UART0 */
SYSCTL_RCGCGPIO_R |= 0x01; /* enable clock to GPIOA */



/* UART0 initialization */
UART0_CTL_R = 0; /* disable UART0 */
UART0_IBRD_R = 8;//104; /* 16MHz/16=1MHz, 1MHz/104=9600 baud rate */
UART0_FBRD_R = 44;//11; /* fraction part, see Example 4-4 */
UART0_CC_R = 0; /* use system clock */
UART0_LCRH_R = 0x60; /* 8-bit, no parity, 1-stop bit, no FIFO */
UART0_CTL_R = 0x301; /* enable UART0, TXE, RXE */

/* UART0 TX0 and RX0 use PA0 and PA1. Set them up. */
GPIO_PORTA_DEN_R = 0x03; /* Make PA0 and PA1 as digital */
GPIO_PORTA_AFSEL_R = 0x03; /* Use PA0,PA1 alternate function */
GPIO_PORTA_PCTL_R = 0x11; /* configure PA0 and PA1 for UART */
}

void UART0Tx(char c)
{
while((UART0_FR_R & 0x20) != 0); /* wait until Tx buffer not full */
UART0_DR_R = c; /* before giving it another byte */
}

void UART0_puts(char* s)
{
while (*s != 0) /* if not end of string */
UART0Tx(*s++); /* send the character through UART0 */

}

/* delay n milliseconds (16 MHz CPU clock) */
void delayMs(int n)
{
int32_t i, j;
for(i = 0 ; i < n; i++)
for(j = 0; j < 3180; j++)
{} /* do nothing for 1 ms */
}

  • Hello Sidra,

    Per our Forum Guidelines, we do not support code for direct register programming on E2E, see guideline #4: https://e2e.ti.com/support/microcontrollers/other/f/908/t/695568

    We would strongly recommend using TivaWare, starting with the single_ended example under [Install Path]\TivaWare_C_Series-2.1.4.178\examples\peripherals\adc

    If you really need to use DRM programming, please refer to that example still and then go into the TivaWare API's to see all the calls made required to setup the ADC for operation.

    Should you decide to use TivaWare and hit an issues, feel free to reply to this post with your TivaWare code and I will help get you going.