Jump to content

1S Wattmeter


Recommended Posts

If you want to detect the minimum voltage, I would use something like this:

if ( Min_Volts == 0 )
{
Min_Volts = Volts ;
}
else
{
if (Volts < Min_Volts)
{
Min_Volts = Volts ;
}
}

When calculating the average, like this:
Volts = (Vtemp/(loops))

I would round the value by doing:
Volts = ((Vtemp+loops/2)/(loops))

A few general comments. Note that in programming, things are not necessarily right or wrong, just different!

A variable defined as an "int" may take both positive and negative values. If a variable doesn't have a meaningful negative value, then it is advantageous to declare it as an "unsigned int".

If you are setting a variable to a constant value, and never changing it, then it is often useful to declare it using a "#define".

In your code above, this could apply to "loopcount" and to "loops".

To help reading code when you go back to it after some time, it is useful to follow some "standardisation".

For example, I use:

#defines are in all capitals,
"Global" variables begin with an upper case letter.
"Local" variables begin with a lowercase letter.
I happen to dislike putting the "{" at the end of a line. I position them on a line by themselves, with the corresponding "}" on a line by itself, at the same level of indentation. With larger programs, it makes finding a missing brace much easier!

Mike

Link to comment
Share on other sites

Mike, many thanks for all the tips. I'm already doing my best to keep things tidy and manageable. I'll add all your suggested conventions as I see exactly how they'll help.

I'll try the min volts thing.

The value rounding you suggest, is that similar to the "adding half a bit to avoid rounding down" that I've been reading about?

i.e. (RawReading+0.5)*(1.1/1023). Which gives us a result half way up a sampling step, rather than at the bottom. (my laymans description).

Link to comment
Share on other sites

That's good Dennis.

I've put the much improved sketch here OLEDPwrMtr V0.3.ino

Clearly not the best way to share files. But it's all I have.
This one has the improved averaging, is much tidier and is saving Max/Mins whenever power is at a new max.

I'll still be trying other methods.

 

Edited By Chris Bott - Moderator on 24/05/2020 13:09:29

Link to comment
Share on other sites

Posted by Chris Bott - Moderator on 26/04/2020 12:31:55:

Hi FF, that's as expected. Then click the download button.

Ah, is that when you get the download error message?

Edited By Chris Bott - Moderator on 26/04/2020 12:32:40

Yes..after pressing the download button it asks 'direct download' or 'save to my dropbox' and as I don't have a dropbox I clicked on direct download and then got the error message.....but I have just tried it again and it works OK now...Problem solved.

Link to comment
Share on other sites


Chris, PCB now populated & appears to be working smiley
I had highish current readings with no load connected - until I realised that I needed to link the PCB sensor track alternative to R2, to the other R2 pad! I’ve only connected one track at present, but am wondering if I need both.

I will check out with load currents, voltage drop/calibration range tomorrow.

Note that there is an alternative unsigned integer definition which can be used - specifies a fixed variable bit length: use “uint8_t” for integers in range 0-255, or “uint16_t” for integers in range 0-65535. I have changed my sketch in this manner.

41ee7aa8-9a58-4651-aa1f-4e6dc819ede8.jpeg

e9889e35-d480-4286-bead-1bd4ae21af88.jpeg

Link to comment
Share on other sites

Looking good Peter.

It will be good to hear your opinion on the sensor tracks.

The multiplier in the sketch is for using both tracks in parallel.

Using both in parallel is good to keep the volts drop down, but there's a downside (because this was designed to be particularly simple).

The lower the volts drop, the lower the volts across the whole sensing range so we're only using a fraction of the 1.1V of the A/D converter range. Using a single track will give you twice as many A/D steps, i.e.greater resolution.

Link to comment
Share on other sites

Chris, If you used both tracks then it’s probably best for me to also go that way in order to minimise volts drop. From the multiplier value, it looked as if you expected a 5A load to give about 110mV drop, thus giving approx 50mA current resolution (1% of Full Scale).

I assume that is good enough for most purposes whilst keeping the volts drop down & avoiding the complexity of boosting the sense voltage.

Link to comment
Share on other sites

Hi Paul

That's interesting, how do they tell you that the LCD is out of stock? It appears to be available here

The .stl for the bezel is on that same Bitsbox page. That's what I'm using.

I'll post the other two parts later. I'm screwing all 3 together with M2.5 x 20mm screws. These work fine but can eventually strip the holes if they're screwed in and out many times.

I'm also using Header sockets to mate with the pins in the display. Those were from my spares, I'll have to find a sourse for them.

As for trimpots, Peter may be better paced to advise as it looks like he has some that fit that PCB.
I'm fairly sure these from RS will fit.

I guess a full parts list is in order now, I'll have a look at doing that.

The new PCB (just ordered) should take two sizes of trimpot and I've made provision for a couple of header sockets at the far end that connect to nothing. These will mate with a couple of pins inserted in the other end of the display and should keep the PCB physically secure.

Link to comment
Share on other sites

Chris,

No, they can only be adjusted from the top, so need to be mounted on the accessible side of the board. I had to swap mine to the other side after I realised the display would cover them.blush

By the way, initial tests indicate that I need to reduce the Amps trim offset from 0.9 in the sketch as my calibration is right at the minimum end. I think the centre point should be 0.85, so will try the software fix first as it avoids getting the soldering iron out. Probably due to track resistance tolerance.

Link to comment
Share on other sites

Interesting. I've been doing a bit of calibrating against a more reliable multimeter and I found the same.

I then cut a link so only one track was in use and adjusted the multiplier in the Amps line to 24. So maybe that would be better at 48 or 47 for use with both tracks.

I think that if a user is going to use this for models that all use currents in the region of 1A, then using a single track is better. WIth the knowledge that volts drop will be higher if they move up towards the 5A range.

But those needing full scale most of the time should use both tracks. It's an available choice, anyway.

What's your feeling on having the readng showing 2 decimal places when resolution is only around 50mA?

Link to comment
Share on other sites

Chris, I was confusing the volts offset number with the calculation for Amps, so Yes I will try my Amps multiplier at 47 or 48. The Volts adjustment only needed a small tweak, so didn’t notice how much range I had there, but the 0.9 to 1.2 times multiplier should be plenty.

I don’t have a problem with a 2 decimal place Amps display as I am aware of the real resolution limitation. You obviously need as much resolution as is available for the Watts calculation, but may be worth reducing to 1 decimal point display with 2 tracks in use. You would probably be ok with 2 places if only one track used, as the resolution then doubles.

Link to comment
Share on other sites

Chris, I’ve tried calibrating my current measurement @1A against my multimeter.

Initially, I changed the Amps multiplier to 48 but found that I couldn’t increase my display value enough. (If anything, there seems to be a dead area of adjustment at the bottom end of the trim pot).

I finally managed to get the display to read 1A by increasing the sketch minimum trim value from 0.9 to 1. Checking the volts drop at 1A gives me 19.2mV (200mV multimeter scale), so my parallel twin track sense resistance is approx 19mOhms.

Interestingly, it seems that the calibrated Amps display tends drifts away from multimeter reading at say 0.5A or 1.5A. Has anyone else noted this?

Link to comment
Share on other sites

Peter: Do they both drift the same way (both higher or both lower) or do they drift in opposite directions (one higher and one lower)?

A comment regarding using uint8_t (8-bit unsigned value) variables. The definition for C (and C++) is that these will be extended to an int (signed value) before they are used in any calculation.

A comment on the use of the copper tracks as the current sense resistor. Copper increases in resistance as the temperature rises. The change is around 2% for every 5 degree C change.

Mike

Link to comment
Share on other sites

Thanks Mike,

Ive put my Int variables back to the normal unsigned variety.

My current readings go down against the multimeter at 0.5A (reading 0.37A on wattmeter), 0.68A reading at 0.75A & up to 1.61A at 1.5A read on multimeter, 1.99A read at 1.8A on multimeter. Of course the multimeter may well be drifting as well, but tends to be close to current indicated on the load supply PSU. I am using fixed resistors (6.2 ohms nominal total & adjusting the supply voltage to vary current. Supply voltage is 3.64V at the 0.5A end & about 12V at the 1.8A end.

Link to comment
Share on other sites

I've put your readings into a spreadsheet and created a graph (x-y). The result is a very nice straight line, but that doesn't go through (0,0). It suggests the wattmeter will read 0.2A when no current is flowing. Do you see this?

The problem is, I think, the A2D is not guaranteed to return a value of 0, when the input voltage is 0. Typically (from the data sheet), it will return a value of 2 (reference voltage of 4V), but this may be higher, particularly if the input voltage doesn't actually reach 0 when no current is flowing and the reference voltage is 1.1V (as is used here).

Since each A2D count of 1 represents 50mA, an offset count of 4 will give 200mA. It looks like an offset calibration value is needed.

Mike

Link to comment
Share on other sites

I've just done these tests.

Quite disappointing but I think still suitable for our use. Especially around the 1 - 2.5A area where indoor models operate. Up at the higher end, the PCB tracks felt warm, so maybe we should limit the unit to, say, 3A?

Multimeter 1S Wattmtr
0.20 0.11
0.30 0.19
0.40 0.29
0.50 0.39
0.60 0.49
0.70 0.63
0.80 0.74
0.90 0.83
1.00 0.94
1.10 1.04
1.30 1.29
1.50 1.45
2.00 2.00
2.50 2.60
3.00 3.09
4.00 4.35
5.00 5.66

Link to comment
Share on other sites

Mike & Chris, it looks as if Chris’s results are similar to mine in that they are too low at the bottom & too high at the top, although calibrated at 2A rather than my 1A, but then that could’ve been where Chris calibrated his unit. Are you now using both tracks Chris, or does your 2A with 1 track equate to my 1A with 2 tracks?

Mike, my unit reads 0A with no load, no matter what the input voltage displayed. When you say that from the offset graphed line that my unit should read 200mA with no load. Presumably, that would be -200mA as it is reading low at the bottom end. The sketch has a line which prevents any negative readings, so the display will bottom out at 0, even if there is a current flowing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...