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.

eZ430RF2500T error in reading ADC value.

Hello,

I am currently using the eZ430RF2500T. I have connected the 7th pin i.e. analog input 4 as given in the user guide. I have connected a berg pin to the 7th pin of the board, soldered it and then connected it to a external voltage.

Here is my code-

ADC10AE0 |= 0x10;
ADC10CTL1 = INCH_4; 
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON ;


__delay_cycles(240);

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

results[0] = ADC10MEM;

I have set the external voltage as 1V. So accordingly i should get a value of 2AA at the ADC10MEM.

But i am getting random values.

Can someone please help me as i am not able to narrow down on the problem.

Thank You.

  • The code as shown does not wait for the sampling and conversion to finish.
  • Thanks for your reply. I didn't connect the ground of the eZ430 to the external voltage ground.
  • That's another problem. However, once you started the conversion, you need to wait until it finishes. Depending on the used ADC mode, you an wait until ADC10SC clears again, or until ADC10IFG is set.
    If you just read from ADC10MEM without waiting, you may read the result of the previous (maybe long outdated) conversion, or even a random value.
    Setting ADC10SC is not a 'blocking library call' that doesn't return until the job is done. For the CPU, it is no different from writing a value to a variable. One instruction two or three clock cycles, then the CPU continues. Neither CPU nor Compiler know that this has started a hardware action and that it might need time to complete. Your code needs to synchronize with the hardware manually. The interrupt mechanisms can help you, if you use them. If not, you need to provide the proper delays.

**Attention** This is a public forum