ok this is my first try at programing i have been a mechanic for the past three years and this year i am going to do both program and build but i need to know how to program a limit switch and in what file should i put the peace of code in
which system are you using?
Im going to assume first off that your using the old control system from IFI and not the cRIO, and that your using the default code.
limit switches are automatically programmed, they use the digital_io ports on the rc. Look in user_routines.c twords the bottom you’ll see a block that will look something like this…
/*---------- PWM outputs Limited by Limit Switches ------------------------*/
Limit_Switch_Max(rc_dig_in05, &pwm03);
Limit_Switch_Min(rc_dig_in06, &pwm03);
Limit_Switch_Max(rc_dig_in07, &pwm04);
Limit_Switch_Min(rc_dig_in08, &pwm04);
Limit_Switch_Max(rc_dig_in09, &pwm09);
Limit_Switch_Min(rc_dig_in10, &pwm09);
Limit_Switch_Max(rc_dig_in11, &pwm10);
Limit_Switch_Min(rc_dig_in12, &pwm10);
Limit_Switch_Max(rc_dig_in13, &pwm11);
Limit_Switch_Min(rc_dig_in14, &pwm11);
Limit_Switch_Max(rc_dig_in15, &pwm12);
Limit_Switch_Min(rc_dig_in16, &pwm12);
each one corresponds to a dig_io port on the RC, you’ll notice that for each motor [pwm port] there are two dig_io ports used. If you are just using one limit switch and one motor you just need to use one of the ports, but if you were using 2 limit switches and one motor you would use 2 ports both of which would have to be controlling the pwm port that the motor is on.
does that make sence? feel free to ask more questions
is that where i put the if statment
also what about relays they dont go to a pwm port
Well for relays you would just change the pwm value on one of the dig_io ports to the relay port [ex. ‘Limit_Switch_Max(rc_dig_in05, &relay1_fwd);’]
Now for if statements we would have to know exactly what your doing with the limit switch, because if you are just using it to stop or start a motor the you don’t have to have if statements. But if your doing something else with it, like telling it when it gets switched to start a sensor of some kind or wanting to have it only stay switched for say 10 seconds then reverse the motor you could add if statements here if you wanted to in order to achieve what ever your task is.