I notice a difference in results, but it should not be. - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

I notice a difference in results, but it should not be.


  • Please log in to reply
14 replies to this topic

#1 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 26 July 2012 - 09:32 AM

Hello,
I am using my Netduino for solar logging.
I had notice these days that there was een difference in output between my Solar Inverter wattage output and the netduino output. My question is why?

I log the time between 2 electrical pulse with a KWH counter in the electrical box.

'wait for the first pulse
   dtStartTime = DateTime.Now
   Do
      If portElectricPulse_D13.Read()   'wait for the pulse'
 
Here is the code for the 1st image/stream:


dtEndTime = DateTime.Now
sSeconds = (dtEndTime.TimeOfDay - dtStartTime.TimeOfDay).Seconds.ToString
sMilliSeconds = (dtEndTime.TimeOfDay - dtStartTime.TimeOfDay).Milliseconds.ToString
dblSecsAndMsecs = CType((sSeconds & "." & sMilliSeconds), Double) 
intWattage = CInt(1800 / dblSecsAndMsecs)

Posted Image


Here is the code for the second stream, and this one calculate it oké:
dblTestWattage = (dtEndTime.Ticks - dtStartTime.Ticks) / TimeSpan.TicksPerSecond
intTestwattage = CInt(1800 / dblTestWattage)


Here is the code for the third stream:
tsElapsedTime = dtEndTime.Subtract(dtStartTime)
dblTestWattage2 = CType((tsElapsedTime.Seconds & "." & tsElapsedTime.Milliseconds), Double)
inttestwattage2 = CInt(1800 / dblTestWattage2)


Posted Image

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 July 2012 - 09:41 AM

Hi Ellen, If I understand this correctly; you need to measure the time between two pulses. Am I right in that? What kind of timeframe should I think of, in ns, µs, ms, seconds, minutes? Ps. nice project you're building!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Gorf

Gorf

    Advanced Member

  • Members
  • PipPipPip
  • 96 posts

Posted 26 July 2012 - 10:29 AM

I had an idea to do something similar, but ended up buying a CT sensor-based meter which sent out the data I need via serial. The original idea, before "economics" got in the way, had been to put a photosensor over the LED on the generation meter. It flashes once per Wh so the time between flashes gets shorter as the sun gets brighter. For Stefan: On a 4 kWp system generating at full capacity, you'd expect the light to be flashing approx once per second (4000 times every 3600 seconds). The difference between 1803 and 1804 watts equates to a time difference of 277.7778 µs between the rate of flashing. For Ellen: Can't see what's wrong with your code - it's as if the internal clock spent half an hour running 1½ seconds too fast.

#4 Gorf

Gorf

    Advanced Member

  • Members
  • PipPipPip
  • 96 posts

Posted 26 July 2012 - 10:31 AM

Incidentally, with our lovely UK weather, the 10 kWp system on the roof of this office building is currently generating 400 W. In July!

#5 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 26 July 2012 - 02:28 PM

Hi Ellen,

If I understand this correctly; you need to measure the time between two pulses. Am I right in that?
What kind of timeframe should I think of, in ns, µs, ms, seconds, minutes?

Ps. nice project you're building!


Hello Stefan,
The pulse meter give 2000 pulse per KiloWatt so 3600 seconds in 1 hour / 2000 give 1.8 seconds per pulse/KW. And I update the cosm server every 20 seconds.

There must be some kind of something wrong. It is between lets say 1610 Watt and 1803 watt.
Have a look at my afternoon image (the gap), and the afternoon mirror the morning, the two should be identical:


This one is the bad one.
Posted Image

This one is the good one:
Posted Image

#6 Gorf

Gorf

    Advanced Member

  • Members
  • PipPipPip
  • 96 posts

Posted 26 July 2012 - 03:03 PM

Are the calculations for AC_Wattage, zTestWattage2 and zTestWattage all in the same thread?

#7 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 26 July 2012 - 05:30 PM

dtEndTime = DateTime.Now
sSeconds = (dtEndTime.TimeOfDay - dtStartTime.TimeOfDay).Seconds.ToString
sMilliSeconds = (dtEndTime.TimeOfDay - dtStartTime.TimeOfDay).Milliseconds.ToString
dblSecsAndMsecs = CType((sSeconds & "." & sMilliSeconds), Double) 
intWattage = CInt(1800 / dblSecsAndMsecs)


I have seen issues with the implicit casting of values in code like yours. You should consider explicitly casting everything. So, for instance, the 1800 should be either 1800.0 or 1800d.

Also, add a Debug.Print statement or write to a log to verify that the input and output of the CType statement is working as expected. Don't assume that it is...

By the way, what kind of chart object is that?

-Valkyrie-MT

#8 Cuno

Cuno

    Advanced Member

  • Members
  • PipPipPip
  • 144 posts
  • LocationZürich / Switzerland

Posted 26 July 2012 - 06:16 PM

By the way, what kind of chart object is that?

Looks like a Cosm, formerly Pachube, feed display.

Cuno

#9 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 26 July 2012 - 07:29 PM

Are the calculations for AC_Wattage, zTestWattage2 and zTestWattage all in the same thread?


Yes Gorf, they are all in the same thread.

#10 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 July 2012 - 07:37 AM

I wonder if there's a pattern in the gaps. Is it recurring every xx minutes for example? You're using a Netduino Plus, and pushing the data over the web. I could imagine a delay in your main loop can happen when another thread becomes active. This could be a native thread, like a dhcp renew. Or the process of uploading the data took some more time. You're not using an interruptport right now, are you? If you did, the timestamp sent with the event parameter is not affected from delays in your code.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#11 Gorf

Gorf

    Advanced Member

  • Members
  • PipPipPip
  • 96 posts

Posted 27 July 2012 - 10:27 AM

It's not a delay causing the problem - she's using dtEndTime as the basis for all the calculations, all in the same thread. Once that's assigned, the ND can hang for 20 minutes - the output should still be the same for all three graphs. Similarly, it's not a missed pulse. If the ND did not "see" the pulse sent from the meter, you would get an erratic graph as a result, but all three methods would produce the same error. The calculation based on dtEndTime.Ticks produces the desired result. The ones based on dtEndTime.TimeOfDay and (indirectly) dtEndTime.Seconds & dtEndTime.Milliseconds produce periodically erratic results. It's as if the ND is forgetting the basis for conversion between Ticks and Seconds, and then recovering.

#12 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 27 July 2012 - 01:06 PM

Just an addition to everything has been written above.
The "Seconds", "MIlliseconds", etc properties yield the value of the respective field in the resulting DateTime structure, and *NOT* the total time elapsed.
For instance, when you subtract two timestamps such as 09:10:11 minus 09:09:10, that yields a TimeSpan of 00:01:01. The "Seconds" property gives just one second, not 61.
Instead, the TotalSeconds gives 61.
Have a look here (regular .Net): http://msdn.microsof...m.timespan.aspx

"Ticks" are heavy to use (it's a "long"), but they give an exact representation of the whole TimeSpan value.
Cheers
Biggest fault of Netduino? It runs by electricity.

#13 Gorf

Gorf

    Advanced Member

  • Members
  • PipPipPip
  • 96 posts

Posted 28 July 2012 - 08:20 AM

Minutes should be included, for completeness, but if there's more than a minute between pulses, Ellen's solar system would be outputting just 30 Watts. Depending on the inverter model, that's probably not even be enough to allow it to switch on. It's not the cause of the problems she's seeing above.

#14 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 30 July 2012 - 06:15 AM

So as I understand, (the bottom line) when you want calculate with time very precisely, you need to use dateTime.Now.Ticks All the other methods results in capricious output.

#15 Gorf

Gorf

    Advanced Member

  • Members
  • PipPipPip
  • 96 posts

Posted 30 July 2012 - 07:15 AM

I had to look up capricious*, but yes. It would appear that the results are unreliable, but I'm sure they're not supposed to be. My only evidence for suggesting this is what you've posted in this thread: I've done no time-critical work yet. * The first hits that came up basically described my ex




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.