watt hours measurement.

General topics and discussions about the VESC and its development.
rew
Posts: 904
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

watt hours measurement.

Postby rew » 23 Jul 2017, 10:24

I may have bragged a bit about how little energy I used on my bike..... Confession time: I have now determined that the measurement in my display is about 2 times too low.

"manual" measurements showed that at say 125W it would take about 16 seconds for the kJ variable to roll over to the next value, while you'd expect 8s. I now borrowed an eagle-tree logger and we measured about the same difference. My test ride used 60kJ according to the logger, and showed 29kJ in the display.

My display gets the kJ value by calling mc_interface_get_watt_hours:

Code: Select all

float mc_interface_get_watt_hours(bool reset) {
        float val = m_watt_seconds / 3600;

        if (reset) {
                m_amp_seconds = 0.0;
        }

        return val;
}

My first reaction is that m_amp_seconds in the middle should probably be watt_seconds. Right? All this doesn't matter, as long as we do not try to reset it, which nobody does.

Anyway, for kJ I print: (double) 3.6*(double) mc_interface_get_watt_hours(0), or effectively watt_seconds/1000, where a Watt-second is a Joule, so everything checks out so far.

Now... why would this counter be wrong?
The counter is kept in mc_interface_mc_timer_isr, and seems to assume that it is called f_sw (switching frequency) times per second. Could it be that this only runs at half this speed?

tecnologic
Posts: 15
Joined: 26 Feb 2016, 08:23
Location: GER / Hamburg

Re: watt hours measurement.

Postby tecnologic » 23 Jul 2017, 14:55

rew wrote:Now... why would this counter be wrong?
The counter is kept in mc_interface_mc_timer_isr, and seems to assume that it is called f_sw (switching frequency) times per second. Could it be that this only runs at half this speed?


Hi rew,

seems to be the key. The function builds an integral which is only right, if its called at the intended frequency.

regards

Tec

rew
Posts: 904
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: watt hours measurement.

Postby rew » 24 Jul 2017, 06:03

I think I found a HINT: mc_interface_mc_timer_isr is called from mcpwm_foc_adc_inj_int_handler which starts with:

Code: Select all

const float dt = 1.0 / (m_conf->foc_f_sw / 2.0);
Possibly this only happens in FOC mode and not in BLDC mode?

So from mcpwm_foc_adc_inj_int_handler we should call mc_interface_mc_timer_isr(2); while mcpwm.c calls mc_interface_mc_timer_isr(1);
and

Code: Select all

const float f_sw = mc_interface_get_switching_frequency_now();
should be changed into:

Code: Select all

const float f_sw = mc_interface_get_switching_frequency_now() / dt;

(where I called the new parameter "dt").

rew
Posts: 904
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: watt hours measurement.

Postby rew » 24 Jul 2017, 09:45

OK. Confirmed!

I instrumented mc_interface_mc_timer_isr to count how many times it was called. When that number exeeded the value returned as the switching frequency I measure the time between "now" and last time that happened.

In BLDC mode, I get 1.000 seconds, and in FOC mode I get 2.000 seconds.

So... I would write a patch and submit it, but I hate working on code that is going to be replaced anyway. Benjamin hasn't published his current code for a while. Oh wel.... Patch attached....

Sigh. The forum won't allow me to add .patch files. Nor .txt . The patch is now attached as a broken jpg. Download, change name, etc. Sigh. Here is a link. http://prive.bitwizard.nl/mah_wh.patch


Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests