View Full Version : sample limit switch code???
anyone got one??? :confused:
we need it to program our arm
KenWittlief
17-02-2004, 16:09
Im pretty sure the default code already has PWMs and relay outputs that are programmed to stop if certain digital input pins are pulled low by an external switch.
From the top of my head, I think relay out 8 is tied to digital input 16? intended to be used with the compressor and the pressure limit switch? - that would be a good example of how to start.
we are trying to use limit switch as interrupts... and when the arm hits the switch, it will stop moving, that's our plan :)
deltacoder1020
17-02-2004, 16:26
then you would probably need a single-edge based interrupt pin to determine when the circuit goes from open to closed.
KenWittlief
17-02-2004, 17:10
it would be much simpler to have the line of code that is controlling the motor also look at the limit switch on a digital input pin, instead of using interrupts
this is not really an interrupt application, because you are controlling the motor output on every loop of your code anyway, there is no reason to interrupt the loop when the switch closes - the victors and spikes dont respond that fast.
besides, contact switches bounce when they open and close - which means, instead of simply going from 0 to 1, they go 0000111110011011010101111111111 - so for every switch closure you will see maybe 20 to 100 interrupts within several milliseconds.
Mark McLeod
17-02-2004, 17:13
we are trying to use limit switch as interrupts... and when the arm hits the switch, it will stop moving, that's our plan :)
As Ken mentioned, this section from the FRC default code, user_routines.c, Default_Routine() does what you want. Each of the pwm outputs are stopped by a limit switch in either direction (min, max).
/*---------- 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);
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.