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/MSP430G2553: divide adc response by 100 gives a strange results

Part Number: MSP430G2553


Tool/software: Code Composer Studio

Hi Everybody,

I have some strange event that i can't understand why it is happenning

i have an external ADC (HX711).

I'm getting  numbers around 8561023 which is good

when i divide the answer by 100 (85610) i'm getting an unstable results (sometimes numbers arround 8561023 and sometimes very large numbers like 14701165)

i thought the time is the problem so i set delay of 2500 ms it returnning numbers around 8561023 which is good

but than i tried another approach (maybe the arithmatic is the problem) so i set the divide to another parameter (not  connected in any way to the adc response), the numbers around 8561023

for example,

wt_curr = ((long)bitbang_data_in())  ---> gives me good response

wt_curr = ((long)bitbang_data_in())/100; --> gives me bad response

wt_curr = ((long)bitbang_data_in())/100;

__delay_cycles(2500); --> gives me good response

wt_curr = ((long)bitbang_data_in());

wt_zero /= 100; --> gives me good response

bitbang_data_in is a function that gets the data from adc.

how can i devide the wt_curr by 100 without a delay?

I hope i made myself clear about my issue

Thank you

  • Hi Joe,

    This is a unique problem, thanks for providing the examples. Bit banging can be tricky and is very timing dependent. I'm suspicious of something being wrong within that function but it doesn't explain the issue you're experiencing. Is it possible to communicate with the ADC over SPI or I2C instead of using bit banging?

    I'd like to test this out on my own board as well. Would you be willing to post a reduced version of your code that can be used to test this issue?

    Best regards,
    Caleb Overbay
  • Your experiment does not necessarily prove that problem is division. Did you try following code, got good result three times in a row?

    wt_curr1 = ((long)bitbang_data_in());

    wt_zero1 = wt_curr1/100;

    wt_curr2 = ((long)bitbang_data_in());

    wt_zero2 = wt_curr2/100;

    wt_curr3 = ((long)bitbang_data_in());

    wt_zero3 = wt_curr3/100;

    Note that I slightly modified code.

  • To isolate the root problem, please turn off optimazition at first. Is wt_curr local or global?

**Attention** This is a public forum