12-30-2016, 12:53 PM
|
#2951 (permalink)
|
EcoModding Lurker
Join Date: Dec 2016
Location: northern sweden
Posts: 33
Thanks: 17
Thanked 20 Times in 17 Posts
|
...also, i guess i need to invert the throttle value somewhere in the code to control the reversing. I havenīt figured it out yet.
Maybe not the throttle, maybe the IqRefRef or some other refref.
reff reff, voff voff, bark bark... Paul, throw me a bone haha
|
|
|
The Following User Says Thank You to motorulf For This Useful Post:
|
|
Today
|
|
|
Other popular topics in this forum...
|
|
|
12-30-2016, 02:07 PM
|
#2952 (permalink)
|
EcoModding Lurker
Join Date: Jul 2011
Location: Slovenia
Posts: 70
Thanks: 0
Thanked 20 Times in 13 Posts
|
Quote:
Originally Posted by motorulf
I see there is an unused input on the dsPIC, as i understand the code it was planned for use as a regen throttle input but i was never used because the PIC cannot read both this and the neighboring temperature input, at least not if both are analog inputs.
So i am thinking, that pin could be used as a digital input for controlling reversing, a feature i really wish to have
}[/CODE]
|
I also need to have reverse option. I will not use transmission, only leaf gearbox. So i want to use one pin on dsPIC to signal reversing by applying +5V to it. I see a way to force software to accept encoder signals in reverse. That would be the easiest way. BUT for that to happen we have to condition some failsafes.
1. Two concious motions have to happen for reverse, hence switch with safety... just llike jettison or bombs away switch.
Pilot Chrome Anodized Safety Cover Aircraft Toggle Switch Red Indicator Light | eBay
2. Motor does not move when reverse is activated
3. Torque available is reduced to cca 1/3 (maybe would be good to set this in config)
Paul agreed to come from the dark side (talking about wig-wag boat throttle and no reverse) to the light and i think has started on this already .
|
|
|
12-31-2016, 02:31 PM
|
#2953 (permalink)
|
EcoModding Lurker
Join Date: Dec 2016
Location: northern sweden
Posts: 33
Thanks: 17
Thanked 20 Times in 17 Posts
|
Ok, now i have been hacking away at Pauls code some more.
Now actually think this would work.
As the code is now, it uses maximum regen as maximum reverse. Not very elegant, i know, this will be a separate variable in the future. I thought it would be enough to test it out anyway.
Test it at your own risk, be shure that you understand what this will do before trying it. I havent tested this myself yet, there are probably some errors, both in my thinking and my code... you have been warned.
I marked the code with *'s where i have been touching it.
Code:
// Is there a throttle fault?
if (throttle <= savedValues.throttleFaultPosition) {
faultBits |= THROTTLE_FAULT;
}
if (savedValues2.throttleType == 1) {
throttle = 1023 - throttle; // invert it.
}
// I think I'll work my way left to right. ThrottleFaultVoltage < ThrottleMaxRegen < ThrottleMinRegen < ThrottleMin < ThrottleMax
if (throttle < savedValues.maxRegenPosition) { //First clamp it below.
throttle = savedValues.maxRegenPosition;
}
else if (throttle > savedValues.maxThrottlePosition) { // And clamp it above!
throttle = savedValues.maxThrottlePosition;
}
if (throttle < savedValues.minRegenPosition) { // It's in regen territory. Map it from [savedValues.maxThrottleRegen, savedValues.minThrottleRegen) to [-maxMotorCurrentNormalizedRegen, 0)
throttle -= savedValues.minRegenPosition; // now it's in the range [maxThrottleRegen - minThrottleRegen, 0)
// Do this if we are reversing *******************************
if (reversing = 1){ //Dont invert it, as regen.brake now will mean a forward rotating force *******************************
throttle = __builtin_divsd(((long)throttle) * maxMotorCurrentNormalizedRegen, savedValues.maxRegenPosition - savedValues.minRegenPosition); //*******************************
}
else{ //Do what you did before *******************************
throttle = -__builtin_divsd(((long)throttle) * maxMotorCurrentNormalizedRegen, savedValues.maxRegenPosition - savedValues.minRegenPosition); //*******************************
}
}
else if (throttle <= savedValues.minThrottlePosition) { // in the dead zone!
throttle = 0;
}
else { // <= throttle max is the only other option! Map the throttle from (savedValues.minThrottlePosition, savedValues.maxThrottlePosition] to (0,maxMotorCurrentNormalized]
throttle -= savedValues.minThrottlePosition;
if (reversing = 1){ //Invert the signal and map it so max regen is maximum reverse. This needs its own value defined in code *******************************
throttle = -__builtin_divsd(__builtin_mulss(throttle, maxMotorCurrentNormalizedRegen), savedValues.maxThrottlePosition - savedValues.minThrottlePosition); //*******************************
}
else{ //Hands off! dont touch Pauls code *******************************
throttle = __builtin_divsd(__builtin_mulss(throttle, maxMotorCurrentNormalized), savedValues.maxThrottlePosition - savedValues.minThrottlePosition); //*******************************
}
}
if (temperatureBasePlate > THERMAL_CUTBACK_START) { // Force the throttle to cut back.
temperatureMultiplier = (temperatureBasePlate - THERMAL_CUTBACK_START) >> 3; // 0 THROUGH 7.
if (temperatureMultiplier >= 7)
temperatureMultiplier = 0;
else {
// temperatureMultiplier is now 6 to 0 (for 1/8 to 7/8 current)
temperatureMultiplier = 7 - temperatureMultiplier;
// temperatureMultiplier is now 1 for 1/8, 2 for 2/8, ..., 7 for 7/8, etc.
}
}
else {
temperatureMultiplier = 8; // Allow full throttle.
}
currentRadiusRefRef = __builtin_mulss(throttle,temperatureMultiplier) >> 3; // scale back the current command based on temperature. *******************************
if (RPS_times16 < 8) { // if less than 0.5 rev per second, make sure there's no regen. Also allow changing into reverse *******************************
if (currentRadiusRefRef < 0) currentRadiusRefRef = 0;
if (I_PORT_REGEN_THROTTLE == 0) { //check input for reverse switch, This input is pin 27 (or pin 10 if you use the 40-Pin PDIP verion) *******************************
reversing = 1; //This guy is not defined yet, define him already *******************************
{
else{
reversing = 0; //*******************************
}
}
}
if (reversing = 0){ //We are moving forward, keep up the good work //*******************************
if (currentRadiusRefRef < 0) {
currentRadiusRefRef = -currentRadiusRefRef;
sign = -1;
}
else {
sign = 1;
}
}
if (reversing = 1){ // Now we wanna go backwards, only give it power while rotating backwards. //*******************************
if (currentRadiusRefRef > 0) {
currentRadiusRefRef = -currentRadiusRefRef;
sign = -1;
}
else {
sign = 1;
}
}
Last edited by motorulf; 12-31-2016 at 02:46 PM..
Reason: usage warning
|
|
|
The Following User Says Thank You to motorulf For This Useful Post:
|
|
12-31-2016, 02:35 PM
|
#2954 (permalink)
|
EcoModding Lurker
Join Date: Dec 2016
Location: northern sweden
Posts: 33
Thanks: 17
Thanked 20 Times in 17 Posts
|
I want to include a picture also, but i only have 4 posts
By posting this i can send an image in the post below...
|
|
|
12-31-2016, 02:36 PM
|
#2955 (permalink)
|
EcoModding Lurker
Join Date: Dec 2016
Location: northern sweden
Posts: 33
Thanks: 17
Thanked 20 Times in 17 Posts
|
|
|
|
The Following User Says Thank You to motorulf For This Useful Post:
|
|
12-31-2016, 05:43 PM
|
#2956 (permalink)
|
Master EcoModder
Join Date: Sep 2010
Location: Saskatoon, canada
Posts: 1,488
Thanks: 749
Thanked 565 Times in 447 Posts
|
I would add a couple of resistors on the board, and one in series with the switch, to limit the max current into the micro.
Perhaps a 22K from Vcc (whether that is 5V or 3.3V) or your top trace on the board to the PIC pin or middle trace on the board. A 10K resistor from the PIC pin, or middle trace on your board, to Gnd, the bottom trace on your board. This one is shown as 'some resistor. That sets up a voltage divider for about 1/3 of Vcc on the input pin, which should read as 0 or OFF.
The switch would go in series with a 2K2 resistor - top trace to your switch .. green wire ... which is now wired in parallel with the 22K resistor. That sets up the PIC pin for about 85% of Vcc and should read as 1 or ON.
These resistor values are ones that I typically use. They limit current under 3 mA and are easy to buy. I didn't look up the specs on the PIC, but I don't expect any issues with low current into the PIC pin.
|
|
|
The Following User Says Thank You to thingstodo For This Useful Post:
|
|
12-31-2016, 06:33 PM
|
#2957 (permalink)
|
EcoModding Lurker
Join Date: Dec 2016
Location: northern sweden
Posts: 33
Thanks: 17
Thanked 20 Times in 17 Posts
|
Yep, good idea to limit the current thank you!
|
|
|
01-01-2017, 08:04 PM
|
#2958 (permalink)
|
PaulH
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832
Thanks: 1,368
Thanked 1,202 Times in 765 Posts
|
Looks good so far motorulf. Just a couple fixes. In C, = is assignment, and == is a test. For example you would do:
if (x == 1) {
Wow! I can't believe it! x is one!
}
y = 1;
// y now contains the value of 1
|
|
|
The Following User Says Thank You to MPaulHolmes For This Useful Post:
|
|
01-03-2017, 12:55 PM
|
#2959 (permalink)
|
EcoModding Lurker
Join Date: Dec 2016
Location: northern sweden
Posts: 33
Thanks: 17
Thanked 20 Times in 17 Posts
|
So, now i wanted to do some bench testing.
I have only contected 24v, throttle, led, rs232, current sensors and IGBTs.
What might cause the hardware fault?
Also i have measured all cables to the current sensors, they are connected, im shure...
I have also tried connecting other sensors, makes no difference.
I am not very good at analysing electronic hardware problems, please give me some advice
Last edited by motorulf; 01-03-2017 at 01:00 PM..
Reason: language...
|
|
|
The Following User Says Thank You to motorulf For This Useful Post:
|
|
01-03-2017, 01:24 PM
|
#2960 (permalink)
|
PaulH
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832
Thanks: 1,368
Thanked 1,202 Times in 765 Posts
|
Make sure you power the +24v where it says "24vGnd" and +24v. They are big, heavy spade connectors. The silkscreen writing is swapped (the only mistake, but fortunately, there's reverse polarity protection so it's not harmful), so make sure the +24v goes where it says 24vGnd, and the 24v ground plugs into the spot where it says +24v.
What current sensors are you using?
Last edited by MPaulHolmes; 01-03-2017 at 01:45 PM..
|
|
|
|