officinerobotiche / uNAV.X

Project MPLABX for drive uNAV on dsPIC33
http://rnext.it/project/unav/
MIT License
9 stars 2 forks source link

Value of ENABLE pin must be configurable #15

Closed katodo closed 9 years ago

katodo commented 9 years ago

Dependig by motor bridge, ENABLE pin can be valid LOW or HIGH. I need a FLAG to chose if ENABLE is true with LOW or HIGH level of output pin...

Now I call this flag Flag.OutpuEnablePolarity If (Flag.OutpuEnablePolarity == 1) I need HIGH level of output EN pin to enable bridge. If (Flag.OutpuEnablePolarity == 0) I need LOW level of output EN pin to enable bridge. Only for example purpose, this is my function on other software:

/*!
  \param Motor : This is channel of motor to be enabled ( 1 or 2 ).
  \param Status : 0 = motor is disabled; 1= motor is enabled. This is indipendent from electronic.
  \return void
MOTOR1 & MOTOR2 are defines.
MOTOR_ENABLE1 & MOTOR_ENABLE2 are macros to change pin status.
*/

void MotorControlEnable(unsigned char Motor, unsigned char Status){
    if( Motor == MOTOR1  ) {   
       if ( Status == MOTOR_ACTIVE ) {   
           // Enable motor 1
            if( Flag.OutpuEnablePolarity == 1)
                MOTOR_ENABLE1 = 1;
            else
                MOTOR_ENABLE1 = 0;
         }
        else {
            // Disable motor 1
            if( Flag.OutpuEnablePolarity == 1)
                MOTOR_ENABLE1 = 0;
            else
                MOTOR_ENABLE1 = 1;
         }
    }
    if( Motor == MOTOR2  ) {   
       if ( Status == MOTOR_ACTIVE ) {   
            // Enable motor 2
            if( Flag.OutpuEnablePolarity == 1)
                MOTOR_ENABLE2 = 1;
            else
                MOTOR_ENABLE2 = 0;
         }
        else
        {   
            // Disanble motor 2
            if( Flag.OutpuEnablePolarity == 1)
                MOTOR_ENABLE2 = 0;
            else
                MOTOR_ENABLE2 = 1;
         }
    }
}
rbonghi commented 9 years ago

I've a trick way to resolve this problem:

1) Set default value: 
MOTOR_ENABLE = Flag.OutpuEnablePolarity;

2) Change value respect default:
MOTOR_ENABLE ^= 1;

/cc @guiott

katodo commented 9 years ago

I don't understand your trick. For example in your bridge Enable is true with a HIGH level input, in my bridge Enable is true with a LOW level input. In my case input of bridge is a DISABLE ( or !ENABLE ) pin, in your case is a ENABLE ( or !DISABLE ) pin.

"Status" can be MOTOR_ACTIVE or MOTOR_DISABLED.

Flag.OutpuEnablePolarity is set to "1" if pin of bridge is an ENABLE pin or "0" if pin of bridge is a DISABLE input.

in this case function may be:

if( Status == MOTOR_ACTIVE )
 MOTOR_ENABLE = Flag.OutpuEnablePolarity;
else
 MOTOR_ENABLE = !(Flag.OutpuEnablePolarity);

this is what you meant?

katodo commented 9 years ago

Possible solution : MOTOR_ENABLE1 = enable_motors xor Flag.OutpuEnablePolarity;

Where, enable_motors is a message from protocol, MOTOR_ENABLE1 is a macro used to change pin status.

thanks rbonghi :)

rbonghi commented 9 years ago

Good morning! Yes @katodo, to solve this problem. I think to add the flag "OutputEnablePolarity" on dspic to change polarity (ON - OFF) switch motor, and add in https://github.com/rbonghi/uNAV.X/blob/develop/src/control/motors_PID.c#L218

The ours solution:

MOTOR_ENABLE1 = enable_motors ^ OutputEnablePolarity;
MOTOR_ENABLE2 = enable_motors ^ OutputEnablePolarity;

Finally, I would like to add a command in "parameters_motor_t": https://github.com/rbonghi/uNAV.X/blob/develop/includes/packet/motion.h#L109 to remotely change enable polarity.

rbonghi commented 9 years ago

solve with 7c521dc7b8a8784a64661951bae9efc6258d1f5d