Hi
I am trying to measure DC current but it is unfiltered. The circuit is a zero crossing detection rectifier so it is pulsed DC. I can get it to read the smaller current but as the DC waveform gets wider as it switches more of the AC waveform the current reading goes backwards basically. The issue of course is the voltage once it reads to the max level it cant cope with more of the waveform being used. I will attach a couple of pictures to explain what I am trying to put into words. The question is how do I get a more accurate current reading at higher currentPlease excuse the rough hand drawing but you can see my dilema. The voltage will be roughly the same but the current can be 5 times as much due to more of the AC waveform being used at higher current. When it is using nice DC from the current shunt as like from a power supply it works fine but this is being very problematic. I am only a newbie with writing software and struggle but I can usually find something on the net and work it around to suit me and it works but there doesnt seem to be anything about this on the net at all.
If you are using a shunt resistor, simply sample the shunt voltage at a high sample rate, and average the values over one complete cycle of the waveform. This tutorial for measuring AC current using a current transformer should give you some ideas.
The default sample rate on the Arduino Uno is about 9615 samples per second, which is more than fast enough. That gives you 160 samples of a 60 Hz waveform, or 192 samples of a 50 Hz waveform.
I have done that but at 1000 samples per second and it is fine at say 5 amps of at 3.5V but when it gets to 12 amps at 7.6V then its no good it seems to fold back on itself. The pickup device is a ACS712 30amp version. I have a 5 amp version on the AC mains side and it works a treat using the Emon library and lists perfectly on the lcd but the DC current has been driving me nuts...the voltage works fine and is reasonably accurate. Because this a non filtered DC signal it shows the raw current waveform which realistically gets wider as the current goes up. I thought maybe some millis function to read the actual timing of the waveform then add say 10 together then average them but not sure how to do that properly yet..so need to investigate the programming for millis. I have eve tried to use the Emon library to use where the zero cross is detetced and only read the section of the waveform from one zero cross to the other similar to what Emon does but I still have this issue that as the current gets higher the resul shown appears to go down or fold back on itself
Attached is the DC end of the board..its a proto I made so its had a few bits and pieces changed so its a bit rough. So a clean pcb will show you the AC mains end and the DC end both are ACS712 devices I have all functions working except for the DC current. I struggle with software but can usually get things done the way I want it so long as its reasonably simple software, The complex stuff is well over my head. I am good with hardware but not software
Is the emon library designed for use with DC signals?
Post the code, using code tags as described in How to use this forum, and a circuit diagram showing all the external components.
I would not trust the solder connections on this board:
+1
Board looks like a bomb site, with shrapnel everywhere.
Should not be connected to mains power.
Leo..
Its a prototype so has been soldered and desoldered parts many a time..its one of 3 I have done it was the first I made. The soldering isnt a problem the code is. My question was how to read the "fullness" of the current waveform as the current gets greater
/*
Arduino Acs712 AC and DC Current Sensing
*/
#include <Wire.h>
#include <LCDi2cNHD.h>
#include <inttypes.h>
LCDi2cNHD lcd = LCDi2cNHD(4,20,0x50>>1,0);
uint8_t rows = 4;
uint8_t cols = 20;
double Voltage = 0;
double Current = 0;
double VoltageDc = 0;
double realVoltage = 0;
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
void setup(){
Serial.begin(9600);
lcd.init();
lcd.setCursor(0,0);
lcd.print("SEAFORD TRANSFORMERS");
lcd.setCursor(1,0);
lcd.print("Chlorinator Tester");
lcd.setCursor(2, 5);
lcd.print("AC and DC");
delay(500);
lcd.clear();
emon1.voltage(6, 160, 1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(1, 6); // Current: input pin, calibration.
}
void loop(){
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable
lcd.setCursor(0,0);
lcd.print("Vac =");
lcd.setCursor(0,6);
lcd.print(supplyVoltage);
lcd.setCursor(1,0);
lcd.print("Irms=");
lcd.setCursor(1,6);
lcd.print(Irms);
lcd.setCursor(2,0);
lcd.print("RPwr=");
lcd.setCursor(2,6);
lcd.print(realPower);
lcd.setCursor(3,0);
lcd.print("APwr=");
lcd.setCursor(3,6);
lcd.print(apparentPower);
//DC section of Monitor
for(int i = 0; i < 1000; i++) { // Voltage is Sensed 1000 Times for precision
Voltage = (Voltage + (.0048828 * analogRead(A3))); // (5 V / 1024 (Analog) = 0.0048828) which converter Measured analog input voltage to 5 V Range
delay(1);
}
Voltage = Voltage /1000;
Current = (Voltage -2.5)/ 0.066; // Sensed millivolt is converted to current
delay(10);
for(int i = 0; i < 1000; i++) { // Voltage is Sensed 1000 Times for precision
VoltageDc = (VoltageDc + (.0048828 * analogRead(A2))); // (5 V / 1024 (Analog) = 0.0048828) which converter Measured analog input voltage to 5 V Range
delay(1);
}
VoltageDc = VoltageDc /1000;
realVoltage = (VoltageDc -2.5) * 24;
lcd.setCursor(0,16);
lcd.print("DC");
lcd.setCursor(1,13);
lcd.print("I=");
lcd.setCursor(1,15);
lcd.print(Current);
lcd.setCursor(2,13);
lcd.print("V=");
lcd.setCursor(2,15);
lcd.print(realVoltage);
}
[code]
I hope this one makes you happier..as I said its just a prototype to get code and hardware tested then a different pcb will be layed out and made
Here is the schematic
As I said the hardware works fine and 3 of the 4 software functions work great I am just having trouble with the DC current accuracy
markkkk42:
I hope this one makes you happier..
Not really.
No Some shrapnel, but still bad soldering.
Mains power needs enough clearance to be safe.
Just look at the solder blobs on the ACS712 on the current side.
I hope that is for the low voltage part.
Also note that an ACS712 is not rated for 230/240 AC.
Leo..
All voltage and current monitoring is done low side...being low side its no an issue and those extra soldering pieces are on purpose they add heatsinking for the chip
Lets repeat this: The creepage and clearance on that PCB are inadequate for mains. Its a death-trap. Mains carries high voltage spikes well above the nominal voltage when there are thunderstorms of even a fridge thermostat switching. The ACS712 is not rated for mains. It is rated for the nominal voltage, but not for actual mains in the real world. And the package is too small for the clearance and creepage distances anyway.
If you work on that board you should use an isolation transformer (or a mains simulator) and assume it will explode without warning (wear eye-protection).
Well all this pontification is wonderful and typical or todays social media lifestyle. Its not what I came here for. I posted here to ask a question on programming to solve a programming question of how to measure the current reasonably accurately.
If you had actually looked there is a mains end and a DC end. The mains end is measured in the neutral NOT the active if you actually looked at the correct end. All creepage distances are in excess of what is required on the mains end of the board. The problem I am having is the DC end of the board which is monitored on the negative not the positive and that reaches a max of 8Vdc
This is a proto working unit for my use to develop the software so it is reasonably accurate only it is nothing like what will be eventually put in motion and it is not a public item it is a in house testing unit. As I have stated before the software for mains side is fine and the DC voltage side is fine its only a issue with the current
Now can we get to the actual crux of what I asked for or is this not a help forum only a a space for people to propose how knowledgeable they think they are.
markkkk42:
Well all this pontification is wonderful and typical or todays social media lifestyle. Its not what I came here for. I posted here to ask a question on programming to solve a programming question of how to measure the current reasonably accurately.
Nothing obviously wrong with the code. Probably the chopping is upsetting the sensor. Do study the data sheet. It may not be able to follow such waveforms properly.
The mains end is measured in the neutral NOT the active
For PCB (and usually circuit) design this is utterly irrelevant as they should be treated equal, if only because they are in fact equivalent.




