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.

CCS/TM4C123GH6PM: Analog Value related Problem

Part Number: TM4C123GH6PM


Tool/software: Code Composer Studio

Hello Sir,

I have use PE-3 pin for analog pin with 3.3 V input on this port. The analog value should be come 4095 according to 12 bit ADC. But that is not comming in attached file.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "driverlib/pin_map.h"
volatile long adcResult=0;
int a,b,c,d,e,f;

void GPIO_InIt(void)
{
    GPIO_PORTE_DIR_R &= ~0x10;              // Make PE1 input
    GPIO_PORTE_AFSEL_R |=0x10;              // Set PE as alternate fun.
    GPIO_PORTE_DEN_R &=~0x10;           // Disable Digital Enable on PE3
    GPIO_PORTE_AMSEL_R |=0x10;              // Enable Analog functionality on PE3

    ADC0_ACTSS_R &=~0x0008; // Disable sample Sequencer 3(SS3)
    ADC0_EMUX_R &=~0xF; // Software Trigger Conversion                 // Configure Trigger event : continuous mode
    ADC0_SSMUX3_R |=0; //  Get input from channel 0
    ADC0_SSCTL3_R |=0x0006; // Take one sample at a time set flat at 1st sample
    ADC0_ACTSS_R |=0x0008; //  Enable SS3
}

void ADC0Seq3_Handler(void)
{
    ADC0_PSSI_R|=0x0008; //  Start Conversion at SS3
    while((ADC0_RIS_R &  0x08)==0){} // Wait for conversion complete
    adcResult = ADC0_SSFIFO3_R & 0xFFF;
    ADC0_ISC_R = 0x0008;
}

int main(void)
{
    SYSCTL_RCGCGPIO_R |=0x10; // Enable clock for Port E
    SYSCTL_RCGCADC_R |=0x01; // Enable Clock for ADC Module 0

    GPIO_InIt();

    while(1)
    {
       ADC0Seq3_Handler();

    }
}

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "driverlib/pin_map.h"
volatile long adcResult=0;
int a,b,c,d,e,f;

void GPIO_InIt(void)
{
    GPIO_PORTE_DIR_R &= ~0x10;              // Make PE1 input
    GPIO_PORTE_AFSEL_R |=0x10;              // Set PE as alternate fun.
    GPIO_PORTE_DEN_R &=~0x10;           // Disable Digital Enable on PE3
    GPIO_PORTE_AMSEL_R |=0x10;              // Enable Analog functionality on PE3

    ADC0_ACTSS_R &=~0x0008; // Disable sample Sequencer 3(SS3)
    ADC0_EMUX_R &=~0xF; // Software Trigger Conversion                 // Configure Trigger event : continuous mode
    ADC0_SSMUX3_R |=0; //  Get input from channel 0
    ADC0_SSCTL3_R |=0x0006; // Take one sample at a time set flat at 1st sample
    ADC0_ACTSS_R |=0x0008; //  Enable SS3
}

void ADC0Seq3_Handler(void)
{
    ADC0_PSSI_R|=0x0008; //  Start Conversion at SS3
    while((ADC0_RIS_R &  0x08)==0){} // Wait for conversion complete
    adcResult = ADC0_SSFIFO3_R & 0xFFF;
    ADC0_ISC_R = 0x0008;
}

int main(void)
{
    SYSCTL_RCGCGPIO_R |=0x10; // Enable clock for Port E
    SYSCTL_RCGCADC_R |=0x01; // Enable Clock for ADC Module 0

    GPIO_InIt();

    while(1)
    {
       ADC0Seq3_Handler();

    }
}

  • Sir, Here i am enable PE4 port with 3.3 V input. But PE3 port showing same value as PE4. Please suggest me answer.

  • As mentioned in response to your other post, we strongly discourage the use of direct register writes and encourage the use of the TivaWare library functions. This will simplify your code, reduce the number of errors and allow others to assist you. Here is an example of reading two ADC values one after the other (1uS) using the TivaWare functions.

    #include <stdint.h>
    #include <stdbool.h>
    #include <inc/hw_memmap.h>
    #include "driverlib/gpio.h"
    #include "driverlib/adc.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    
    
    int main(void)
    {
        unsigned int array[4];
    
        //Set clock to 16 MHz
        SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        // Enable the GPIOE peripheral
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    
        // Enable the ADC0 module.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    
        // Wait for the GPIOE module to be ready.
    
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE))
        {
        }
        // Wait for the ADC0 module to be ready.
        //
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))
        {
        }
    
        //Configures ADC pins PE3 (AIN0) and PE2 (AIN1)
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2);
    
        //Configure ADC functions
        // Using Sequence 1 which has a 4 entry FIFO
        ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
        ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0 );
        ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
        ADCSequenceEnable(ADC0_BASE,1);
        ADCIntClear(ADC0_BASE, 1);
        ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1);
    
    
    
        while(1)
        {
            ADCProcessorTrigger(ADC0_BASE, 1);
            //wait for the conversion to be completed
            while(!ADCIntStatus(ADC0_BASE, 1, false))
            {
            }
            //clear Interrupt flag
            ADCIntClear(ADC0_BASE, 1);
    
            //Read ADC input and store PE3 in array[0], PE2 in array[1]
            ADCSequenceDataGet(ADC0_BASE, 1, array); //read the analog values
        }
    }
    

  • Thanks sir,

    I have again two more question regarding sample/ sec and UART. First, please tell me API regarding analog data in samples/second.  Second How to send this multiple anlog data on UART toghter.

  • The example above uses a software trigger and one ADC converter to take two different samples. The ADC clock is 16MHz and each conversion takes 16 clocks. If you were to do continuous conversions instead of software trigger that, each conversion takes 1uS. Your sample rate would be 500K samples/S for each of the two channels.  

    You are not likely to be able to send 1 million 12-bit conversions out a UART every second. What sample rate do you need? If not sure, what will you do with the data after it goes out the UART?

  • Sir,

        I want to acquire 4 muscle EMG data at 2048 sample/sec. So i want to know, How could i record these muscle data at these sample rate.

  • OK, if you want to send 4 12-bit values 2048 times every second, you need to transfer 2 bytes for each value (12 bits plus an identifier as to which sample it is). Each byte is 10 bits (start bit, 8 data bits and a stop bit). That means a baud rate of at least 163,840 bits/second. The next fastest standard baud rate is 230,400 baud. Of course the application receiving the data needs to know how to interpret these binary values.

    You can use a timer to trigger the ADC conversions every 488.275uS. (It is actually slightly faster than 2048 times/second.)