Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Microswitch problem (http://www.chiefdelphi.com/forums/showthread.php?t=53193)

SoD 01-02-2007 09:15

Microswitch problem
 
We have a problem with our micro switch. It doesn't work. We conncected it to the digital in/out, but it allways gets a '1' from the program no metter what, even when its disconnected. What is the problem?

Andrew Morris 01-02-2007 09:21

Re: Microswitch problem
 
A few questions:
1. Do you have the digitalIO port you are using configured as an input?
2. What alias are you using to read the port(like rc_dig_in01)?

Basedd on your answers I should be able to tell you what is wrong.

Andrew

SoD 01-02-2007 09:35

Re: Microswitch problem
 
Quote:

Originally Posted by Andrew Morris (Post 569411)
A few questions:
1. Do you have the digitalIO port you are using configured as an input?
2. What alias are you using to read the port(like rc_dig_in01)?

Basedd on your answers I should be able to tell you what is wrong.

Andrew

1. Yes
2. Yes, we are using rc_dig_in01. This is the code we tried.

if (rc_dig_in01 == 1)
{
relay1_fwd = 0;
relay1_rev = 0;
}

Mark McLeod 01-02-2007 09:42

Re: Microswitch problem
 
The digital inputs are designed to return 1 if the switch is open or disconnected. It returns 0 only when closed.

The code you posted never does anything if the switch is closed (rc_dig_in01 is 0).

Try something like:
Quote:

Originally Posted by SoD (Post 569419)
if (rc_dig_in01 == 1)
{
relay1_fwd = 0;
relay1_rev = 0;
}
else
{
relay1_fwd = 1;
relay1_rev = 0;
}


SoD 01-02-2007 09:44

Re: Microswitch problem
 
oops I though it should give 1 xD

So if i change it to ==0 it should work?

Mark McLeod 01-02-2007 09:53

Re: Microswitch problem
 
Quote:

Originally Posted by SoD (Post 569423)
oops I though it should give 1 xD

So if i change it to ==0 it should work?

Usually we give it something to do when it's equal to 1 and something different to do when it's equal to 0.

Relay1 will only change when we explicitly change it. The last thing we did will always be in effect.
For example, in your original code the relay was set to:
Code:

    relay1_fwd = 0; relay1_rev = 0;
in User_Initialization(), then your code changed to to the same value.
Nothing ever changed it to 1.

If you modify your code to use "==0" instead and change it to set the Relay to 1, then Relay1 will begin as 0 and change to 1 when you flip your switch, but nothing will ever change it back to 0 if the switch is flipped off again.

SoD 01-02-2007 09:59

Re: Microswitch problem
 
Ok i think i understand, tnx alot ;p

SoD 01-02-2007 10:24

Re: Microswitch problem
 
$@#$@#$@#$@# it still doesn't work X_X

The rc_dig_in01 is allways 1 even when we press on the microswitch X_X what is wrong here?

Mark McLeod 01-02-2007 10:31

Re: Microswitch problem
 
If you are using the micro switch that came in the kit, then there are different ways of wiring it.
Choose the wrong way and it will never be 0.


Let me see if I can find a picture....

Andrew Morris 01-02-2007 10:32

Re: Microswitch problem
 
You may have the switch plugged in wrong(white where black sould be). Otherwise I would need to know how you are checking the value(LED or printf statement) and see the code you are using.

Andrew

SoD 01-02-2007 10:40

Re: Microswitch problem
 
Printf. And there are 3 plugins in the microswitch right? We connected the yellow one to the upper one, nothing to the middle one, and the red one to the lowest one

Mark McLeod 01-02-2007 10:45

Re: Microswitch problem
 
Quote:

Originally Posted by SoD (Post 569461)
Printf. And there are 3 plugins in the microswitch right? We connected the yellow one to the upper one, nothing to the middle one, and the red one to the lowest one

Should be black and yellow, no red at all.
Use only the outer wires at the RC digital input side.

The red is power and used only by devices that need power to work. A switch doesn't need power. It simply connects the signal wire (yellow) to the ground (black) or not to close or open the circuit.

If you have a multimeter you can use it to test that the switch is wired correctly.

Bomberofdoom 01-02-2007 10:55

Re: Microswitch problem
 
Thanks! We've got it working!:D

SoD 01-02-2007 11:28

Re: Microswitch problem
 
Darn we now have a new problem :(

if (rc_dig_in01 == 0)
{
relay1_fwd = 0;
relay1_rev = 0;
}

else
{
relay1_fwd = 1;
relay1_rev = 1 ;
}

This is the code we are trying to use atm, but we have a problem. When the motor works foward, and i press the microswitch, it changes from 1 to 0 and the motor stops working. But when the motor is working backwards, and I press the microswitch, the microswitch turns to 0 but the relay1_rev remains 1 ;s

Whats wrong?

Andrew Morris 01-02-2007 11:34

Re: Microswitch problem
 
What motor? You haven't mentioned a motor before.

Andrew

Mark McLeod 01-02-2007 11:55

Re: Microswitch problem
 
1 Attachment(s)
Here is a table of how to set the relay values to get the different results possible. It's from the IFI Spike document: http://www.ifirobotics.com/docs/spik...uide-sep05.pdf

We don't usually set both "rev" and "fwd" to 1 at the same time.

Both fwd=0;rev=0; as well as fwd=1;rev=1; should mean the motor is off.

This code will execute one section only as long as the switch is depressed and the other whenever the switch is not pressed.


All times are GMT -5. The time now is 23:49.

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