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.

MSP-EXP430FR5994: Sampling rate and pure sine wave

Part Number: MSP-EXP430FR5994
Other Parts Discussed in Thread: ENERGIA

Hello,

What is the default sampling rate of the given Launchpad and how to set it in general?
On the other hand, how to generate a pure sine wave in order to calculate THD factor?
I work in Energia.

Best regards,
Adi

  • Hi Adi,

    I assume that you are using the ADC peripheral when you are referring to the sampling rate. Are you using the AnalogRead() method in Energia? Looking at the documentation for the AnalogRead() method, it looks like Energia implements a single-shot ADC conversion, taking approximately 100 microseconds to complete (typical). Thus, the sampling rate is driven by the rate at which you call the method. You can likely set up a timer to establish a periodic sampling rate.

    energia.nu/.../

    If you need more deterministic timing and/or faster performance, you may want to consider switching to C rather than using the abstracted Energia libraries.

    A good function generator would be a good place to start for THD measurement.

    Regards,
    Walter
  • Hi Walter,

    Yes, I use AnalogRead() method. So it means that limit is 10 ksps.
    By setting the timer, you mean using millis()? Or could you clarify it more in details?

    Best regards,
    Adi
  • Hi Adi,

    Yes, millis() or micros() could be used to set up an interval to give you slightly more deterministic sampling.

    For example, you could scan every ms for 1ksps using an approach like the one below:

    unsigned long compareValue;

    compareValue = micros();
    while(1)
    {
    compareValue += 1000;
    while(micros() < compareValue)
    {
    // Wait
    }
    AnalogRead(pin);
    }
  • Hi Walter,

    Taking into account that I measure AC voltage and current, a period of 20 ms is more interesting for me or N x 20 ms. So it means each period must provide 200 readings. Furthermore, I have to provide continuous monitoring and micros() will overflow in 70 minutes while millis() does the same in 50 days. What do you think about that?

    Best regards,
    Adi
  • Hi Adi,

    I see there is an example of a msec timer in Energia examples (cut/paste below).
    You could modify it to meet your timing requirements and in the interrupt handler you could make your call to measure the ADC.

    /*
    Sample program that uses 1 tasks triggered by the OneMsTaskTimer
    loop is empty as all is done in the ISR
    running 1 tasks with LED.

    The circuit:
    * LED common tied to VCC.
    * LED connected to I/Os

    This example code is in the public domain.

    */

    #include "OneMsTaskTimer.h"

    const int heartbeatPin = RED_LED;
    int status = 0;

    OneMsTaskTimer_t myTask ={5, flash, 0, 0};

    void setup() {
    // open the hardware serial port
    pinMode(heartbeatPin, OUTPUT);
    OneMsTaskTimer::add(&myTask); // 1ms period
    OneMsTaskTimer::start();

    }

    void loop() {
    }

    // interrupt handler passed to OneMsTaskTimer
    void flash(){
    if (status){
    digitalWrite(heartbeatPin,HIGH);
    }else{
    digitalWrite(heartbeatPin,LOW);
    }
    status ^= 0x0001;
    }

**Attention** This is a public forum