Shop OBEX P1 Docs P2 Docs Learn Events
Entering the EV world — Parallax Forums

Entering the EV world

First think I notice was driving past a gas station looking at the gas prices only to realize it doesn't matter.

I am used to pulling up to the gas pump and seeing how much gas and what it cost me. Now I plug it into an outlet at my house and have no idea what I just did. There is no pump fuel gauge or cost to tell me what just happened.

There are devices that can be installed in the power panel that will monitor everything that goes on in your house. Emporia is one of these devices.

I was thing of DIYing it with building a ferrite core and cutting it in half and monitoring with a hall effect sensor. This seems a little much and now looking at a different solution.


This takes some of the DIY out of the project and make a simple device that outputs 40ma per amp of power.

Now I need to build a program that converts the voltage into amps and displays it or maybe sends the data to my network for processing. I would need to monitor how many amps per hour are used to come up with a cost to charge an EV as we pay for power by the kilowatt hour.

I was thinking that a P2 could easily do this by using the analog feature of the pin with a resistor function added across as the circuit needs an added resistance to measure the voltage.

The only thing is how to measure time.

Comments

  • This is a simple current transformer? Ok, this is better than the linear hall effect sensor as it doesn't have offset and temperature drift problems. But you should also measure the voltage, say every milli second, and then multiply current times voltage to get power (kW) and then integrate that over time to get energy (kWh). This way you measure true RMS current. Only measuring (average) current will produce errors when there is reactive current, e.g. the power factor is not 1.0.

  • iseriesiseries Posts: 1,521

    The unit I am looking at is CTS-CS-CAX-10-050. This unit require 5 volts to power it and returns a voltage based on current flow. Not sure how this works.


    If the P2 is running at 200Mhz and I setup a loop to read every millisecond how much drift would there be in an hour?

  • ManAtWorkManAtWork Posts: 2,270
    edited 2026-01-13 11:37

    This sensor has an offset drift of +/-5mV. This sounds not too bad but means +/-0.5A. If you charge your EV say it's 16A @ 400V for 2 hours or 22kWh. But an offset error of 0.5A is 345W so during the rest of the day (22h) this could sum up to an error of 7.5kWh.

    Edit: never mind. The actual error is much lower if you do that true RMS calculation a DC error means a power draw for one half period but a feed-back for the other half.

  • iseriesiseries Posts: 1,521

    I setup a test program just using a potentiometer to see what the smart pin will read out.

    This is the test program:

    #include <stdio.h>
    #include <propeller.h>
    #include <smartpins.h>
    
    
    #define POWER 20
    
    int main(int argc, char** argv)
    {
        int i;
    
        printf("Starting\n");
    
        _pinstart(POWER, P_ADC | P_ADC_1X, 13, 0);
    
        while (1)
        {
            i = _rdpin(POWER);
            printf("Power: %d\n", i);
            _waitms(1000);
        }
    }
    

    This is a table of the results. The output reading jumps around so did not get a stable value to use.

    Will have to average the numbers somehow or maybe just divide by 10.

    Right now, the unit charges the car at 40 amp at 240 volts or about 9.6Kw per hour and can fully charge the car in under 10 hours.
    Based on the owner's manual they recommend only charging the unit to 80% to preserve the life of the batteries. Only charge to 100% on long trips.

  • iseriesiseries Posts: 1,521

    Never realized how complicated EV charging station are. While there are only two types of plugs, an AC plug and a DC plug the number of different cars is many.

    When you plug your car in the car talks to the charging station and negates what it wants. Some car run at 400 Volts while other can be up to 1,000 Volts.

    If the charging station only supplies 400 volts the car uses a buck convert to jump the voltage up to what it needs. It even uses one winding on the BLDC motor as part of the buck converter.

  • The P2 pin will add at least +- 1mV drift with the best code. Accurate DC measurement with the P2 pins is tricky.

    The sensor you linked looks fine. I believe it will give AC output with a 2.5V DC bias.

    Have a look at OpenEVSE. That unit uses a current transformer which is read by an ATmega328.
    https://github.com/OpenEVSE/OpenEVSE_PLUS/blob/master/OpenEVSE_PLUS_v5.5/OpenEVSE_PLUS_v5.5.pdf It works fairly well. I assume there is a high pass filter in the software to eliminate DC offset.

    There is a good chance that the AC current is reported over the CAN bus. Every vehicle is different.

    For timing you'll want to use a timer. The documentation has this example:

            GETCT   x               'get initial CT
            ADDCT1  x,#500          'make initial CT1 target
    
     .loop  WAITCT1                 'wait for CT to pass CT1 target
            ADDCT1  x,#500          'update CT1 target
            DRVNOT  #0              'toggle P0
            JMP     #.loop          'loop to the WAITCT1
    
    

    This can be done in high level languages too. The code here will run every 500 clock cycles regardless of how long the code inside takes. Using a delay function won't work because it won't compensate for the time it takes to run the actual program. Any crystal oscillator should have enough accuracy for this purpose. If you want to sample every 1mS (I would run faster, like 0.1mS) then the value would be 200000000/1000 = 200000 clock cycles.

    Or you could use the ADC smart pin for timing. If you set a sample period of 20000 then waiting for IN to go high will have the same effect.

  • evanhevanh Posts: 17,038

    @iseries said:
    ... If the charging station only supplies 400 volts the car uses a buck convert to jump the voltage up to what it needs.

    Now you're getting a taste as to why AC was chosen over DC in the early days of building out electricity distribution. Having just a plain ruggedly built transformer for handling this conversion eliminates so many points of failure.

  • My current plan right now is to read the sensor every second and sum those values into minutes where I will divide it by 60 to the average voltage.

    Convert that value to amps and add that value to hours. Then by multiplying that value by 240 to get watts per hour.

    I figure I will need three bucks, Seconds, Minutes, and Hours.

    Mike

Sign In or Register to comment.