Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   sample limit switch code??? (http://www.chiefdelphi.com/forums/showthread.php?t=25492)

tml240 17-02-2004 16:01

sample limit switch code???
 
anyone got one??? :confused:
we need it to program our arm

KenWittlief 17-02-2004 16:09

Re: sample limit switch code???
 
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.

tml240 17-02-2004 16:17

Re: sample limit switch code???
 
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

Re: sample limit switch code???
 
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

Re: sample limit switch code???
 
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

Re: sample limit switch code???
 
Quote:

Originally Posted by tml240
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).
Code:

  /*---------- 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);



All times are GMT -5. The time now is 17:26.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi