RTC Website

Programming the myRIO PWM outputs

TX

Some myRIO DIO lines can be optionally configured to generate pulse-width modulation (PWM) signals at rates up to \(40\) kHz (Instruments 2020). Each of the A and B connectors have three and the C connector has two PWM lines. The myRIO C library includes several functions for programming these interfaces (see PWM.h and PWM.c). The T1 library includes an additional wrapper function, pwm_set, as to simplify the programming interface. From pwm-wrapper.h, the prototype is

int pwm_set(MyRio_Pwm* pwm,
            MyRio1900Fpga60_ControlU8 reg,
            double duty);

The first argument pwm is a pointer reference to a PWM channel struct type MyRio_Pwm, defined in PWM.h. The following could be used to configure the A connector PWM0 pin for PWM:

MyRio_Pwm pwmA0;
pwmA0.cnfg = PWMA_0CNFG;
pwmA0.cs = PWMA_0CS;
pwmA0.max = PWMA_0MAX;
pwmA0.cmp = PWMA_0CMP;
pwmA0.cntr = PWMA_0CNTR;

Note that not pwmA0, but a pointer thereto, should be passed to pwm_set, (i.e., &pwmA0). Other PWM channels have constants defined in the myRIO C library header MyRio1900.h.

The second argument reg of pwm_set is the register corresponding to the connector chosen for the pwm channel argument. In the example given here, we chose an A connector, so we would use

MyRio1900Fpga60_ControlU8 reg = SYSSELECTA;

For B and C connectors, reg would be SYSSELECTB and SYSSELECTC, which are defined in MyRio.h.

The third argument duty of pwm_set is the duty cycle of the PWM waveform. It is of type double and should be in the interval \([0,1]\). The duty cycle resolution is \(0.001\), but the function handles any double in the interval.

The frequency of the PWM will be set to its maximum, \(40\) kHz. Lower PWM frequencies can be generated with the functions provided by the myRIO C library’s PWM.h header, but the pwm_set wrapper function does not support this.

fpgaPersonality6

Instruments, National. 2020. “myRIO Shipping Personality 6.0 Reference.” Web. https://www.ni.com/en-us/support/documentation/supplemental/13/myrio-shipping-personality-reference.html.

Online Resources for Section G.1

No online resources.