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.

TM4C123GH6PM : ADC issue

Other Parts Discussed in Thread: TM4C123GH6PM

I am using TM4C123GH6PM lauchpad.

IAR developement software.

I wanted to use two sensor on A0 & A1 pins.

Read the values sequencially, do the processing.

Here is my code.

Please correct:

......................................................................................................................................................................................................................................

#include <lm4f120h5qr.h>
#include <stdlib.h>
#include <stdio.h>
//#include <intrins.h>
#include <math.h>
#include <string.h>
/* ...........................................
DATA PA4 13
SCK PA2 11
SS PA3 12
............................................*/
unsigned long ADC_RESULT=0;
float ADC_RESULT1=0;
void adc_init();
unsigned long ADC();
void send_dac();
void serial_clk();

unsigned long ADC()
{
unsigned long result;
ADC0->PSSI = 0X0004; //Begin sampling on Sample Sequencer 2
while((ADC0->RIS &0X04)==0);
result = ADC0->SSFIFO2 &0XFFF;
ADC0->ISC = 0X0004;
return result;
}


int main(void)
{
                                                                                         //...13.4.1 Module Initialization pg. 817
SYSCTL->RCGCADC =0X00000001;                     //1. ADC 0 module selected
                                                                                         //General purpose I/O Run Mode Clock RRCGCGPIO pg. 340
SYSCTL->RCGCGPIO=0X00000011;                     //2. Port A & Port E are selected

//DAC Pin settings
                                                                                        // GPIO direction GPIODIR pg. 663
GPIOA->DIR =0X1C;                                                  // PA2, PA3, PA4 as output pin
                                                                                       // GPIO Digital Enable (GPIODEN) pg.682
GPIOA->DEN =0X1C;                                               // PA2, PA3, PA4 are Digital Enabled
                                                                                      // GPIO Data (GPIODATA) pg. 662
GPIOA->DATA =0X08;                                              // Initial pin data

//ADC port pin initialization

GPIOE->AFSEL = (1<<2)|(1<<3);                         //3. Set the GPIOAFSELbits for the ADC input pins
GPIOE->DEN &= ~0X0C;                                       //4. Configure theAINx signals to be analog inputs by clearing the correspondingDENbit in the GPIO Digital Enable (GPIODEN)
GPIOE->AMSEL = (1<<2)|(1<<3);                        //5. Disable the analog isolation circuit for all ADC input pins that are to be used by writing a 1 to the appropriate bits of the GPIOAMSELregister
GPIOE->DIR &= ~0X0C;

//13.4.2 Sample Sequencer Configuration
ADC0->ACTSS &= ~0X0004;                               //1. Ensure that the sample sequencer is disabled by clearing the correspondingASENnbit in the ADCACTSSregister
                                                                                    // ADC SS2 Enable- 4 sample
ADC0->EMUX = 0XF000;                                     //2. Configure the trigger event for the sample sequencer in theADCEMUX register
// set as Continuously sample
ADC0->SSMUX3 = 1;                                            //4. For each sample in the sample sequence, configure the corresponding input source in the ADCSSMUXnregister
ADC0->SSMUX2 = 0;                                            // SSMUX3 -> AIN1 & SSMUX2 -> AIN0
ADC0->SSCTL2 = 0X60;                                      //5. For each sample in the sample sequence, configure the sample control bits in the corresponding nibble in theADCSSCTLn register
                                                                                   // 2nd sample is last sample and Interrupt enabled after that (This for SS2)
ADC0->IM = (1<<2);                                              //6. interrupts are to be used, set the corresponding MASKbit in the ADCIM
                                                                                  // ADCSSCTL2 IEn bit is set
ADC0->ACTSS |= 0X0004;                                 //7. Enable the sample sequencer logic by setting the correspondingASENnbit in the ADCACTSS register
ADC0->SSPRI = 0X1023;


while(1)
{
ADC_RESULT = ADC();
ADC_RESULT1 = (ADC_RESULT/4095)*3.3;
ADC_RESULT = ADC_RESULT | 0x3000;

}
}.....................................................................................................................................................................................................................................

I dont understand ADC_RESULT will have which value, from AIN0 or AIN1.

and how to get both value from AIN0 or AIN1.

  • Hello Krishnat

    Can you please move away from DRM style register access and instead use TivaWare. The code is highly unreadable for someone else other than you.
  • which development software should I use??

    I have done this coding in IAR development software.

    In main function I have initialize and configure ADC as steps given in datasheet.

    And in while loop I am waiting for ADC conversion complete interrupt.


    To scan single analog pin code works fine.
    how to scan two analog pins simultaneously or 1-by-1?

    My one more query is- I want get two integer data values from NI-cRIO which I will process in TIVA.
    How to communicate between TIVA and NI-cRIO .

  • Hello Krishnat

    Please use TivaWare that can be downloaded from TI's website. Once you construct the software for single pin we can help in multi-pin sampling. Also please do a search on the forum. There are some examples on the forum in the last 2 months on multiple pin sampling.

    I have not used a NI-cRIO so I would not be the correct expert for the same.
  • Hello Amit,

    I manage to do code for scan 1 analog pin (using SS3) and scan 4 analog pins (using SS2) .

    Now I want to do this using Interrupt.

    ie When any GPIO pin(eg. PF1) voltage level changes, ADC loop should start scanning analog pins (eg. PE2 for SS3 or PE1, PE2, PE3 & PE4 for SS2)

  • Krishnat,
    You did not state if you managed to read 1 pin WITH TIVAWARE or using your initial direct register method.
    We will all be able to help you MUCH MORE if you use Tivaware. If you haven't done it, please do it today - think of it as "investing two hours to figure it out, install and compile", and then to save many hours later using "easier commands". It is probably less time than it took you so far reading the datasheet about registers.
    As for the interrupts, there is no such interrupt as "when a voltage level changes". If you want to continuously monitor ADC pins, you will need to set them continuously. On ADC, the interrupt is used on the following concept: you configure the ADC to sample with certain parameters, and when the sampling/conversion is finished on a hardware level, a interrupt will be generated so that you can service it and read the values.
    Regards
    Bruno
  • HI Bruno,

    I did this code with direct register method.
    I understood ADC concept.
    Analog pin and interrupt pin are different. Switch button is used to get interrupt.
    In my problem statement, in ADC loop I am calculating Peak voltage, error such parameter.
    In interrupt handler I want to reset these parameter and start scanning Analog pin again & calculate these parameter.

    Regards,

    Krishnat

  • Krishnat Pawar said:

    HI Bruno,

    here I configured port F swich as input and Led as output.

    When switch is pressed Led will blink.

    Something is wrong in interrupt configuration. Bcoz if I do same by polling then code works fine.

    I refer this link : www.youtube.com/watch

    Regards,

    Krishnat

  • Krishnat,
    Yes, we can see you did your code with direct register method.
    Both Amit and myself are suggesting you to use TIvaware.
    Nobody will have the time or patience to try to figure out your codes - I'm sorry to put things that way but it is the truth.
    Get a simple GPIO Tivaware example to work on your environment, and your problems (at least the current ones) will be solved.
    Regards
    Bruno
  • hi,

    I m newbie. from last 1 month only I started working with Tiva C.

    Earlier i have worked with Arduino board only.

    At my work-space nobody worked with Tiva, and So I started learning by watching you-tube videos where direct register method has been explained.

    I want to switch to tivaware as u both suggested.

    Is there any document available regarding software, drivers , libraries configuration information is given and some basic example code.

    any document regarding API's, eg what is API,builtin API, how to modify, how to create your own API

    If any link available please share with me.

  • Krishnat,
    For some bad luck, it seems like you selected "the wrong youtube videos" :)
    If you haven't done so, go to www.ti.com/tivaware, and download the COMPLETE option of TivaWare for C Series.
    After installing, inside the /docs folder, you will see a big PDF (almost 5Mb). It is like taking a kid first time to Disney... "Oh - I had no idea they had all these for me to play with!".
    There are "easier, efficient solutions" for almost everything you use on a project: SPI, GPIO's, UART, TIMERS, etc etc etc.
    As for "documents on how to create an API", take it slow: that is more than anything related to C programming, not to TM4C planet. Once you get used to the elegant implementation strategy that Tivaware uses, you will be tempted to create your own libraries and use them in different projects - but it will take some learning time. Meanwhile, make it simple - just add whatever custom-created function to a file inside your project, or even inside your main file, for starters.
    Bruno
  • hi,

    Thanx for reply..

    still stucked..

    I refered :Tiva™ C Series Development and Evaluation Kits for IAR Embedded Workbench

    still getting error:

    blinky.c
    Fatal Error[Pe1696]: cannot open source file "inc/hw_memmap.h" D:\blinky\blinky.c 27
    searched: "D:\blinky\"
    searched: "D:\blinky\..\..\..\..\"
    searched: "C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.5\arm\inc\"
    searched: "C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.5\arm\inc\c\"
    Error while running C/C++ Compiler

    Done. 1 error(s), 0 warning(s)

    ......................................................................................................

    same error as shown in this video : 

    Problem still persist if create new project and copy only blink.c from  "board/examples".

    I copied that header file in my workspace, I added path in preprocessor window, still problem persist.

    waiting for reply.

    regards,

    Krishnat

  • Hi Amit, Hi Bruno Saraiva,

    I solved previous problem.

    I just created project in : C:\ti\TivaWare_C_Series-2.1.3.156\examples\boards

    instead of D:\  drive.

    Now I manage to do programs with API's.

    I have done switch interrupt code and timer interrupt code using API.

    I want one more help:

    Problem:

    I have one pulse as shown in fig. Pulse width is 10 to 25 us. But next pulse will come after 100 ms.

    I need to find peak of each pulse. I have reference peak value. I need to generate error send to DAC module.

    In my current code,

    If I take one sample and check whether peak or not, and calculate error send to DAC,

    this code takes 35 us time.That means pulse is gone.

    How should I tackle this situation.

    I have one solution, I want suggestion from you , whether it is feasible or not??

    ADC0 and ADC1- same pulse as input

    ADC0-Comparator

    ADC1-uDMA module

    I will configure my ADC0 module for digital comparator for HIGH band in always mode.

    I will start my uDMA module to store ADC1 samples until my comparator output is High.

    Once comparator output is LOW, I will start find peak out of stored samples & generate error send to DAC module.

  • Hi Amit, Hi Bruno Saraiva,

    I am glad to tell you that, I successfully done my assignment.

    BUT, I wrote code in DRM style. 

    As you both suggested, I want to learn  API style coding.

    But How do I start..?

    Bruno Saraiva gave link of ' TivaWare™ Peripheral Driver Library user guide '

    where only given how many API's are there and their argument list.

    But no data is given when , which API is to be used.

    In contrast, data is given in datasheet for DRM style, for example, for ADC to configuration which registers need to be initialize and in which order is given in datasheet

     

    Still I tried coding using API style, I installed tivaware, I am using IAR workbench.

    I took ready made code and created project in  D drive. It gives me error.

    But when I did same project in this path "C:\ti\TivaWare_C_Series-2.1.3.156\examples\boards" it works fine.

    I already shared this problem with you in my previous post.

    As I had time bound to do assignment I preferred DRM style, as it is easy. and videos are available which are related to my assignment ADC, TIMER interrupt, switch interrupt.

    I hope you will reply and give valuable information.

    regards, 

    Krishnat