|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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.
|
|
#2
|
|||
|
|||
|
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; |
|
#3
|
||||
|
||||
|
Re: pwm controlled by relay
Quote:
Code:
if (p1_sw_top && !p1_sw_trig)
{
pwm04 = 225;
}
else if (!p1_sw_top && p1_sw_trig)
{
pwm04 = 50;
}
else
{
pwm04 = 127;
}
|
|
#4
|
||||
|
||||
|
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;
}
|
|
#5
|
||||
|
||||
|
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?
|
|
#6
|
||||
|
||||
|
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
}
Last edited by usbcd36 : 12-02-2008 at 21:30. |
|
#7
|
||||
|
||||
|
Re: pwm controlled by relay
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:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Silicon Controlled Rectifier | teh_pwnerer795 | Electrical | 37 | 26-11-2007 07:09 |
| Guage of PWM/Relay Cables | Jake M | Electrical | 2 | 07-02-2007 00:49 |
| PC Controlled Robot | EHaskins | Programming | 6 | 05-11-2006 06:45 |
| Servos controlled by RC? | Obi | Programming | 5 | 01-02-2005 14:43 |
| relay and pwm outputs | nick_champ_2 | Electrical | 1 | 31-01-2003 13:08 |