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.

How to use properly ADC10 Clock Source Select (ADC10SSELx) from the ADC10 (MSP430G2553)

Other Parts Discussed in Thread: MSP430G2553

Hello,

I'm using MSP430G2553 to measure the electricity voltage and the electricity current from the supply grid.
For I get a good precision I need at least 50 smaples for each cicle (60Hz) in each analog channel (voltage, current).
In my following code, I'm using a timer interruption to create my time base, and in the main loop, the adc10 always is working.In other words the samples are collected in each the timer interruption but the conversion is always happening.
Anyway I think I can improve that method if I manage to configure the adc10 for only convert in the timer interruption.But I don't know how to do that.
My aim is set SHI from the timer interruption instead of from the register ADC10SC.

I think one way would be using the register ADC10SSEL to do that, but I don't know how exactly.
I really appreciate any help.
Thanks in advance.

My code :

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

unsigned int nsample, n_ciclos, nint, nt, ad1=0, ad2=0, valoradc[2];

void main(void)
{
/*---------------------------------------------------------------------------*/
//  Inicializção de parâmetros e de variáveis:
/*---------------------------------------------------------------------------*/

WDTCTL = WDTPW + WDTHOLD; 
BCSCTL1 = 0x00;                    // Set DCO
DCOCTL = 0x00;

BCSCTL1 = CALBC1_16MHZ;                    // Set DCO
DCOCTL = CALDCO_16MHZ;

CCTL0 = CCIE;
TACTL = TASSEL_1 + MC_2/* + TAIE*/;              // SMCLK, Contmode 

  ADC10CTL1 = INCH_5 + CONSEQ_3;            // A5/A4, repeat multi channel
  ADC10CTL0 = ADC10SHT_0 + MSC + ADC10ON + ADC10IE;
  ADC10DTC1 = 0x02;                         // 2 conversions
  ADC10AE0 = P_X4 + P_X5;                   // P1.4,5 ADC option select

nint = 0; nt = 0;

  cc=6;
  n_ciclos = 60;

nsample = 32768 / (60*cc);          // nsample = 91

while(1)

{

 ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);               // Wait if ADC10 core is active
ADC10SA = (unsigned int) valoradc;       // Data buffer start
ADC10CTL0 |= ENC + ADC10SC;

_BIS_SR(/*LPM0_bits + */GIE);                 // Enter LPM0 w/interrupt   

}

}

// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
/*---------------------------------------------------------------------------*/
//  Rotina de armazenamento das leituras AD em intervalos de tempo fixos:
/*---------------------------------------------------------------------------*/
  CCR0 += cc;                                // 1 / (32768Hz / CR0) -> Time betwaeen samples

  ad1 = valoradc[1];        
  ad2 = valoradc[0];
    
  nint++;

  if(nt == 0 && nint==1)
  {
   nt=1;
  }
/*---------------------------------------------------------------------------*/
 
/*---------------------------------------------------------------------------*/
//  Rotina para evitar um loop infinito devido a perda de sincronismo:
/*---------------------------------------------------------------------------*/
  if(nint>1e6)
  {    
    CCTL0 &= ~CCIE;
  }
/*---------------------------------------------------------------------------*/
}

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

The Best Regards.

  • Pedro Bacheti said:
    Anyway I think I can improve that method if I manage to configure the adc10 for only convert in the timer interruption.But I don't know how to do that.

    The simple way is to not use CONSEC_3 but rather CONSEC_1 (single sequence). And inside the timer ISR you read the last results and set ADC10SC for the next sequence.

    More complex is the use of SHSx to trigger the next single conversion or the next sequence using TimerA0 CCR0/1/2 registers. But since you need to enter timer ISR each time anyway, to store the last results, this approach only reduces the jitter a bit but besides this gives no real advantages.

  • Hello Jens, Thanks very much for your answer. I did what you recommended me, and works.

    But you were right, my method didn't improved as I was expecting.

    Anyway your suggestion was very useful.

    The Best Regards.

**Attention** This is a public forum