collin80 / GEVCU

Generalized Electric Vehicle Control Unit
113 stars 56 forks source link

PWM outputs #96

Open collin80 opened 8 years ago

collin80 commented 8 years ago

GEVCU5 boards are capable of PWM on the outputs but there is currently no support for this functionality in software. It would be nice if it were possible to set up a PWM map on the GUI interface that allows the end user to calibrate the PWM output to how their gauge works.

jrickard commented 8 years ago

The PWM output has a problem I think. Maybe I'm wrong. Get me straightened out. With this low side switching isn't ON off and OFF is on and so forth? So no output is a solid 12v and as we increase the pulse width the PWM output would go DOWN instead of up. This is a little counterintuitive.

Jack Rickard

On Tue, Dec 15, 2015 at 8:44 PM, Collin Kidder notifications@github.com wrote:

GEVCU5 boards are capable of PWM on the outputs but there is currently no support for this functionality in software It would be nice if it were possible to set up a PWM map on the GUI interface that allows the end user to calibrate the PWM output to how their gauge works

— Reply to this email directly or view it on GitHub https://github.com/collin80/GEVCU/issues/96.

http://www.EVTV.me http://EVTV.me

Electric Vehicle Television - KickinGas - One Car at a Time.

collin80 commented 8 years ago

Yes, you are correct. The outputs are low side and switch ground so PWM is completely backward of what you would normally expect. High duty cycle corresponds to a lower average voltage and lower duty cycle raises the average voltage. So, for voltage sensitive gauges the whole thing is backward. For gauges that count pulses it can work as normal as you would still get the correct number of pulses, just with reverse polarity. I think that would still work OK.

A somewhat bigger issue is how irritating it is if you need a frequency controlled gauge. Controlling the frequency of the PWM outputs isn't a lot of fun. It's much simpler when you can just control the duty cycle.

neuweiler commented 7 years ago

In ArduinoDue branch SystemIO::handleTick() (around line 100) I use PWM to output the estimated SOC to a DOUT. It is reversed due to the MOSFET. Works pretty fine for my digital fuel gauge with a resistor and capacitor to smoothen out the PWM to an analog signal.

collin80 commented 7 years ago

Thanks for the heads up. Yes, I can see how you've implemented it. Using analogWrite works fine but as you know it's inverted and also does not support setting the frequency. Normally you don't need to change frequency but I had an application where I had to. I've still got that code in a private branch, perhaps I'll see what it would take to bring it into mainline.