MediaTek Link-it One and EmonLib

Dear Open Monitor 

We based out of India, we recently import your Link-it board  (  , It is ARM core processor...

, We are in Sensor Analytics, and we use OpenEnergyMonitor ( method to monitor the power. They have the API library , EmonLib.cpp and .h, It is working perfectly with Aurduino based boards, Now I use the same for the Link-it, The compilation is fine, after I upload the sketch...The processor is taking too much time to process the Arithmetic operation it seems, 

 In the Arduino this loop takes, 1 -2 secs, but in Link-It is taking more than 60 secs, Is there any thing wrong, or Math library issues, Or the way analogRead being used?, 

We are kind of stuck here, could you help Us...


float EnergyMonitor::calcIrms(int NUMBER_OF_SAMPLES)
 Serial.println("Enter CalcIrms.. "); 
  int SUPPLYVOLTAGE = 3300;                        //SPARK delete readVcc();
  for (int n = 0; n < NUMBER_OF_SAMPLES; n++)
    lastSampleI = sampleI;
    sampleI = analogRead(inPinI);
  //  delayMicroseconds(250);                //SPARK this delay spaces samples to allow phase correction
    lastFilteredI = filteredI;
    filteredI = 0.996*(lastFilteredI+sampleI-lastSampleI);

    // Root-mean-square method current
    // 1) square current values
    sqI = filteredI * filteredI;
    // 2) sum 
    sumI += sqI;
/*    Serial.print("Sampling Loop.. CalcIrms. Loop Number . "); 
    Serial.println(sumI); */

  float I_RATIO = ICAL *((SUPPLYVOLTAGE/1000.0) / 4096.0);
  Irms = I_RATIO * sqrt(sumI / NUMBER_OF_SAMPLES); 

  //Reset accumulators
  sumI = 0;
 Serial.println("Exit CalcIrms.. "); 
  return Irms;




Robert Wall's picture

Re: MediaTek Link-it One and EmonLib

Unless somebody here has that board, I doubt we can help you.

You need to start from basics, not lift a library that's designed for one processor family and expect it to work with another. You need to use our algorithm, but not (necessarily) our code. Start with reading an analogue port and time that. On the Atmel328P, we get roughly 2500 sample pairs (voltage and current) per second, and that's with doing the maths for rms calculations using floating point arithmetic. Then you can add the part of the maths that's performed every sample, and time it. The add the 'end of loop' maths and repeat. Finally, add the calibration maths. I suspect that's where the delay will be because of the need to measure the internal reference voltage so as to work out the actual rail voltage (assuming you need to do that - it's really only needed for battery operation where the rail voltage can change markedly).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.