Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   pwm controlled by relay (http://www.chiefdelphi.com/forums/showthread.php?t=63895)

captainking 12-02-2008 17:35

pwm controlled by relay
 
in our code we want to be able to control pwms through buttons on the controller, but the only place we can find button commands are on relay blocks, and IF statements haven't worked for us so far, any ideas? Thanks in advance.

blaxbb 12-02-2008 17:41

Re: pwm controlled by relay
 
You can use relays to control motors, but you wont have the speed control that using a PWM value would give you.

When you program it assign a button to forward and reverse

Code:

relay1_fwd = p1_sw_aux1;
relay1_rev = p1_sw_aux2;


billbo911 12-02-2008 17:56

Re: pwm controlled by relay
 
Quote:

Originally Posted by captainking (Post 697560)
in our code we want to be able to control pwms through buttons on the controller, but the only place we can find button commands are on relay blocks, and IF statements haven't worked for us so far, any ideas? Thanks in advance.

We have done exactly this in the past.

Code:

if (p1_sw_top && !p1_sw_trig)
{
pwm04 = 225;
}
else if (!p1_sw_top && p1_sw_trig)
{
pwm04 = 50;
}
else
{
pwm04 = 127;
}


Boydean 12-02-2008 18:03

Re: pwm controlled by relay
 
We have to do the same thing, but we have to have the motor turn one direction all the time and the other only when the button is pressed.

Code:

if(p2_sw_aux1 == 1)
        {
                relay1_fwd = 1;
                relay1_rev = 0;
        }
else
        {
                relay1_fwd = 0;
                relay1_rev = 1;
        }


captainking 12-02-2008 18:38

Re: pwm controlled by relay
 
I think I should be a little more specific, we want to be able to switch from one set up to another by the push of a button, but we can't find a way to switch pwms through that. All of our if statements haven't worked, is there a way to assign for example, tank drive to trigger and arcade mode to aux?

usbcd36 12-02-2008 21:27

Re: pwm controlled by relay
 
You could use static variables to achieve these means.

Code:

static unsigned char Tank_Drive = 1; //default is tank drive

if (p1_sw_trig) Tank_Drive = 1; // enable tank drive
else if (p1_sw_aux1) Tank_Drive = 0; // enable other drive system

if(Tank_Drive)
{
    // code for tank drive here
}
else
{
    // code for other drive system here
}

What this will do is switch to tank drive when you press the trigger and switch to another drive system when you press the aux button. Not when you hold them down, but when you press them.

neutrino15 13-02-2008 01:29

Re: pwm controlled by relay
 
Quote:

Originally Posted by usbcd36 (Post 697755)
You could use static variables to achieve these means.

Yep. That is exactly what we do to produce an "on/off" button effect. It has to be modified slightly to use 1 button for "toggle" instead of 2 distinct "tank" and "other" buttons. I don't know why you want to drag a relay into this, and I am almost sure I don't understand what you are asking. Could you explain better?

Quote:

but the only place we can find button commands are on relay blocks
What about buttons on the joysitck? Digital inputs on the OI? (Or even resistors in parallel?)


All times are GMT -5. The time now is 00:57.

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