pwm-prescaler-set

gst/pwm-prescaler-set/pwm-prescaler-set

No description
pwm-prescaler-set
@/pwm-prescaler-set
INIT_1pulse
switches the prescaler to divisor 1 (highest frequency)
INIT_2pulse
switches the prescaler to divisor 8
INIT_3pulse
switches the prescaler to divisor 64
INIT_4pulse
switches the prescaler to divisor 256
INIT_5pulse
switches the prescaler to divisor 1024 (lowest frequency)
Timernumber
0 -5 = choise timer 0-5
pwm-prescaler-set
DONE
INIT_1
INIT_2
INIT_3
INIT_4
INIT_5
Timer
DONEpulse
Spits a pulse when done
To use the node in your project you should have the gst/pwm-prescaler-set 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

#pragma XOD require "https://github.com/terryjmyers/PWM"

{{#global}}
#include <PWM.h>
{{/global}}

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {

Number Tmr = getValue<input_Timer>(ctx);

     

    
  
    
    
    
    
    
    
    
    
    
    
     if (isInputDirty<input_INIT_1>(ctx) 
     &&  (Tmr == 0))
      Timer0_SetPrescaler (1);
 
     if (isInputDirty<input_INIT_2>(ctx)
     &&  (Tmr == 0))
      Timer0_SetPrescaler (2);
    
     if (isInputDirty<input_INIT_3>(ctx)
     &&  (Tmr == 0))  
      Timer0_SetPrescaler (3);
 
     if (isInputDirty<input_INIT_4>(ctx) 
     &&  (Tmr == 0))
      Timer0_SetPrescaler (4);
    
     if (isInputDirty<input_INIT_5>(ctx)
     &&  (Tmr == 0))
      Timer0_SetPrescaler (5);
    
    
    
     if (isInputDirty<input_INIT_1>(ctx) 
     &&  (Tmr == 1))
      Timer1_SetPrescaler (1);
 
     if (isInputDirty<input_INIT_2>(ctx)
     &&  (Tmr == 1))
      Timer1_SetPrescaler (2);
    
     if (isInputDirty<input_INIT_3>(ctx)
     &&  (Tmr == 1))  
      Timer1_SetPrescaler (3);
 
     if (isInputDirty<input_INIT_4>(ctx) 
     &&  (Tmr == 1))
      Timer1_SetPrescaler (4);
    
     if (isInputDirty<input_INIT_5>(ctx)
     &&  (Tmr == 1))
      Timer1_SetPrescaler (5);
    
    
     if (isInputDirty<input_INIT_1>(ctx) 
     &&  (Tmr == 2))
      Timer2_SetPrescaler (1);
 
     if (isInputDirty<input_INIT_2>(ctx)
     &&  (Tmr == 2))
      Timer2_SetPrescaler (2);
    
     if (isInputDirty<input_INIT_3>(ctx)
     &&  (Tmr == 2))  
      Timer2_SetPrescaler (3);
 
     if (isInputDirty<input_INIT_4>(ctx) 
     &&  (Tmr == 2))
      Timer2_SetPrescaler (4);
    
     if (isInputDirty<input_INIT_5>(ctx)
     &&  (Tmr == 2))
      Timer2_SetPrescaler (5);
    
    
     if (isInputDirty<input_INIT_1>(ctx) 
     &&  (Tmr == 3))
      Timer3_SetPrescaler (1);
 
     if (isInputDirty<input_INIT_2>(ctx)
     &&  (Tmr == 3))
      Timer3_SetPrescaler (2);
    
     if (isInputDirty<input_INIT_3>(ctx)
     &&  (Tmr == 3))  
      Timer3_SetPrescaler (3);
 
     if (isInputDirty<input_INIT_4>(ctx) 
     &&  (Tmr == 3))
      Timer3_SetPrescaler (4);
    
     if (isInputDirty<input_INIT_5>(ctx)
     &&  (Tmr == 3))
      Timer3_SetPrescaler (5);
    
    
     if (isInputDirty<input_INIT_1>(ctx) 
     &&  (Tmr == 4))
      Timer4_SetPrescaler (1);
 
     if (isInputDirty<input_INIT_2>(ctx)
     &&  (Tmr == 4))
      Timer4_SetPrescaler (2);
    
     if (isInputDirty<input_INIT_3>(ctx)
       &&  (Tmr == 4))  
      Timer4_SetPrescaler (3);
 
     if (isInputDirty<input_INIT_4>(ctx) 
     &&  (Tmr == 4))
      Timer4_SetPrescaler (4);
    
     if (isInputDirty<input_INIT_5>(ctx)
     &&  (Tmr == 4))
      Timer4_SetPrescaler (5);
    
    
     if (isInputDirty<input_INIT_1>(ctx) 
        &&  (Tmr == 5))
      Timer5_SetPrescaler (1);
 
     if (isInputDirty<input_INIT_2>(ctx)
     &&  (Tmr == 5))
      Timer5_SetPrescaler (2);
    
     if (isInputDirty<input_INIT_3>(ctx)
       &&  (Tmr == 5))  
      Timer5_SetPrescaler (3);
 
     if (isInputDirty<input_INIT_4>(ctx) 
     &&  (Tmr == 5))
      Timer5_SetPrescaler (4);
    
     if (isInputDirty<input_INIT_5>(ctx)
     &&  (Tmr == 5))
      Timer5_SetPrescaler (5);
    
    
    
  //  ATMEGA 2560 
  //  Timer0 = D4 and D13 Attention! Timer0 is also used for other tasks (millis, micros, delay).
  //  Timer1 = D11, D12
  //  Timer2 = D9, D10
  //  Timer3 = D2, D3, D5
  //  Timer4 = D6, D7, D8
  //  Timer5 = D44, D45, D46
 
  

  //  Prescaler 1= 31372,55Hz, 2= 3921,16Hz, 3= 490Hz, 4= 122.55Hz 5= 30Hz (in case of timer0 the PWM frequency for prescaler values 1-5 are doubled)
  //  Timer1_SetPrescaler (2);
  //  Timer2_SetPrescaler (2);
  //  Timer3_SetPrescaler (2);
  //  Timer4_SetPrescaler (2);
  //  Timer5_SetPrescaler (2);
  
   
    
    emitValue<output_DONE>(ctx, 1);
};