One button control PWM

Hello, friends.
I’ve maid my first project with XOD.
But i think it’s very complicated and maybe somebody made same things more optimal?

I have one button and three-grade (actually four) PWM - 0% , 50% , 75% and 100%.
Algorithm is:

  1. On boot everything off - 0%
  2. When i press one time - PWM changing to 75%
  3. When i press one time (delta-time between two presses more than 2 seconds) - 75% changing to 0% and cycling between 75 and 0
  4. When i press two or more times (with delta time less than 2 seconds) - PWM changing to 100 > 50 > 75 > 100 > 50 >75 and so on.
  5. When i stopped on some percents (delta-time between two presses more than 2 seconds) - algorithm like #3 - cycling between current percents and 0.

This algorithm for controlling coolers (ventilation system). Very useful - i made (actually copied) such kind of project on Attiny13 and AVR Studio (for pocket lighter) but for now i need to extend this algorithm if future and Attiny has less pins and timers than i need (this needs in future to react on logic true and off timer additionally).

Screen Shot 2020-05-13 at 10.54.04

Thanks for reading! :slight_smile:

This is considerably simpler, but may have issues that make it unusable for you (for example, if it is on when you double-press, the 1st press will turn it off, then 2nd press within 2 seconds will turn it back on & cycle to the next value. If needed, you could probably add code to prevent it turning off for 2 seconds to see if there is another button press, but you mentioned you had a limited number of timers.)

As I understand it, the goal is to cycle between a stored value and off; if button press is <2s apart, then change stored value. In my code, the count and nth-input is the stored value. The delta-time/greater/branch nodes determine if we are just toggling on/off or changing stored value. The flip-flop/if-else nodes determine if we are on or off. If changing stored value, then increment count and set toggle to force system to turn on.

Note: if we could default to 0.50 instead of 0.75, we could replace nth-input with multiply 0.25 and add 0.50. If you really want to, you could even send pulse to count-INC on boot so it starts at 1, giving 0.75 as the initial value:
image

This eliminates the issue where 1st button-press turns system off, then 2nd press turns it back on and increments PWM value, but it uses another system timer & adds a 2-second delay to turning the system on or off (waiting to see if there is another button-press before acting). If there is a 2nd button press within 2 seconds, then the gate-EN below delay will be false when delay-DONE pulses and it will not toggle the flip-flop.

Thank You very much for your answer!
I’ll try to repeat your algorithm today.

The next approach is make this program works only if input pin is High (i turned on the system and give +5v to input) and 2 minutes delay after i’ve turned system off (+5v disappeared and 2 minutes delay off).

Maybe you can propose some method?
Thanks again!

If you want to add more conditions for turning on, you can add more if-else after the existing (which would allow different values besides just on/off), or add an “and” node between the flip-flop and if-else so that all inputs to the “and” will have to be true for the system to turn on.

Without the delay to turn off, you can use the “button” node to read the value of the pin getting +5v input. Just link it directly to the “and” node mentioned in previous paragraph. To add the delay for off, you need to add a delay node that starts when the button node turns false (use pulse-on-false node). As long as button “or” delay-ACT is true, system should be on.

Can you please make screenshot of this operator aparted?
Thanks!
Screen Shot 2020-05-13 at 19.10.36

I don’t understand what you are asking for. It looks like you provided a screenshot of just that part…

Are you asking for an explanation of what nth-input does or how to find it?

Sorry, maybe i wrote wrong word, i’m not very familiar with English.

XOD asked me to change nth-input to nth-input(number). I’ve changed - everything works as expected. Are your patch works well?

My question is to see this node opened :slight_smile: It’s usual (regular)? Simulation works?

Do you have an older version of XOD (or maybe just an older copy of nodes in __lib__\xod)? My copy just uses generic pins & simulation worked.
image

Let me notice that i’m on Mac.

If you modify any of the built-in nodes (or XOD thinks you changed them; even just moving nodes within a patch) and save your project, it will create a personal copy of the XOD nodes, and they will not update when you update XOD. In my case, the libraries are stored in C:\Users\gweimer\xod\__lib__. There should NOT be any xod* (xod, xod-dev, etc.) folders in this location. If any exist, exit XOD, then delete (or at least rename) them so XOD doesn’t see them as over-rides for the built-in nodes.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.