View Single Post
  #4   Spotlight this post!  
Unread 13-01-2006, 17:00
artdutra04's Avatar
artdutra04 artdutra04 is offline
VEX Robotics Engineer
AKA: Arthur Dutra IV; NERD #18
FRC #0148 (Robowranglers)
Team Role: Engineer
 
Join Date: Mar 2005
Rookie Year: 2002
Location: Greenville, TX
Posts: 3,078
artdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond repute
Re: Limit switch in easy c?

Quote:
Originally Posted by chadbarbe
I've only messed around with easy c a couple of times and i was able to get a 2 motor tank drive system up and running in no time... i love it! however, I'd like to get my limit switches working to prevent an arm motor from going too far (either up or down)... I know how to do this by handing coding in MP lab but I am not sure how to do it within the constraints of Easy C. Any suggestions?

CHAD
All you need to do is to be able to tell when the limit switch was depressed at the same time that the motor is trying to run in that direction. That way, you will only limit the direction of the motor in that direction, while still allowing for it to go in the other direction.

Here is how this sample arm/elevator is set up. There is an upper and a lower limit switch. The PWM signal for moving the arm up must be between 127 and 255. The PWM signal for moving the arm down will be between 0 and 127. Here is a diagram of this setup:




And here is the code: (from EasyC 2.0)
Code:
#include "Main.h"

void main ( void )
{
      char upperlimit; 
      char lowerlimit; 
      unsigned char arm; 

      while ( 1 )
      {
            upperlimit = GetDigitalInput ( 1 ) ; //Upper limit Switch is plugged into I/O Port 1
            lowerlimit = GetDigitalInput ( 2 ) ; //Lower limit Switch is plugged into I/O Port 2
            arm = GetRxInput ( 1 , 1 ) ; //Arm control is coming from RX port 1, Channel 1
            if ( upperlimit == 0 && arm > 127 )
            {
                  arm  = 127 ;
            }
            if ( lowerlimit == 0 && arm < 127 )
            {
                  arm  = 127 ;
            }
            SetPWM ( 1 , arm ) ; //Set PWM port 1 to 'arm' variable
      }
}
__________________
Art Dutra IV
Robotics Engineer, VEX Robotics, Inc., a subsidiary of Innovation First International (IFI)
Robowranglers Team 148 | GUS Robotics Team 228 (Alumni) | Rho Beta Epsilon (Alumni) | @arthurdutra

世上无难事,只怕有心人.