Relay program?

I need help trying to figure out a program. I want to engage a relay when my right and left drive motors are between 125 and 129. I thought it would be something along the lines of 125 < x < 129 but i cant seem to get this to function can anyone help me out?

Comparisons don’t “chain” like that in C. Do it this way:

if ( (125 < x) && (x < 129) )

The inner parentheses aren’t strictly necessary, but I think they make it much more readable.

do a printf of x. You may not be getting the PWM value you think you are.
We have had problems with pwmXX values not being available in all of our subroutines. If that is working, try a nested if-not as elegant, but it works.
Lastly try increasing the band you are allowing on 127-your offset may be off or you go through it too fast.

Check that your value to the relay routine call is a logical 0 or 1 (try forcing it)

i was thinking i needed to set my x value to say (pwm 1) if i wanted it to work with my pwm. But i tried using pwm control with the x variable inside it and it just makes my pwm continually run is there something i’m missing

Show us the code you’re trying to make work. Tell us exactly what you want it to do, and we can tell you what to change to make it do that.

here is our code you asked for…

Break program.doc (116 KB)

Break program.doc (116 KB)

where are you setting the value of x?

Where is this file in the overall scheme of the robot? I don’t know how to look at easy C to intuitively know what is going on, but it could be you are calling the function in the wrong place. Is the function called in user_routines.c? It should probably called somewhere from within Default_Routines(). I am assuming the easy C version of the code is organized the same way as just regular code.

I don’t see anything that sets the value of x. Did you forget the line that reads the joystick value?

(Is there a reason you posted it as a Word document containing a picture, instead of just copying the text? I don’t use Word, and it was inconvenient to convert your file to a readable form.)

the Setpwm (1, x) is a window that you put your variable in so “x” is set to the value of pwm 1

Isn’t it the other way around? As an output function, SetPwm( 1, x ) sets pwm 1 to the value of x. I’m not aware of a built-in way to read the present value of a pwm output using easyC.

So where in your program do you actually control the pwm output that you want to use as the trigger for your relay?

Normal operation would be to:

  1. Get the desired drive value from the driver–GetOIAInput()

  2. Do your tests on when you want your relay to be active–if () else

  3. Output your relay command–SetRelay()

  4. Set your PWM Output–SetPWM()