# Pulse width extender

**URL:** <https://forum.xod.io/t/pulse-width-extender/3437>\
**Category:** XOD Programming Questions\
**Created:** [February 6, 2020, 3:48am UTC](https://forum.xod.io/t/pulse-width-extender/3437 "2020-02-06T03:48:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 3:48am UTC](https://forum.xod.io/t/pulse-width-extender/3437/1 "2020-02-06T03:48:33Z")

</div>

hi, i´m from Venezuela, sorry my english  
i would like to build a pulse width extender:  
i receive pulses from a source and i whant to add a variable amount of pulse wide, i would like to use 2 buttons, 1 for add and other for lower  
if anybody can help me do do it i appreciate it much.  
thanks ![pulsoingles](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/7/751f0e6e0726ae9d0cb28b1965f793c3ef40de33.png)

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 4:00am UTC](https://forum.xod.io/t/pulse-width-extender/3437/2 "2020-02-06T04:00:04Z")

</div>

Add a “delay” node and you can vary the pulse duration depending on the frequency

[**`nkrkv`** rotary encoder](https://xod.io/libs/nkrkv/encoder/) library has an up-down counter, you can set step of 0.01 as an example

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 10:21am UTC](https://forum.xod.io/t/pulse-width-extender/3437/3 "2020-02-06T10:21:21Z")

</div>

thanks to you, i´m not a good programmer, i´ll work in it

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 10:45am UTC](https://forum.xod.io/t/pulse-width-extender/3437/4 "2020-02-06T10:45:58Z")

</div>

is there in XOD a oscilloscope virtual tool ? or whatever let me see what i´m doing ?

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 11:19am UTC](https://forum.xod.io/t/pulse-width-extender/3437/5 "2020-02-06T11:19:31Z")

</div>

![xod](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/e/e3f171dc47abeb4fe8c531f2adb00997ce20c4d6.png)

???

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 11:23am UTC](https://forum.xod.io/t/pulse-width-extender/3437/6 "2020-02-06T11:23:49Z")

</div>

min-max not is for it , use [nkrkv/encoder/count — XOD](https://xod.io/libs/nkrkv/encoder/count/)

search the library, from the add button look for `nkrkv/encoder`

> [@gsune](#):
>
> is there in XOD a oscilloscope virtual tool ? or whatever let me see what i´m doing ?

Use “watch” node, it’s not like a graphic function but it helps

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 11:54am UTC](https://forum.xod.io/t/pulse-width-extender/3437/7 "2020-02-06T11:54:01Z")

</div>

> [@cesars](#):
>
> watch

thanks to you. it help me a lot

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 12:30pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/8 "2020-02-06T12:30:05Z")

</div>

![2](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/a/a370154d89efe4c5dc13cd4cd51aab3c46cd8f61.png)  
??

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 12:34pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/9 "2020-02-06T12:34:06Z")

</div>

but you don’t load it to a board or simulate it, it only works if you simulate or debug

in step de count place a tweak-number so you can vary in simulation …

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 6, 2020, 1:21pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/10 "2020-02-06T13:21:51Z")

</div>

Or, more directly, replace buttons with tweak-pulse or tweak-boolean…

Note: The above code will provide a minimum pulse width at least delay-T long, but it will not ADD the delay to each pulse. In fact, if original pulse is greater than delay-T, the resulting pulse will only be delay-T.

You could add delay to pulse by using pulse-on-false to start timer when pulse ends and OR it with the actual pulse. You might get a quick dip in your pulse before delay starts, though. Adding a defer between the pulse source and the OR would probably eliminate the quick dip, but it will also delay the start of the output pulse.

![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/c/ce40cec831b58e73e201ae9190b6d97dae9d8e81.png)

NOTE: probably none of this will work if you are trying to manage very short pulses (micro-second? I don’t know what the limit is…) since Arduino may not be fast enough (especially if there is other code running at the same time). You certainly won’t be able to see short pulses using a watch node…

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 1:27pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/11 "2020-02-06T13:27:26Z")

</div>

to add something step to 1, it may be too much if the frequency is high and you will not see a difference, you may need 0.1, 0.01 or 0.001

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 3:04pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/12 "2020-02-06T15:04:54Z")

</div>

the pulse width is goin to be between 0 and 30 ms

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 3:10pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/13 "2020-02-06T15:10:49Z")

</div>

![3](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/9/9c94e032da77de3612625306afbd2647f5fe6791.png)  
how do i search those (puls… and or ) in the libraries ?

PD: i already found IT THANKS

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 3:32pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/14 "2020-02-06T15:32:14Z")

</div>

STEP 1 = 1sec DELAY  
use STEP 0.001 to 0.03

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 3:33pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/15 "2020-02-06T15:33:16Z")

</div>

pulse-on-true or pulse-on-false

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 3:35pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/16 "2020-02-06T15:35:12Z")

</div>

STEP 1 = 1sec DELAY  
use STEP 0.001 to 0.03

Where do i have to set it ?

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 3:39pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/17 "2020-02-06T15:39:01Z")

</div>

> [@gsune](#):
>
> Where do i have to set it ?

in count change step (in inspector node) or add tweak-number as I indicated above

---

<div class="post-metadata">

**Author:** ![gsune](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gsune/32/1966_2.png) [@gsune](https://forum.xod.io/u/gsune)\
**Post date:** [February 6, 2020, 3:59pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/18 "2020-02-06T15:59:25Z")

</div>

can i push the tweaks buttons in real time in the simulation?  
i can´t post untill 18 hours because i´m new ITS WORKING THANKS

 ![4](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/4/408a47a474361291ac742824bc443a920ba1b96b.png)

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [February 6, 2020, 4:07pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/19 "2020-02-06T16:07:56Z")

</div>

Select or use double click, change in the inspector.

External libraries will give error, use debug and upload

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 6, 2020, 4:51pm UTC](https://forum.xod.io/t/pulse-width-extender/3437/20 "2020-02-06T16:51:36Z")

</div>

For most tweak-\* nodes, you select the node, then update the value in the inspector sub-window to the left. For tweak-pulse, instead of updating a value, you just push the Pulse button where value would normally be. Each click on that button will send another pulse.

[Next page](https://forum.xod.io/t/pulse-width-extender/3437.md?page=2)
