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.

Analog Voltage Reference Using the Energia IDE ( Tiva C Series Connected Launchpad TM4C1294 )

Other Parts Discussed in Thread: ENERGIA, TM4C123GH6PM, TM4C1294NCPDT

I am having some trouble using analogReference() in the Energia IDE. I am trying to change the reference voltage from the internal source (3.3 V) to an external source. I know that in order to do this, according to the Energia reference webpage, you must use the argument EXTERNAL. Whenever I go to verify and compile my code, an error is displayed in the console that states that EXTERNAL is "not declared in this scope." What must I do to fix this issue? Thanks. 

  • I believe you will find that analogReference() is a dummy function on Tiva platforms in Energia. The references to DEFAULT and EXTERNAL were supported in the MSP430 libraries only.

    Randy
  • That's disappointing. Do you think that analogReference() would work in CCS?
  • Hi John,

    You could use Energia in CCS yes (it's the only way you can use those functions) and it would be exactly the same! A different IDE will not change the libraries being used.

    As Randy said it's a dummy function, look at the source code:
    //
    //empty function due to single reference
    //
    void analogReference(uint16_t mode) {
    }


    If I am not mistaken the TM4C123GH6PM actually does not have an option. The ADC is powered by the VDDA and it takes the voltage reference from that. In the launchpad it's connected to the VCC if I am not mistaken. So it really it isn't even an error from the Energia libraries.
    Only in the TM4C1294 launchpad you can select an external reference independent of the VDDA. They didn't add the function when this launchpad was added because the pin is probably not accessible.
  • Luis,

    You said that on the TM4C1294 you have the ability to select an external reference. I'm having the hardest time trying to figure out how to use the VREF pin. How would I even go about using void analogReference( uint16_t mode )? I understand that you need an un-signed 16-bit integer as an argument, but that is about all that I understand. I'm quite new to this if you can't already tell.

    Thank you for your time.
  • Ok so let me try to be more clear.

    The TM4C1294 does have the ability to select an exteral reference. It's an option.
    I actually went ahead and check the pin map (link here) and the pin is available (you could have no easy access to the pin).

    Now can you select the option with Energia? No you cannot.
    I showed above the function. It is empty. It does nothing!

    Do you understand? With Energia Libraries you cannot change the reference.

    You would need to use Tivaware libraries or direct register access to do what you want.



  • Luis has done his (usual) great job in assisting.    Good that.

    As small, tech biz owner - I (most often) "Look for the bigger picture."    And such reveals: "Why do you think that changing from the "normal/customary" 3V3 analog reference - will prove beneficial?"

    For that to (possibly) be true - it must be that your input signal level falls far beneath - that 3V3.    Is that (really) your case?

    If so - might there be another means to achieve your objective?    Indeed there is - and requires NO HW modification to your board.   (but does require a small, added breadboard)

    As your ADC accommodates an, "input signal span betwen 0 and 3V3" you may "amplify" any lesser signal - to "max out" at 3V3.    A sub 1 (USD) "op amp" (many available from this vendor/others) achieves that goal - over 10K Google listings detail the "how."

    If and when the input signal fails to comply with the MCU spec one may: a) "bend the spec" (can you say, "over-clock") NEVER Recommended!  or b) bend the input signal to "match" the ADC's (bit limited) spec.  (much better)

    In fairness/completeness - one weakness arrives w/this "amplify" suggestion.    I'll leave that in "reserve" for later - and much doubt that it will have any serious impact upon your goal...

  • My I add that a precision external reference allows for added precision - in the launchpad VDDA is connected to the VCC basically, how precise is the 3.3V voltage regulator?

    Though cb1 suggestion of using a op-amp to amplify (and could be used to scale down too) the signal would prove to work also on the TM4C123
  • OK, try this. In wiring_analog.c, replace the analogReference function with this:


    #ifdef __TM4C1294NCPDT__ void analogReference(uint16_t mode) { if (mode == EXTERNAL) ROM_ADCReferenceSet(1); else ROM_ADCReferenceSet(0); } #else // //empty function due to single reference // void analogReference(uint16_t mode) { } #endif

    This is untested. Should work.

    Edit: Forgot to add "#define EXTERNAL 1" in Energia.h


    Randy

  • cb1_mobile said:
    "Why do you think that changing from the "normal/customary" 3V3 analog reference - will prove beneficial?"

    The obvious answers would be accuracy and repeatability, the power supply makes a dreadful reference (generally between 3 and 4 bits).

    Robert

  • Are you not assuming that the VDDA pin is - or is about to - be tied to the "unfiltered" Vdd rail?

    Once again (always?) - user is vague on why there is such, "need."

    On our past LX4F we have a VDDA pin - and power it thru a proper, quiet/filtered 3V3 source. To route so special a "reference pin" to the dreadful supply was not my suggestion nor intent.

  • Not just a noise issue. Sometimes a precision reference is required. Depends on what you are measuring and what accuracy is required.
  • cb1- said:
    Are you not assuming that the VDDA pin is - or is about to - be tied to the "unfiltered" Vdd rail?

    No, lack of filtering would make it worse.  I was assuming a well filtered VDDA.

    Robert

  • Randy, 

    First of all, thank you for your post. For a beginner like myself, It means a lot for someone to make things simple and not recite a bunch of jargon. I am still having a bit of trouble though. Whenever I tried to input the source code you posted, it gives me the following error. It is apparently something to do with the arguments within ROM_ADCReferenceSet(). What is wrong? 

    Thank you, 

    - John

  • Oops, you are correct.  I forgot an important argument to the ReferenceSet function.

    The two calls should be: ROM_ADCReferenceSet(ADC0_BASE, 1); and ROM_ADCReferenceSet(ADC0_BASE, 0); respectively.

    Randy

  • John Wells said:
    make things simple and not recite a bunch of jargon

    If some are guilty of such - would you be good enough to list - so that we may correct?

    And - we must note, does your thread's title, "Analog Voltage Reference Using the Energia IDE ( Tiva C Series..." escape your desired, "Jargon free?"

  • Randy,

    The code builds and debugs just fine. Although, whenever I read the VREF pin voltage with a multimeter, it still reads 3.3 V showing that the switch from internal reference to external was not made. Also, whenever I use the code pictured below, there aren't any values printed to the serial port. 

    I apologize for being a pain,

    - John

      

  • John,

    The VREF pin is not an output, it is an input. You have to supply the reference yourself. If you are using a Launchpad, it is already connected to 3.3V. You will have to disconnect it and connect it to your reference.
    This is the part where you need to study the Tiva data sheet and schematics of the hardware to understand how the reference is connected.

    Randy
  • Randy,

    I realize that the pin is an input; I must have not made myself clear. I was using the multimeter to ensure that the VREF pin voltage was 0 V (which it wasn't) because that would show that VREFA+ was chosen instead of VDDA. I have been studying the Tiva™ TM4C1294NCPDT Microcontroller Data Sheet and the Tiva TM4C129X ROM User's Guide all morning. I now know that the VREF bit in the ADCCTL register must be assigned the value 0x1 in order to reference an external voltage. I believe this is what you were trying to do whenever you posted the source code for me to try. Although, the code did not return any results to the serial monitor, and I have no clue where to go from here.

    If you are wondering why I am so confused, I am a freshman Electrical Engineering student trying to get my feet wet.

    - John
  • John,
    It doesn't matter whether you select internal or external VREF, the pin will not change. If you are using the Launchpad, the VREFA+ pin is connected to the 3.3V supply rail. you have to disconnect this by removing a 0 Ohm resistor in order to supply another reference.
    In either case, this will not keep the code from working. If the VREF is not what you expect then the result will be undesirable ADC readings.
    What are you planning to use for this external reference?

    Randy
  • Even if the reference input was floating, measuring it might not tell you much. Depending on the implementation there could be leakages to the power rail sufficient to bring it up. Also a number of implementations use a charge balancing approach in the conversion. This means that the reference input is not high impedance but needs to sink and source current. As a result the act of converting is likely to change the value of a floating reference "input".

    Robert
  • Randy,

    I'm wanting to supply a voltage that is smaller than the 3.3V power rail in order to increase the definition of the ADC. I would prefer to supply 1V, but apparently VREFA+ cannot receive any less than 2.4V according to the ADC Characteristics Chart. How would I go about removing the 0 Ohm resistor you mentioned? Also, keep in mind that the ADC readings that I am getting are not just undesirable, I'm not getting any reading whatsoever. There is nothing being printed to the serial port. If the code was working properly, and everything was as you mentioned, I would be seeing the same values printed to the serial port as if I did not include the analogReference() function.

    - John
  • Hi,

    John Wells said:
    ...smaller than the 3.3V power rail in order to increase the definition of the ADC

    This is really new, can you explain? using a smaller reference voltage make an ADC step smaller, buried into the digital noise and harder to extract from that noise. I think you may need to increase the resolution of the ADC, that can be done (within some limits) if using some kind of oversampling and averaging. If you use DC, this can be done easily; if AC, can be done, but a little bit harder and only on periodic waveforms. 

    As for using a reference function from library, use this:

    MAP_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V) ; (you tried to use, but ignored the second parameter)

    but with care, read the documentation - as not all TI's Cortex-M4 micros may have 1V reference or internal/external one.

    Petrei

  • John Wells said:
    Also, keep in mind that the ADC readings that I am getting are not just undesirable, I'm not getting any reading whatsoever. There is nothing being printed to the serial port. If the code was working properly, and everything was as you mentioned, I would be seeing the same values printed to the serial port as if I did not include the analogReference() function.

    It's not clear here, have you ever had a working A/D function? If so go back to that and make sure you have something that works, if not do that first.

    Once you have that working and if the micro supports an external reference, then you can use the 3V3 supply and make sure it still works with the external 3V3 supply. Only after that consider an external reference.

    John Wells said:
    How would I go about removing the 0 Ohm resistor you mentioned?

    I understand you are a student. Find someone (in the EE lab?) who can show you soldering.  It's not difficult but it's a lot easier if you have someone to show you.

    Finally, you would probably be better off amplifying the signal rather than adjusting the A/D range. As Petrei mentioned lowering the range may well lead to other issues.  There are accuracy gains in providing an external reference but probablyno gain in lowering the range significantly. If you use a reference with a high value below the lower end of the supply range you should be safe and at the most accurate point for the converter. And remember the A/Ds on board micros are limited compared to the range of characteristic available from external A/Ds

    Robert

  • Long, long ago - one here questioned - the need & usefulness of, "External Reference."    And only recently has the desire for, "vastly improved ADC signal accuracy and/or precision" - in the measure of 1V0 signal levels - been admitted.    And poster noted that the MCU could and would not accommodate so low a reference voltage - even hallowed/external one.

    Far simpler, "gain of 3" op amp stage - surely seems best/fastest - "Good for Gov't Work" solution.   And - for initial test/check-out - as Robert has suggested - avoids (completely) the unwise, time-wasting, diversion into, "external reference!"

    KISS appears either untaught or unlearned - Robert's suggested - "small, incremental step approach" is clearly KISS in practice.

    Again - as past noted - there do exist far more accurate/precision ADCs - not burdened with MCU's (very) mixed signals - thus far more appropriate for higher analog measurement accuracy and precision.

    Poster may consider KISS, right tool for the job, and "asking for direction" rather than, "steering the thread toward rocky shores..."   Novice captains rarely, "direct large vessels" - perhaps for good reason...    And - just 6 posts in - more experienced ship captain "knew" poster's ship was "full steam" to rocky shores...