PWM zero gaps !

25 views
Skip to first unread message

ilight

unread,
May 10, 2013, 2:26:10 PM5/10/13
to ioio-...@googlegroups.com
i tried to generate using setdutycycle and setpulsewidth and i always get zero gaps in it ! 

this is a sample of what i'm doing 

public void setup() throws ConnectionLostException {
try {

pwmOutput1_ = ioio_.openPwmOutput(new DigitalOutput.Spec(11,Mode.OPEN_DRAIN), 1000);
 
pwmOutput2_ = ioio_.openPwmOutput(new DigitalOutput.Spec(12,Mode.OPEN_DRAIN), 1000);
enableUi(true);
} catch (ConnectionLostException e) {
enableUi(false);
throw e;
}
}
public void loop() throws ConnectionLostException {
try {
while(true){
if (OnOff_1.isChecked()) {
pwmOutput1_.setDutyCycle(seeking11.getProgress()/1000.0f);

} else {

pwmOutput1_.setDutyCycle(0);

}

Ytai Ben-Tsvi

unread,
May 10, 2013, 7:47:00 PM5/10/13
to ioio-...@googlegroups.com
What do you mean by "zero gaps"?
I see that you're opening the pins in open-drain mode. Do you have pull-ups on them?


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ilight

unread,
May 10, 2013, 8:47:21 PM5/10/13
to ioio-...@googlegroups.com
yes i'm using drain mode and pull up and it's giving 5 v and everything is okay and the pulses changes with the duty cycle but there's problem of zeros between the periods that affect the pwm signal , i thought there was a problem in the thread ,but now i modified IOIOsimpleApp a little bit and it gives better response than the earlier thread.

thanks Ytai 

Ytai Ben-Tsvi

unread,
May 10, 2013, 9:09:49 PM5/10/13
to ioio-...@googlegroups.com
I'm sorry, I don't understand what do you mean by "zeros between the periods" still.
Can you explain in more detail or attach a diagram?


On Fri, May 10, 2013 at 5:47 PM, ilight <ilight....@gmail.com> wrote:
yes i'm using drain mode and pull up and it's giving 5 v and everything is okay and the pulses changes with the duty cycle but there's problem of zeros between the periods that affect the pwm signal , i thought there was a problem in the thread ,but now i modified IOIOsimpleApp a little bit and it gives better response than the earlier thread.

thanks Ytai 

--

ilight

unread,
May 11, 2013, 9:41:18 AM5/11/13
to ioio-...@googlegroups.com


import ioio.lib.api.PwmOutput;
import ioio.lib.api.DigitalOutput;
import ioio.lib.api.DigitalOutput.Spec.Mode;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.android.IOIOActivity;
import ioio.lib.util.AbstractIOIOActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.ToggleButton;

public class IOIORBG extends AbstractIOIOActivity {
private ToggleButton OnOff_1, OnOff_2, read, relax, party, normal;
private SeekBar seeking11, seeking22;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

seeking11 = (SeekBar) findViewById(R.id.seekBar11);
seeking11.setMax(100);

seeking22 = (SeekBar) findViewById(R.id.seekBar22);
seeking22.setMax(100);

OnOff_1 = (ToggleButton) findViewById(R.id.toggleButton1);

OnOff_2 = (ToggleButton) findViewById(R.id.toggleButton2);

read = (ToggleButton) findViewById(R.id.toggleButton3);
relax = (ToggleButton) findViewById(R.id.toggleButton4);
party = (ToggleButton) findViewById(R.id.toggleButton5);
normal = (ToggleButton) findViewById(R.id.toggleButton6);
        enableUi(false);
    }
class IOIOThread extends AbstractIOIOActivity.IOIOThread {

private PwmOutput pwmOutput1_;
private PwmOutput pwmOutput2_;
public void setup() throws ConnectionLostException {
try {

pwmOutput1_ = ioio_.openPwmOutput(new DigitalOutput.Spec(11,Mode.OPEN_DRAIN), 1000);
 
pwmOutput2_ = ioio_.openPwmOutput(new DigitalOutput.Spec(12,Mode.OPEN_DRAIN), 1000);
enableUi(true);
} catch (ConnectionLostException e) {
enableUi(false);
throw e;
}
}
public void loop() throws ConnectionLostException {
try {
while(true){
if (OnOff_1.isChecked()) {
pwmOutput1_.setDutyCycle(seeking11.getProgress() /100.0f);

} else {

pwmOutput1_.setDutyCycle(0);

}

if (OnOff_2.isChecked()) {

pwmOutput2_.setDutyCycle(seeking22.getProgress() /100.0f);


} else {

pwmOutput2_.setDutyCycle(0);

}

if (read.isChecked()) {
pwmOutput1_.setDutyCycle(0.8f);
pwmOutput2_.setDutyCycle(0.8f);
} else {
pwmOutput1_.setDutyCycle(0);
pwmOutput2_.setDutyCycle(0);
}
if (relax.isChecked()) {
pwmOutput1_.setDutyCycle(0.6f);
pwmOutput2_.setDutyCycle(0.6f);
} else {
pwmOutput1_.setDutyCycle(0);
pwmOutput2_.setDutyCycle(0);
}
if (party.isChecked()) {
pwmOutput1_.setDutyCycle(1);
pwmOutput2_.setDutyCycle(1);
} else {
pwmOutput1_.setDutyCycle(0);
pwmOutput2_.setDutyCycle(0);
}
if (normal.isChecked()) {
pwmOutput1_.setDutyCycle(0.5f);
pwmOutput2_.setDutyCycle(0.5f);
} else {
pwmOutput1_.setDutyCycle(0);
pwmOutput2_.setDutyCycle(0);
}

IOIOThread.sleep(10);}
} catch (InterruptedException e) {
ioio_.disconnect();
} catch (ConnectionLostException e) {
enableUi(false);
throw e;
}
}
}

@Override
protected AbstractIOIOActivity.IOIOThread createIOIOThread() {
return new IOIOThread();
}

private void enableUi(final boolean enable) {
runOnUiThread(new Runnable() {
//@Override
public void run() {
seeking11.setEnabled(enable);
seeking22.setEnabled(enable);
OnOff_1.setEnabled(enable);
OnOff_2.setEnabled(enable);
read.setEnabled(enable);
relax.setEnabled(enable);
party.setEnabled(enable);
normal.setEnabled(enable);
}
});
}

}

Ytai Ben-Tsvi

unread,
May 11, 2013, 9:55:46 PM5/11/13
to ioio-...@googlegroups.com
Your code does that...
Imagine for example that "party" is false and "normal" is true. Your loop will first set the PWM to 0, then to 0.5. In general, regardless of what the checkboxes are set to, only "normal" will eventually matter, since you're overriding all the previous settings.

You probably want something like a radio button widget and then your code might look like:

if (sw1.isChecked()) {
  ...
} else if (sw2.isChecked()) {
  ...
} else if (sw3.isChecked()) {
  ...
} else {
  ...
}



}
});
}

}

ilight

unread,
May 12, 2013, 2:32:39 AM5/12/13
to ioio-...@googlegroups.com
thanks a lot i will try it.
Reply all
Reply to author
Forward
0 new messages