|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Limit Switches
How can we go about thoroughly programming the limit switches to control a specific motor using MPLab,
ex: if ((dig_in03)) { pwm03 = p3_y; } else { pwm03 = 127; } Is that the correct way? Any help would be greatly appreciated, Thanks! |
|
#2
|
|||
|
|||
|
Re: Limit Switches
You're up a bit late, aren't cha? (Or early? Do programmers ever get to see the sun?)
I think it's rc_dig_in03. Here's some code we had from last year, using joystick 2 y-axis to move the grabber arm up or down (like your lower arm with the motor at the elbow). We had a limit switch (LS) at the top and bottom to stop the motor, but allows it to go the other way even if it reaches the limit switch. Code:
//-------------------------- ARM WORK 3 -------------------------------------
//Arm desired direction is from JoyStick2, Y-axis. UP goes fwd, DOWN is back.
//pwm05 is the motor. LimitSwitch 5 and 7 is fwd and back stop points.
//Change pwm numbers of motor, LS, and Joystick as need be.
if (p2_y >(127+50)) //If Joystk2 Y pushed up - arm forward
{
if (rc_dig_in05 == 0) //is LS5 not pressed?
{ pwm05= 127+3; } // No- turn motor on!
else
{ pwm05= 127; } // Yes- turn motor off!
}
else if (p2_y < (127-50)) //If Joystk2 Y pulled back - arm backwrd
{
if (rc_dig_in07 == 0) //is LS7 not pressed?
{ pwm05= 127-3; } // No- turn motor on!
else
{ pwm05= 127; } // Yes- turn motor off!
}
else
{ pwm05= 127; } //Turn motor off
Just remember to cover all possibilities (all if/ifelse/else's) so you know at the end the motors are on or off.This wasn't our final code, but it did work at the time. As always YMMV. ______________________ One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs. |
|
#3
|
||||
|
||||
|
Re: Limit Switches
Hey, thank you so much! It worked!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Alternative to limit switches? | RbtGal1351 | Electrical | 27 | 10-12-2005 15:30 |
| limit switches | stephenthe1 | Programming | 28 | 11-05-2005 16:37 |
| Limit Switches help. | Xufer | Programming | 9 | 21-04-2004 21:21 |
| Limit switches | Team168 | Programming | 8 | 10-02-2003 16:22 |
| Limit Switches/Pots | Brett W | Technical Discussion | 3 | 28-01-2003 14:25 |