Duty cycle in is similar to setup as period in. The difference is that duty cycle in returns two values, the number of clock cycles the signal is high and the number of cycles the signal is low packed into one 32 bit number. These two values, therefore, are 16 bit, so you'll need to pick a clock frequency and divisor that won't overflow the 65535 counts possible. Setting up these modes is just a matter of performing all the basic steps we've described:
1) Enable a Timer:
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 1, 0, 0)
2) Set the mode:
AddRequest(ID, LJ_ioPUT_TIMER_MODE, 0, LJ_tmDUTYCYCLE, 0, 0)
3) Set the clock frequency and divisor:
// use system clock so works on U3 and UE9:
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tcSYS, 0, 0)
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 48, 0, 0)
4) GoOne() to actually execute the commands:
GoOne(ID)
5) Create a channel to read the Timer. I/O Type is Timer, Channel # is the timer #, in this case 0.
The tricky part is actually parsing the data, since it is actually two different values packed into one number. The best way to do this is similar to the way we dealt with resetting counters, by creating extra, psuedo-channels to store the parsed data:
6) Create two more channels, one called TimeHigh, one called TimeLow. Device Type is Test, D# = 0, I/O Type = A to D, Chan # = 0 and most importantly, Timing = 0.
7) Click Apply to save your new channels, then click on the + next to CHANNELS: in the Workspace, then click on your Timer channel. We'll assume you called that channel RawDuty.
8) Click on the Event tab when the Channel view appears. Enter the follow script to parse the timer reading and click Apply:
TimeHigh.AddValue(RawDuty[0] % 0x10000) // LSW
TimeLow.AddValue(floor(RawDuty[0] / 0x10000)) // MSW
This will split the single 32 bit reading into two separate readings and place them in their own channels.