I need some input to solve an issue with my EV conversion

Basic proportional ‘P’ control system. Could also implement a derivative ‘D’ component, it would converge better (PD).

Alan KM6VV

Hi Andre,

Except for the reverse voltage thing… you really did great! No, not on purpose. It was an honest mistake, so you really did a good job! And you are right on the money as to how to control the gear selection. Can you rotate the motor/pot continuously? I’m working on your next test program. There is little hope of repairing a board that had the voltage reversed.

Hi guys, thanks for getting back to me. Alan, I looked up Proportional controls, and that helped me in understanding what is going to be happening when the shift selector gear is approaching a new setpoint(gear position). I believe the problem with overshooting the setpoint will be minimal because each gear position on selector gear has a Dimple that a ball with a heavy duty spring behind it drops into(a ball detent). You can see the dimples in the pictures I previously posted. This is the exact position for each gear and that is where the pot positions were taken. So once the spring forces the ball into the detent dimple it should go right to the new setpoint.
Jim, I did not try the controller on the actual shifter motor. I made a test setup to play around with, using a 10K pot to control the motor speed and direction. I had planned to try it on the real motor but fried the controller showing my son how it worked on the test bench the night before.


I have been going thru the reference manual, and I’m thinking that you will probably be using the
IF, THEN, and <, > commands in the next code. It’s very late so I will do more research tomorrow
I have to share with you that since starting my change over to Renewable Energy 2 years ago I finally today received a bill from the Electric Co. for 0.00 This is a big milestone for me, and is way beyond what I had expected to be able to do in terms of using green energy without changing my lifestyle. This EV conversion is my next phase in my “Go Green” plan.
Thanks for your helping me to go greener.

Good morning, I have spent many hours going thru the reference manual for Basic Micro Studio, and I am sure you realize that being new to this I am probably more confused instead of being more enlightened. This is mostly because the examples in the reference manual are very vague with the exception of the Adin command that was actually quite to the point, and that’s why I got the code example Jim gave to work, The only part I will take credit for is that I took the time to read up on all the stuff that Jim put in the example code, and that I noticed the discrepancies. without the example code I would still be scratching my head. that being said I followed up on Jim’s comments that I was looking inthe right direction, and I came up with the line of thinking below. Again this is me thinking out loud, but hopefully at least in the right direction.

Gear_change.bas
cur_pos var word ‘<- sets up the variable for storing the current pot value.
new_pos var word ‘<- Bear with me, I am going this route because I do not know yet how I will be inputting the positions for each gear change yet, so I am pretending I have a input voltage that represents a new gear position value
loop’
adin 0, cur_pos ‘<- the variable cur_pos now holds the numeric value of the current pot(gear) position.
adin 1, new_pos ‘<- the variable new_pos now holds the numeric value of the new gear position.
If cur_pos – new_pos < 0 then
xxxxxxxxxxxxxx’< code that would rotate motor CW towards new gear position If cur_pos – new_pos < 0 if this is false then it would go to next line. (So far I have no thoughts yet on this code. )
If cur_pos – new_pos > 0 then’
xxxxxxxxxxxx ‘< code that would rotate motor CCW towards new gear position If cur_pos – new_pos > 0 if this is false then it would go to next line.
If cur_pos – new_pos = 0 then ‘
End or stop’< if above also false it would go to next line. If true I have shifted to a new gear position and it’s done until I decide to change gears again.
Goto loop’

Actually, after looking at it again it does not seem right, but it’s late, and I am not thinking straight any more. Please give me some input to work with, and have a wonderful day.

I never got an answer, can the pot rotate continuously? Normally they do not. This will complicate things a bit as I think the real pot on the motor can, but your test rig can not. I will throw something together for you to try today.

Is the motor controller replaced yet?

Ok now we will put the code that reads the position in a subroutine. This code should run same as before.

[code]var pot_position word '<- sets up the variable for storing the pot value.
loop: '<- label, you can “goto” here.
gosub get_pot_position
goto loop

get_pot_position:
adin 0, pot_position '<- the variable pot_position now holds the numeric value of the pots position.
serout s_out,i9600,“Analog input reading:”,dec pot_position,13] '<- this sends the value to the PC so you can see it.
pause 100 '<- a small 0.1 second pause, no need to go full speed here.
return '<- this takes you back to the position right after the gosub.[/code]

Now we will implement inputs. We will use the three buttons on the BB2, A, B and C, to shift into three gears. The motor controller will connect to IO 4 on the Bot Board II. The motor controller should be put into RC mode. 1500uS will stop the motor. Sending larger pulses will start rotation in one direction and shorter pulses will rotate the opposite direction. The farther from 1500 the faster the motor will run. The range should be 1000uS to 2000uS. The code for generating these pulses is handled in 0.5uS steps. So to make 1500uS you send a value of 3000. You may need to reverse the wires on the motor if it rotates the wrong direction. I have not tested this but it should be close. There is no PID or anything fancy, just some brute force code to get started. I’m not a great programmer. Anyone else want to assist here?

[code] pot_position var word '<- sets up the variable for storing the pot value.
gear_A con 973 'reverse
gear_B con 817 '1st gear
gear_C con 697 '2nd gear
buttonA var nib '<- nibble variable holds 0-1.
buttonB var nib
buttonC var nib
prevA var nib
prevB var nib
prevC var nib
deadband con 15 '<- we want this as low as will reliably operate.

loop:
buttonA = in12
buttonB = in13
buttonC = in14
  if (buttonA = 0) AND (prevA = 1) then
     gosub select_gearA
  endif
  if (buttonB = 0) AND (prevB = 1) then
     gosub select_gearB
  endif
  if (buttonC = 0) AND (prevC = 1) then
     gosub select_gearC
  endif

prevA = buttonA
prevB = buttonB
prevC = buttonC
goto loop

select_gearA:
gosub get_pot_position
  if (pot_position < (gear_A + deadband)) AND (pot_position > (gear_A - deadband)) then
   pulsout 4, 3000 '<- stop the motor if running
  return
  endif
  if pot_position > (gear_A + deadband) then
   pulsout 4, 2600 '<- 1300uS (change this to move faster or slower)
  goto select_gearA
  endif
  if pot_position > (gear_A - deadband) then
   pulsout 2, 3400
  goto select_gearA
  endif

select_gearB:
gosub get_pot_position
  if (pot_position < (gear_B + deadband)) AND (pot_position > (gear_B - deadband)) then
   pulsout 4, 3000 '<- stop the motor if running
  return
  endif
  if pot_position > (gear_B + deadband) then
   pulsout 4, 2600 '<- 1300uS (change this to move faster or slower)
  goto select_gearB
  endif
  if pot_position > (gear_B - deadband) then
   pulsout 2, 3400
  goto select_gearB
  endif

select_gearC:
gosub get_pot_position
  if (pot_position < (gear_C + deadband)) AND (pot_position > (gear_C - deadband)) then
   pulsout 4, 3000 '<- stop the motor if running
  return
  endif
  if pot_position > (gear_C + deadband) then 
   pulsout 4, 2600 '<- 1300uS (change this to move faster or slower)
  goto select_gearC
  endif
  if pot_position > (gear_C - deadband) then
   pulsout 2, 3400
  goto select_gearC
  endif

get_pot_position:
adin 0, pot_position
serout s_out,i9600,"Analog input reading:",dec pot_position,13]
pause 100
return  [/code]

Wow Jim, you sent me a lot of stuff. Thank you. I will take my time and go over it.
I just wanted to quickly answer the question about the pot. The pot on the test rig is the actual pot from the gearbox. It can in fact rotate continuously, but installed on the gearbox it never would be able to. It’s actual range of travel is 350 degrees. again thank you. I am going to be up late tonight.
Andre

Hi all , OK, I have read thru the codes that Jim wrote for me, and I can pretty much follow the logic of it. Thank you Jim. And please, as Jim stated earlier, any other ideas or comments will be greatly appreciated. The replacement Syren-10 motor controller has not arrived yet, so I can’t do any actual testing yet. It does give me the chance to go over Jim’ s code and ask questions, because I want to know how and why things work, and just telling me to do it this way does not work for me.
Hopefully I won’t ask any really stupid questions, and if I do please bear with me. My experience has taught me that stupid questions are exponentially less expensive than stupid mistakes.
So, first question, looking back at my mistake with the reverse polarity that fried my first SyRen motor controller. is there any reason why I cannot install a 10Amp blocking diode in the wires to the battery? and of course why?
Next, the motor controller will have to be powered from the 12 Volt system of the car. the BB2 can only accept a max of 9 V. I remember reading that BB2 needs at least 5.5V at the Vlogic input to be able to output 5V+ to the pot for instance. does this mean that I will need a separate regulated power supply of maybe 7.5V for the BB2 or can I use the +5V out from the SyRen to power both the BB2 Vlogic input and the 0V/+5V to the gearbox pot and have the pot center tab go to P0 input on the BB2, all of this of course with all the grounds being common. Ok, so it’s very late again, but I have searched all over for references to the Prev expression in the code, and nothing. I am guessing that it has something to do with these buttons being momentary on buttons, so something like if within a certain time frame there is both a 0 and a 1 input then it means the button was pushed. I am also assuming that you used the 3 buttons on the BB2 simply because they are already there and this is only testing and that we will use external momentary switches connected to the BB2 inputs for the real deal. What really gets me is that 40 years ago in college I went with Civil Engineering instead of Electrical Engineering because of the Calculus requirements for the EE degree. I could not comprehend calculus at all. Looking back, I never did a day’s work as a Civil Engineer in my life, but have been involved with electrically powered equipment and their maintenance ever since I graduated from College. Go figure. I will be back later.

The diode drops a fairly good amount of voltage which can cause problems. Reverse protection diodes are fine for devices that are connected and reconnected over and over, but for something like this, just check it, recheck it, then check it again, then apply power.

We are conservative with the specs. As long as you are not drawing a lot of current from the 5vdc regulator you should be able to use the 12vdc directly to VL. It is best to use the 5vdc from the Bot Board II because it is the supply for the processor. One potential problem with using analog to digital converters is you must insure the voltage never goes negative, but also the voltage never goes above the processors supply voltage. Using the Bot Board II’s regulator for the pot prevents these issues from happening.

The prev, is simply a variable, it’s not a command. When a switch is pressed it does bounce, which can cause a program to detect multiple 1’s and 0’s true. This code is really just making sure the desired action only happens once per button press.

The three buttons were used out of convenience. You can add as many inputs as you have available IO.

I have an EE degree which explains why there is so much mechanical engineering in my position. lol

The code I threw together should move between the desired gears without rotating a full 360.

Good morning, thank you for the very explicit responses to my questions and comments, after my costly mistake I want to avoid a repeat incident. So in regards to connecting 12 Volts to the BB2 I want to give accurate details as to the actual Voltage the BB2 would see when connected to the cars 12 volt system. The car will have a 96 volt nominal lead acid battery pack. To accommodate the normal electrical system, Lights , radio, etc. I will have a CleanPower 96V DC-DC converter installed that basically takes the 96V from the battery pack and reduces it to supply power to the normal 12V system of the car. this eliminates the need for a separate 12V battery that would have to be recharged separately from the HV pack. Here is the link for it. thunderstruck-ev.com/cleanp … dc-dc.html , and the specs below so you can see them right away.
**IpDCIS-9612 Specifications:
Input Voltage: 80V~130V
Output Voltage: 13.8V@30A(Can be used to charge battery)
Max Output Current: 32A @11V(typical)
Maximum Efficiency: ≥ 90%
Environmental Enclosure: IP68
Shock and Vibration: SAEJ1378
Safety-North America: UL2202/UL1564 2ND Edition
Emissions- North America: FCC Part 15/ICES 003 Class A
Immunity-Europe: EN61000-4-2/3/5/6/11
Operating Temperature: -20 celsius degree~50 celsius degree(-22-122) **
Would the 13.8V still be safe? Right now for testing that is not an issue, but in case it is an issue when the BB2 gets installed in the car then I want to have a solution in place for when the time comes. I also realized after going over your code that I gave a pot position for Reverse, when in fact it no longer exists in the gearbox. At this point it is really of no consequence on the test rig.
With a bit of luck I might have the new controller on Friday afternoon. BTW, I like you Beer Bot, Maybe after the EV project I will build me a Rum Bot. It will have to be a heavy duty version to be able to handle the daily Aruba happy hours. (1/2 gallon bottle capacity.) Finally I will be able to put my engineering degree to good use. LOL. Life is good, I just wish there were 30 hrs in each day. I could use the extra 6 hrs to get some sleep, but I would probably just find more things to do.
have a wonderful day!!

Yes I am aware of the 12vdc spec as meaning up to 13.8vdc. The regulator on the Bot Board II would need to provide about 30mA without anything extra, LED’s or other devices powered by the 5vdc. So 13.8 - 5 = 8.8vdc dropped across the regulator. 8.8 x .03 = .264 watts. I went ahead and powered one up with 13.8 and the regulator is warmed slightly. Should not be an issue. But if you start adding things to the 5vdc line the heat could be an issue.

Hi Jim, Thank you again for your clarification. I have no doubts at all in your expertise regarding my concern with the 13.8V question. In fact, I ask you these questions because you are the expert and I am totally new to this, and my concerns were based on limits mentioned in the product hardware information pdf, and of course my mistake with the motor controller wire connection. The literature was very explicit in warning about this, so I had no reason to doubt the 9V limit for the BB2.
I really appreciate you’re time and effort in helping me, so please do not reply to this post. I just feel the need to justify my questions. My question about PREV was because you also used BUTTON as a variable. I remembered seeing the Button command and looked it up and it had to do with what you explained about the bouncing. instead of realizing you had used it as a variable name and that it was not a command, I assumed it was a command and then figured PREV was also a command that I could find no reference to. Hence the question. I apologize for taking up your time, with this post, but if you ever come to Aruba I will make it up to you. My shipper said i would get the new controller Friday afternoon. I hope so, otherwise it is going to be a very long weekend,
have a wonderfull day.

OK, Back again. I did get the new Syren Friday PM, and this time I set everything up nicely with plugs, inline fuse, and on/off switches to avoid mistakes. I loaded the code you sent me Jim, no errors, but nothing happened. So, I started analyzing and making changes. Well Jim , now I’m convinced you are testing the new guy to see if he can solve problems or just wants the answer on a silver plate. Well, I enjoy the challenges of problems like this. It’s so much more satisfying to have been part of the solution. The reason I say you involved me in the process is that there were some obvious bugs in the code that would stand out by just reading thru the code. I’m referring to you specifying pin 2 in the pulsout of the third IF…THEN on each of the select gear sub routines instead of pin 4. Unfortunately it did not work after correcting this. It did get me going on my quest to get this code to work. so after working on this till 4:30 AM on both Friday and Saturday night, I realized that I got it to work, and went to bed. I fine tuned a bit today, and I actually have a working solution. It’s right on the money.
Thank you so much Jim. All joking about you testing me aside, the codes you sent me were exactly what I needed, and after working out the bugs I now have a much better understanding of how the code works. Here is the code that works as of today. I know there will be more changes.

[code]pot_position var word '<- sets up the variable for storing the pot value.
time var word
gear_A con 961 '6th gear
gear_B con 803 '5th gear
gear_C con 682 '4th gear
buttonA var nib '<- nibble variable holds 0-1.
buttonB var nib
buttonC var nib
prevA var nib
prevB var nib
prevC var nib
deadband con 5 '<- we want this as low as will reliably operate.
gain con 4

loop:
buttonA = in12
buttonB = in13
buttonC = in14
  if (buttonA = 0) AND (prevA = 1) then
     gosub select_gearA
  endif
  if (buttonB = 0) AND (prevB = 1) then
     gosub select_gearB
  endif
  if (buttonC = 0) AND (prevC = 1) then
     gosub select_gearC
  endif

prevA = buttonA
prevB = buttonB
prevC = buttonC
goto loop

select_gearA:
   low 4   
gosub get_pot_position
time=2870 + gain*(pot_position - gear_A)
  if (pot_position < (gear_A + deadband)) AND (pot_position > (gear_A - deadband)) then
   pulsout 4, 2870 '<- stop the motor if running      
  endif      
  if pot_position > (gear_A + deadband) then
   pulsout 4, time 
  endif            
  if pot_position < (gear_A - deadband) then
   pulsout 4, time
  endif       
  goto select_gearA

select_gearB:
   low 4
gosub get_pot_position
time=2870 + gain*(pot_position - gear_B)
  if (pot_position < (gear_B + deadband)) AND (pot_position > (gear_B - deadband)) then
   pulsout 4, 2870 '<- stop the motor if running      
  endif      
  if pot_position > (gear_B + deadband) then
   pulsout 4, time 
  endif            
  if pot_position < (gear_B - deadband) then
   pulsout 4, time
  endif 
  goto select_gearB
  

select_gearC:
   low 4
gosub get_pot_position
time=2870 + gain*(pot_position - gear_C)
  if (pot_position < (gear_C + deadband)) AND (pot_position > (gear_C - deadband)) then
   pulsout 4, 2870 '<- stop the motor if running      
  endif            
  if pot_position > (gear_C + deadband) then
   pulsout 4, time
  endif            
  if pot_position < (gear_C - deadband) then
   pulsout 4, time
  endif 
  goto select_gearC

get_pot_position:
adin 0, pot_position
serout s_out,i9600,"Analog input reading:",dec pot_position,13]    
return  

[/code]

The way it is now there are only 2 slight problems.
first one is that I have to reset before i can select a different gear position. I guess once it’s stopped at a position it keeps running the loop. This is actually good, because it causes the motor to counteract any movement that could possibly cause the gearbox to pop out of gear.
the second one is a problem that i have to correct. the way I have the proportional control set up, once the new gear position is further away the base time + proportional time exceed 4000, and the motor either stops or drops to a very slow speed until it’s close enough to drop below either 4000 or above 2000. I’m not sure how I am going to adjust that yet. the final hurdle I solved that had me all confused was when at 4:00 AM I figured out that for whatever reason the pulse value that stopped the motor in my case was 2870 and not 3000. After I figured that out I got it working perfectly for the 3 gear positions on the gearbox itself. It’s late again. Thanks for the guidance, I appreciate it very much. BTW, We are just getting started. LOL.

Great report! I am not testing you. :wink: I made sure it would compile, but I didn’t have a full set up so I couldn’t really test it.

The Atom processor uses a highly accurate crystal to base it’s clock timing on. The motor controller uses a less accurate ceramic resonator as the clock. So it’s stop pulse length will always be off by a little. You did exactly right in adjusting it to stop the motor. Sorry for not thinking about it before.

We need video!!! :slight_smile:

Happy Birthday Andre! You are older than me, and I’m older than trees… lol :smiley:

hello again, and thank you for the birthday wishes. Just wanted to update. I been very busy, and with the knowledge that I will be able to change gears in my EV, will take afew days to catch up on some other stuff. I will get some video. Jim, I don’t know if you have decals for Lynxmotion, but if you do I would like to get 2 to put on the car when it’s finished. I’ll be back.

Hi forum members, I am back after a long absence mostly due to having to much stuff to do, and also because I basically had a working solution to my initial reason for joining the forum at my last posting.
At that time it worked in a bench test situation. before I continue, I want to express my gratitude for all the input I received, but I especially want to thank Jim for not only supplying me with the hardware I needed, but also for helping me with a sample code that was the basis for me working out a code that in bench testing worked perfectly. Jim, I am sure you are reading this, so thank you. I also just read all about the change of ownership, and why you had to make that decision. I don’t know the exact details, but from what I read you made the right choice. I remember you saying I was older than you, and I know how our bodies capabilities no longer are up to what we think they should do, so several years ago I also decided that it was time for me to put myself and my family before work etc.
I had planned on doing some traveling, but my life is now totally occupied by all the projects I have come up with. At least I am doing what I want to, and not busting my butt to keep others happy.
enough said. Enjoy doing whatever you will be doing, but I am pretty sure that will include this forum.
Ok, I am sure you all realize I am back for a reason. Let me update. Over the past months I have put everything together in my EV conversion project, and my last hurdle was deciding on my battery pack. I really wanted Li-Fe-Po,($$$$$), and lead acid was payable but at such a weight penalty that I could not make my mind up. Remember also that lead acid is not cheap here in Aruba.
About 10 days ago I was telling the local FORD dealer about my RV conversion project, and he graciously offered to donate 8 MOTORCRAFT Deep Cycle Marine Batteries to me so I could complete my project. I was blown away, especially since my project car was not a FORD, but the next day I had my brand new batteries, and day before yesterday I actually drove my Smart ForTwo EV conversion around the neighborhood at 3 AM for the first time. It’s actually really awesome. Crazy acceleration even with the heavy batteries, and almost no sound. You hear all the rattles and noises the car makes going over bumps in the road. More stuff to fix. Right now I have no idea which gear the car is in, but I think it’s in 2nd gear. I have not yet hooked up the shifter module I made with this forums input, and here is why. I had a total hard drive meltdown on my laptop after an insane thunderstorm passed by. And yes, I had not backed up in a long time. So here is my dilemma. The only working version of my shifter code is in my AtomPro28 microprocessor, and there is also the last code that is posted on this thread that is unfortunately nowhere near my final working version. before I do anything I want to ask if it’s possible to retrieve the code that is currently loaded on the AtomPro28 microprocessor. I looked through the manual but have not found anything yet. Any input will be greatly appreciated. please tell me it’s possible.
thank you
Andre Loonstra