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.

MSP430 5 minutes Sample Timing

Other Parts Discussed in Thread: MSP430F2013

Hi I am writing a code for MSP430F2013, I need to sample ADC every 5 minutes. ADC can be running all the time but I only need to read it every 5 minutes. I will be doing this for a period of 12 hours.

Any sugestion ?

Below is part of my code, I made a counting routine with "x" but I am not happy with this way.

while(1)
 {
   SD16CCTL0 |= SD16SC;                    // Set bit to start conversion
   _BIS_SR(LPM0_bits + GIE);               // Enter LPM0
  P1SEL |= 0X40;  

 //***************************************************************************************
 //                       5 MINUTES SAMPLE TIME STARTS  
 //

   CCR0 = 0xFFFF;                            // CCR1 COUNT VALUE FOR 5 MINUTES
   TACTL = TASSEL_1 + MC_1 + ID_3;        // SMCLK UP MODE
 //***************************************************************************************  
  }
}
// Timer A0 interrup service routine
#pragma vector = TIMERA0_VECTOR
__interrupt  void Timer_A (void)
   {
     x = x + 1;
     Sample_x = Sample_x + 1;
     Solar_Power = Solar_Power + Solar_Volts;
    if (x == 18)                                     // every sample is = 16s so count to 18 samples = 288s ( 4.8 minutes)
    {
      P1SEL &= ~ 0X40;                           // Turn LED ON
      x = 0;
    }
   }

  • Using ultralong delays almost always requires usage of counter variables.

    However, there's a trick that can be used to  get what you want.

    1) set up the ADC so that the S&H time is controlles by the timer. That means, on every timer cycle, one conversion is done.
    2) use the DTC feature of the timer to transfer x (1..255) results from ADC10MEM to a result variable.

    After x conversion (= x timer cycles) you'll get an ADC10 interrupt. Which enters an ISR that can wake up the main thread from sleep mode and has the last conversion result stored in the variable.

    For 5 minutes between wakeups, you'll need a timer cycle of 300/255 = 1.176 seconds, which is easily done with a 32768Hz clock source for the timer. This is the minimum. If you use the tiemr clock divider, you can get 32768Hz/8 =4096 Hz, giving you a timer cycle of 16 seconds between conversions, so you only need 18.75 conversions through DTC.

    However, during all this time, the reference and the ADC need to be active, which greatly increases current consumption.
    It might be better to keep the counter variable, count to 18 and in the 18th timer interrupt, you switch on the ADC and reference, start the conversion using timer control (TImerA.OUT1) and in teh ADC ISR, you fetch the result, wake up main and disable the ADC again.
    This will probably be the most energy-efficient solution.

  •  

    I understood, but I am little confuse.

    I could set the ADC to be controlled by the timer, but if the timer is doing its conversion only every 5 minutes the results that I need all the time will be lost. I need to measure battery voltage all the time so as solar voltage, solar current could be measured every 5 minutes and then computed with solar panel voltage. I just don't know if that is what you are talking about .

    Thanks

     

  • Looks like I misunderstood your requirements.

    Yoiu need a constant conversion of one analog input (battery voltage) and want to additionally measure solar voltage and current every 5 minutes?
    hen I'd configure the ADC to constantly convert all three, and just skip the current/voltage calculation most of the time.

    Since you're doing one of the three conversions all the time, you'll need the reference on all the time too, so it doesn't waste much additional energy to sample all three.

    In this case, I'd just set up the timer to any interval of your liking, count up a variable inside teh ISR and when it reaches a certain threshold, main can do the additional calculation once and reset this variable.

    Much of the optimum strategy depends heavily on the exact project requirements. Sometimes down to microseconds. A small difference here will make a completely different strategy teh optimum one.

**Attention** This is a public forum