View Single Post
Old 09-26-2015, 08:44 PM   #2092 (permalink)
MPaulHolmes's Avatar
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832

Michael's Electric Beetle - '71 Volkswagen Superbeetle 500000
Thanks: 1,368
Thanked 1,132 Times in 746 Posts
It's so much fun reading all the new posts when all I did was go to costco and eat some pizza. haha. The controller on instructables doesn't have voltage monitoring, but it can control current precisely into the battery pack or from the battery pack.

Here's the piece of code that controls the current into the battery without knowledge of the pack voltage:
	batteryCurrentLong = __builtin_mulss(Ia,pdc1) + __builtin_mulss(Ib,pdc2) + __builtin_mulss(-Ia-Ib,pdc3);  // batteryCurrent is in [-4096*sqrt(3)/2, 4096*sqrt(3)/2] = [-3547, 3547].

if (batteryCurrentNormalized < -maxBatteryCurrentNormalizedRegen) { // maxRegenCurrent is negative.  Computed in "InitializeThrottleAndCurrentVariables()".
		// averageDuty = (pdc1+pdc2+pdc3)/3.  But division is slow.  So, do this instead:
		// averageDuty = 65536 * ((pdc1+pdc2+pdc3)/3) / 65536
		// averageDuty = 21845 * (pdc1+pdc2+pdc3) / 65536
		// averageDuty = (21845 * (pdc1+pdc2+pdc3)) >> 16
		averageDuty = __builtin_mulss(21845, pdc1+pdc2+pdc3) >> 16;	// avoiding divide by 3.  HAHA.  
		if (averageDuty > 0) {
			temp = -__builtin_divsd(maxBatteryCurrentNormalizedRegen,averageDuty); // This is the first try at IqRefRef.  Later, other values will be calculated based on throttle.  Keep the one closest to zero.
			if (IqRefRef < temp) {
				IqRefRef = temp;  // if it was more negative, then make it smaller in magnitude, 'cuz there's too much friggen current going into the batteries!!!
By the way, I've fixed a few bugs and sensorless is so close to being debugged and working! The code now is much more complete and fancy than the instructables code. well, I think it's gotten better. I'll upload it in just a couple days once it's in a useable place.

EDIT: Without voltage monitoring (which is super easy to include, and actually was included on the revision board that got stolen that was on my laptop, but I'm not angry at all. nope), I think the controller could precisely command constant current into the batteries, somehow using the motor windings for an inductor, but it wouldn't know when to stop, unless it was told somehow. I haven't seen the link you guys are talking about, but I know it could be done. I just feel it way down deep.
kits and boards

Last edited by MPaulHolmes; 09-26-2015 at 09:13 PM..
  Reply With Quote
The Following 3 Users Say Thank You to MPaulHolmes For This Useful Post:
danibjor (09-27-2015), e*clipse (09-27-2015), thingstodo (09-27-2015)