hr-fast-pwm

hussainfawzi/fast-pwm/hr-fast-pwm

No description
hr-fast-pwm
@/hr-fast-pwm
PORTport
Select the Port to use for PWM
FREQUENCYnumber
Set the frequency (range 0Hz - 500kHz)
DUTYnumber
Set the duty cycle (range 0 - 65535)
UPDATEpulse
Feed a pusle along with required frequency and duty cycle.
hr-fast-pwm
PORT
FREQUENCY
DUTY
UPDATE
DONE
DONEpulse
Spits a pulse when done
To use the node in your project you should have the hussainfawzi/fast-pwm library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
     if (!isInputDirty<input_UPDATE>(ctx))
        return;
    const uint8_t port = getValue<input_PORT>(ctx);
    if (!isValidDigitalPort(port)) {
        raiseError(ctx);
        return;
    };
    auto duty = getValue<input_DUTY>(ctx);
    if(duty>65535){duty=65535;}
    if(duty<0){duty=0;}
    auto freq = getValue<input_FREQUENCY>(ctx);
    SetPinFrequencySafe(port, freq);
    pwmWriteHR(port, duty);
    emitValue<output_DONE>(ctx, 1);
};