EcoModder Forum Paul & Sabrina's cheap DIY 144v motor controller

Register Now
 Remember

 04-05-2014, 06:05 AM #6401 (permalink) EcoModding Lurker   Join Date: Jul 2011 Location: INDONESIA Posts: 40 Thanks: 20 Thanked 6 Times in 6 Posts Order the new board of 1K Paul, I want to buy 2 pcs of 1k board... I will send money to your paypal...how much will be include shipping cost. Thank u, Kukuh Jakarta Last edited by KUSAW; 04-05-2014 at 06:07 AM.. Reason: Mistypo
 The Following User Says Thank You to KUSAW For This Useful Post: MPaulHolmes (04-05-2014)
 Today Popular topics Other popular topics in this forum... View the most popular topics in this subforum by views or by posts
Dreamer

Join Date: Nov 2013
Location: Australia
Posts: 350
Thanks: 95
Thanked 214 Times in 151 Posts
Quote:
 Originally Posted by MPaulHolmes I'm getting close to being done with a complete rewrite of the code. I'm pretty sure there's a bug in the original software for the pwm filter. It tries to take sort of a running average for pwm, but look at this: pwmAverage = (127*pwmAverage + 1*pwmNewValue)/128 Let's say, for instance, pwmAverage is 10, and pwmNewValue is 20. pwmAverage will never be able to creep toward 20. If the new value of pwm average is 10 < pwmAverage < 11, it will be truncated to 10, and won't ever get to 20.
Paul,

If the intention is to have a pwmNewValue of 20 move the pwmAverage towards 20 with each evaluation. Then the pwmAverage needs to be a floating point number or somehow be saved with about 3 decimal places of precision. If an integer is used then a pwmNewValue of 20 isn't high enough to step the average up to the next integer value.

Another approach would be to multiply the pwmAverage by 100 before storing it. Then dividing it by 100 whenever it is used.

pwmAverage = ((( 127 * (pwmAverage / 100)) + (1 * pwmNewValue)) / 128 ) * 100
pwmAverage = ((( 127 * (1000 / 100)) + (1 * 20)) / 128 ) * 100
pwmAverage = ((( 127 * (10)) + (1 * 20) / 128 ) * 100
pwmAverage = (( 1270 + 20) / 128 ) * 100
pwmAverage = (1290 / 128 ) * 100
pwmAverage = 10.078125 * 100
pwmAverage = 1007.8125
Stored as an integer we get 1007

Next evaluation with pwmNewValue = 20 we get
pwmAverage = ((( 127 * (pwmAverage / 100)) + (1 * pwmNewValue)) / 128 ) * 100
pwmAverage = ((( 127 * (1007 / 100)) + (1 * 20)) / 128 ) * 100
pwmAverage = ((( 127 * (10.07)) + (1 * 20) / 128 ) * 100
pwmAverage = (( 1,278.89 + 20) / 128 ) * 100
pwmAverage = (1,298.89 / 128 ) * 100
pwmAverage = 10.147578125 * 100
pwmAverage = 1014.7578125
Stored as an integer we get 1014

And so on and so on until we approach pwmAverage of 20 or pwmAverage stored value of 2000

If you didn't want to change the magnitude of the pwmAverage value (if it is used elsewhere) then you could use a second value to hold the more precise pwmAverage value.

 The Following User Says Thank You to Astro For This Useful Post: MPaulHolmes (04-05-2014)
 04-05-2014, 09:08 AM #6403 (permalink) PaulH     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,202 Times in 765 Posts Hi MisterSid! The revision 1.11b code is somewhere in the wiki. Here it is: Index of /firmware I used to have a Linux dual boot, since Fran had done that code in Linux, and had a fairly special build environment. That hard drive broke, and I haven't gone back to it. Now, I'm using AVR Studio, but it messes up the use of the bootloader. That's another reason I didn't mind switching to a dsPIC. Well, the dsPIC is also a motor controller micro, and it definitely shows. Everything I wanted it to do, it does very easily. __________________ kits and boards
 04-05-2014, 10:21 AM #6404 (permalink) PaulH     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,202 Times in 765 Posts The 3 ring capacitors have been shipped. They are in MS, whatever that is. haha. Minnesota? Manuscript? Mississippi? Multiple Sclerosis? Your tracking/waybill number is 361026370772321. Click on the "Track Shipment" link for tracking information. https://www.fedex.com/fedextrack/?tr...nguage=english __________________ kits and boards Last edited by MPaulHolmes; 04-05-2014 at 02:12 PM..
 The Following User Says Thank You to MPaulHolmes For This Useful Post: flores (04-05-2014)
PaulH

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,202 Times in 765 Posts
Quote:
 Originally Posted by Astro Paul, I am a karate expert!
LOL. I'm sorry, my wife and kids left for the store, and I'm working on the software, and thought it would be hilarious to make you say something you didn't say.

I thought of a perfect name for the controller too!!
The "Diarrhea"... Since it gives your car the runs.

There will also be a "diaper" mode, which prevents you from going all over the street. Other "controller making people" have labeled it a "valet" mode.
__________________
kits and boards

Last edited by MPaulHolmes; 04-05-2014 at 04:00 PM.. Reason: controllers don't label things. they are inanimate objects.

Dreamer

Join Date: Nov 2013
Location: Australia
Posts: 350
Thanks: 95
Thanked 214 Times in 151 Posts
Quote:
 Originally Posted by MPaulHolmes LOL. I'm sorry, my wife and kids left for the store, and I'm putting the finishing touches on my superman costume, and thought it would be hilarious to make you say something you didn't say.
It took me a moment to work out what was going on as i read the quoted text first. Actually scrolled back through the thread looking for where i had put a comment like that. Then i went back and finished reading the rest of the post and realised it was a trick. You got me.

I have nothing to do with Karate, my sister however did it for a few years which is the main reason why we are very careful not to make her angry. Sort of like living with the Hulk.

Did the suggestion for pwmAverage help or did i do my normal thing of misunderstanding the question.

 04-05-2014, 09:41 PM #6407 (permalink) EcoModding Lurker   Join Date: Mar 2014 Location: New Zeland Posts: 4 Thanks: 0 Thanked 2 Times in 2 Posts Cheers Paul. I will get myself up to speed with the rev2c avr code. Sorry, I just assumed your dsPIC port to might have diverged from the AVR implementation. The dsPIC33 looks like a big step up for all the reasons you have outlined and it has a decent motor control library as well.
 04-05-2014, 10:11 PM #6408 (permalink) PaulH     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,202 Times in 765 Posts Actually, it would be better to see the new dspic code. I'm not doing anything with the avr code. It has diverged quite a bit. Im mostly done, and the main area that seems needing of cleanup is the serial. Could I email it once done? Its already so different. Astro, yes that was a very helpful suggestion! I had resorted to a standard average, but I think your suggestion is better. __________________ kits and boards
 04-06-2014, 12:51 PM #6409 (permalink) PaulH     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,202 Times in 765 Posts Here's the modified throttleAverage code, as a sample. Thanks for the suggestion, Astro! I'm making the same change to pwmAverage and temperatureAverage. Totally unreadable, but pretty fast. haha: Code: throttleAverageTimes1024 // = (31*throttleAverageTimes1024)/1024 + 1*ADThrottle) / 32 * 1024; // = 32*(throttleAverageTimes1024/1024) - 1*(throttleAverageTimes1024/1024) + 1*ADThrottle) / 32 * 1024; = ((throttleAverageTimes1024 >> 5) - (throttleAverageTimes1024 >> 10) + (long)ADThrottle) << 5; __________________ kits and boards
 The Following User Says Thank You to MPaulHolmes For This Useful Post: Astro (04-06-2014)
Dreamer

Join Date: Nov 2013
Location: Australia
Posts: 350
Thanks: 95
Thanked 214 Times in 151 Posts
Quote:
 Originally Posted by MPaulHolmes Here's the modified throttleAverage code, as a sample. Thanks for the suggestion, Astro! I'm making the same change to pwmAverage and temperatureAverage. Totally unreadable, but pretty fast. haha: Code: throttleAverageTimes1024 // = (31*throttleAverageTimes1024)/1024 + 1*ADThrottle) / 32 * 1024; // = 32*(throttleAverageTimes1024/1024) - 1*(throttleAverageTimes1024/1024) + 1*ADThrottle) / 32 * 1024; = ((throttleAverageTimes1024 >> 5) - (throttleAverageTimes1024 >> 10) + (long)ADThrottle) << 5;
I had to look up a wiki to find out what >> did in C programming language.
(One day i will have to learn C.)
A bitwise shift. Very neat.
Sometimes readability needs to take a back seat to performance. After all that's what comments are for.

 The Following User Says Thank You to Astro For This Useful Post: MPaulHolmes (04-06-2014)