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: reading analog values

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

Tool/software: Code Composer Studio

hi,

I'm a total beginner with the tiva c-series TM4C123g Launchpad.and i am using ADXL1001z motion sensor with it. the question is how can i read the analog values form this motion sensor using the board. i have designed the hardware so that Vout from the sensor is an analog input at pin AIN0/PE3. and now all i want is to read data from there. id be really thankful if anyone can help me with this.

Thanks in advance

  • Do you have TivaWare, Code Composer Studio, and a ARM compiler (either GCC or TI ARM compiler for TM4C) installed?

    Once you have these three things installed, and assuming you installed them to the default locations, there are example programs located here which pertain to the development board:

    C:\ti\TivaWare_C_Series-2.1.4.178\examples\boards\ek-tm4c123gxl

    And more example programs located here which pertain to the TM4C family MCUs:

    C:\ti\TivaWare_C_Series-2.1.4.178\examples\peripherals

    In particular, look at the example programs for the ADC:

    C:\ti\TivaWare_C_Series-2.1.4.178\examples\peripherals\adc

    You'll probably want to study the one called single_ended.c.

    To use this as a starting point, create a new CCS project for your particular microcontroller model (I think that's TM4C123GH6PM but please verify that) with TivaWare and copy-and-paste function calls from the example.

    Note that it is very important to make the SysCtlClockSet() call to set the system clock, and equally important to enable each peripheral that you want to use before making any calls to setup such peripheral. If you forget to enable a peripheral and attempt to write to any of its registers your program will go to FaultISR().

    Enabling ADC0 is done with SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0) as shown in the example program.

    You also have to enable the GPIO port that the pins you want to use are on. That's done with SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE).

    And tell the pin to be ADC type: GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3).

    And set up the ADC peripheral to get the results you want.

    The example program walks through all these steps and is well commented. I recommend taking the time to study the appropriate sections of the datasheet. You don't necessarily have to study what each bit in each register does because the TivaWare functions take care of most of that for you, but knowing how the peripherals work at a high level allows you to use TivaWare more effectively. Also, you'll need to know what the registers do when your programs misbehave and you try to diagnose why!
  • ** LIKE ** - ** LIKE ** - ** LIKE! **    (Staff/I could have (likely) SOLD another 'few K' of  Vendor MCUs/other devices - had NOT  - the (MOST NECESSARY) 'LIKE' Button - been ripped from our 'luke-warm'  (not quite DEAD) hands!  

    Oh MY - 12 Squared.     Your (rather) recent 'trunk confinement' seems (not) to have too, 'dulled your mind.'
    It is hoped that our poster 'recognizes & appreciates'  the great focus & effort you've extended.      (especially the clarifying narratives - rather than the (all too common - 'personality light' - (i.e. ice-cold) 'Industrial style' code blurbs!)     

    Your effort proves So 'detailed & convincing' that even a 'feeb' (such as myself) - may actually 'attempt' to 'Slay the ADC Dragon.'      (Maybe! ...  my quick-glance @ 'Staff's eye rolls' - signals that 'I've got MORE work to do' - as 'one's reach should not SO FAR EXCEED' one's grasp.)      Good job - non-Robotic User Guides are (always) in 'high & much appreciated demand!'

  • cb1_mobile said:

    ** LIKE ** - ** LIKE ** - ** LIKE! **    (Staff/I could have (likely) SOLD another 'few K' of  Vendor MCUs/other devices - had NOT  - the (MOST NECESSARY) 'LIKE' Button - been ripped from our 'luke-warm'  (not quite DEAD) hands!  

    I, too, miss the LIKE button.

    cb1_mobile said:

    Oh MY - 12 Squared.     Your (rather) recent 'trunk confinement' seems (not) to have too, 'dulled your mind.'

    I had nothing else to do there but think, so my mind is sharper than ever!

    cb1_mobile said:

    It is hoped that our poster 'recognizes & appreciates'  the great focus & effort you've extended.      (especially the clarifying narratives - rather than the (all too common - 'personality light' - (i.e. ice-cold) 'Industrial style' code blurbs!)     

    Your effort proves So 'detailed & convincing' that even a 'feeb' (such as myself) - may actually 'attempt' to 'Slay the ADC Dragon.'      (Maybe! ...  my quick-glance @ 'Staff's eye rolls' - signals that 'I've got MORE work to do' - as 'one's reach should not SO FAR EXCEED' one's grasp.)      Good job - non-Robotic User Guides are (always) in 'high & much appreciated demand!'

    Reading the ADC is the easy part. Filtering what you read to get rid of that annoying phenomenon called NOISE is another story.
    Note that the TM4C's ADC has this really great feature called Hardware Averaging of up to 64 samples. I am pretty sure that to make effective use of this, the ADC should be configured to trigger from a Timer peripheral, so that samples are taken at regular intervals. If you want to report, say, 1000 samples per second, take 64,000 samples per second and use the hardware-averaging. But make sure you're not sampling at the same frequency as your switching power supply!
  • Should 'FAST & HIGH ACCURACY' Analog Measures be sought ... Dedicated  ADCs - appear 'de rigueur.'     (At least that proves the case - for our larger & most serious clients.)

    As any modern MCU has 'SO much high speed switching' AND so many 'mask layers' - such places a (very) high challenge upon the (hapless) "MCU-Analog Designer!"    (oxymoron - anyone?)

    You note the 'switching power supply frequency - yet are there not MANY such frequencies, and harmonics, and 'beat-frequencies' - w/in even the simplest of MCUs?     And - either hardware or software 'averaging' - trades (jitter reduction) for (Speed Reduction) - which a (proper/dedicated) ADC - may (completely) escape! 

  • cb1_mobile said:

    Should 'FAST & HIGH ACCURACY' Analog Measures be sought ... Dedicated  ADCs - appear 'de rigueur.'     (At least that proves the case - for our larger & most serious clients.)


    As any modern MCU has 'SO much high speed switching' AND so many 'mask layers' - such places a (very) high challenge upon the (hapless) "MCU-Analog Designer!"    (oxymoron - anyone?)




    I agree! Just look at any electronics publication. What are they talking about all the time? Mixed signal. Every other article is about mixed signal. Whenever trade journals spend so many column inches talking about a particular subject, you know it's a really big problem.


    cb1_mobile said:


    You note the 'switching power supply frequency - yet are there not MANY such frequencies, and harmonics, and 'beat-frequencies' - w/in even the simplest of MCUs?     And - either hardware or software 'averaging' - trades (jitter reduction) for (Speed Reduction) - which a (proper/dedicated) ADC - may (completely) escape! 

    Yes there certainly are. But I didn't want to overwhelm the OP. Let's first get those sensor readings into the MCU in a digital form, and then figure out how to get rid of that ever-present noise.

    Two more frequencies you'll most likely want to avoid: 50 Hz and 60 Hz!

  • What about the frequency emitted by the (wife, gf, significant other - even 'boss') when identifying  'ANY'  of our 'multiple transgressions?'

    Is not nature  'to be praised'  - for enabling (highly) selective, filtered  hearing?      Huh?

  • cb1_mobile said:

    What about the frequency emitted by the (wife, gf, significant other) when 'identifying ANY' of our 'multiple transgressions?'

    There I cannot help you, my friend!

    cb1_mobile said:

    Is not 'nature' to be 'praised' - for enabling (highly) selective, filtered hearing?      Huh?

    Yes!
  • BTW - Go read my response to Chester's '8b/10b' (aimed primarily at YOU/Others)  ... the effort/achievement of those (college & gifted high school) students - in (pardon) 'Many 'passing' upon internship offers from this vendor' - instead spending their summer @/around 'Hacienda cb1' (noted as a back-room - behind (another) back-room - proves inspiring ... (and revealing ... MORE than a FEW - like 'LIKE!' - and recognize its demise as 'cruel/demented' - very 'off-putting!')

    Youth - especially 'youth'  - Crave Recognition (especially well identified (i.e. REAL) Recognition) - which is 'symbolized' by (the departed) 'LIKE!'