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/CC430F6137: Read ADC output value using IQmathlibrary

Part Number: CC430F6137

Tool/software: Code Composer Studio

Sir, I try to read adc output value using IQmathlibrary but that value is not correct. how to read adc output value using IQmathlibrary?

here attached model code. 

int main(void)
{
 _iq1 A0results,A1results,index=0;
 float Iamps,Volt,Power=0,RMS_Current=0,RMS_Voltage=0;
 char res[12],res1[12];


WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer

P1DIR |= 0x01;
uart_init();

P2SEL = 0x0F; // Enable A/D channel inputs

ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_8; // Turn on ADC12_A, extend sampling time
// to avoid overflow of results
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_3; //3 // Use sampling timer, repeated sequence
ADC12MCTL0 = ADC12INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = ADC12INCH_1; // ref+=AVcc, channel = A1
ADC12MCTL2 = ADC12INCH_2+ADC12EOS; // ref+=AVcc, channel = A2
// ADC12MCTL3 = ADC12INCH_3+ADC12EOS; // ref+=AVcc, channel = A3, end seq.
ADC12IE = 0x04; // Enable ADC12IFG.3
ADC12CTL0 |= ADC12ENC; // Enable conversions

while(1)
{

ADC12CTL0 |= ADC12SC; // Start conversion


 while(!(ADC12IFG2));
A0results =ADC12MEM1;
A1results  = ADC12MEM2;

Iamps = _IQ1toF(A0results);
Volt = _IQ1toF(A1results);
uart_tx(0x0d); uart_tx(0x0a);
// Iamps = A0results;
uart_str("I:");_IQ1toa(res, "%2.4f", Iamps); uart_str(res);
uart_str("V:");_IQ1toa(res1, "%2.4f", Volt); uart_str(res1);

}

}

  • Hello Sivanathi,
    you're mentioning readout of ADC values using IQMath Library, but in the code sample I see
    while(!(ADC12IFG2));
    A0results =ADC12MEM1;
    A1results = ADC12MEM2;
    So do the values in this spot match your expectation, or is this where they already do not meet the expected range?
    Have you used one of our ADC code examples for this? That would be our recommendation.
    The of IQmath Library has no impact on handling the ADC and the results. Your code just needs to utilize the IQmath library functions for the post processing of the ADC values.

    Best regards
    Peter
  • Hello Sivanathi,
    could you please let us know whether you still need support on this? In case you do, you can reopen the thread by posting to it. For now I assume your problem is solved.

    Best regards
    Peter