Multiple PWM outputs with different frequencies. | LabJack
 

Multiple PWM outputs with different frequencies.

8 posts / 0 new
Last post
stuartdye
stuartdye's picture
Multiple PWM outputs with different frequencies.

Hi I have been playing around with PWM signals on the T7 for a while now and I can get multiple PWM signals with the same frequency. However I need multiple PWM signals with different frequencies.

I have read the documentation on the 3 clock sources available on the T7 but I am left a little confused. I am aware that CLOCK1 and CLOCK2 are part of CLOCK0 somehow and I'm not sure that these can be used separately and simultaneously.

If you are able to provide any insight on this subject that would be much appreciated.

Thanks,

Stuart.

LabJack Support
labjack support's picture
Basically you use Clock0 or

Basically you use Clock0 or you use Clock1 & Clock2.  Using 1 & 2 at the same time as 0 is complex and not really supported, but is mentioned in the "Advanced" section towards the end of 13.1.1:

https://labjack.com/support/datasheets/t7/digital-io/extended-features/e...

So to get 2 different PWM frequencies you use Clock1 with one PWM and Clock2 with the other PWM.  The downside to Clocks 1 & 2 is that they are 16-bit, which means ROLL_VALUE is limited to 0-65535, which affects the formulas to set PWMFrequency and DutyCycle:

https://labjack.com/support/datasheets/t7/digital-io/extended-features/p...

stuartdye
stuartdye's picture
Hi, thanks for the reply.

Hi, thanks for the reply.

How would I set which clock goes to what PWM?

Thanks,

Stuart.

stuartdye
stuartdye's picture
Just figured it out, thanks.

Just figured it out, thanks.

Stuart.

Dan
Dan_leb's picture
Hi, I can get multiple PWM

Hi, I can get multiple PWM signals with the difference frequency. In fact, I'm sending two square waves with clock 1 and one square wave with a different duty cycle with clock 2 (whose frequency is the (frequency of clock 1) /2). I'm trying to have the rising edge of my signal from the two clocks at the same time. I think I have to use Stream_out, but I can't synchronize my signals. I'm using Matlab and here is a part of my code:

LabJack.LJM.eWriteName(handle, 'STREAM_OUT0_ENABLE', 0);% Disable clock source (Must be disabled during configuration: 1 = enabled. 0 = disabled)

LabJack.LJM.eWriteName(handle, 'STREAM_OUT0_TARGET',2500); 

LabJack.LJM.eWriteName(handle, 'STREAM_OUT0_BUFFER_SIZE', 1024);

LabJack.LJM.eWriteName(handle, 'STREAM_OUT0_ENABLE', 1);

LabJack.LJM.eWriteName(handle, 'STREAM_OUT0_LOOP_SIZE', 16 )

LabJack.LJM.eWriteName(handle, 'STREAM_OUT3_ENABLE', 0);% Disable clock source (Must be disabled during configuration: 1 = enabled. 0 = disabled)

LabJack.LJM.eWriteName(handle, 'STREAM_OUT3_TARGET', 2500); 

LabJack.LJM.eWriteName(handle, 'STREAM_OUT3_BUFFER_SIZE', 1024);

LabJack.LJM.eWriteName(handle, 'STREAM_OUT3_ENABLE', 1);

LabJack.LJM.eWriteName(handle, 'STREAM_OUT3_LOOP_SIZE', 16 )

LabJack.LJM.eWriteName(handle, 'STREAM_OUT0_SET_LOOP', 1) %Use new data immediately.

% Configure Clock Registers:

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK1_ENABLE', 0);  % Disable clock source (Must be disabled during configuration: 1 = enabled. 0 = disabled)

% Set CLOCK1's divisor and roll value to configure frequency: 80MHz/256/31250 = 10Hz

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK1_DIVISOR', Divisor_LED);  % Configure CLOCK1's divisor

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK1_ROLL_VALUE',Roll_Value_LED);  % Configure CLOCK1's roll value

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK1_ENABLE', 1); % Enable the clock source

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK2_ENABLE', 0);  % Disable clock source (Must be disabled during configuration: 1 = enabled. 0 = disabled)

% Set CLOCK2's divisor and roll value to configure frequency: 80MHz/256/31250 = 10Hz

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK2_DIVISOR', Divisor_Cam);  % Configure CLOCK2's divisor

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK2_ROLL_VALUE',Roll_Value_Cam);  % Configure CLOCK2's roll value

LabJack.LJM.eWriteName(handle, 'DIO_EF_CLOCK2_ENABLE', 1); % Enable the clock source

% Configure EF Channel Registers:

% FIO3 - LED470

LabJack.LJM.eWriteName(handle, 'DIO0_EF_ENABLE', 0);  % Disable the EF system for initial configuration

LabJack.LJM.eWriteName(handle, 'DIO0_EF_INDEX',0);  % Configure EF system for PWM (An index to specify the feature you want)

LabJack.LJM.eWriteName(handle, 'DIO0_EF_OPTIONS', 1);  % Configure what clock source to use: CLOCK1 (0 = CLOCK1, 1 = Clock1, and 2 = Clock2)

LabJack.LJM.eWriteName(handle, 'DIO0_EF_CONFIG_A', ConfigLED);  % Configure duty cycle to be: 50% (Function dependent on selected feature index.)

LabJack.LJM.eWriteName(handle, 'DIO0_EF_ENABLE', 1);  % Enable the EF system, PWM wave is now being outputted

% FIO4 - LED410

LabJack.LJM.eWriteName(handle, 'DIO2_EF_ENABLE', 0);  % Disable the EF system for initial configuration

LabJack.LJM.eWriteName(handle, 'DIO2_EF_INDEX', 1);  % Configure EF system for PWM (An index to specify the feature you want)

LabJack.LJM.eWriteName(handle, 'DIO2_EF_OPTIONS', 1);  % Configure what clock source to use: CLOCK1 (0 = CLOCK1, 1 = Clock1, and 2 = Clock2)

LabJack.LJM.eWriteName(handle, 'DIO2_EF_CONFIG_A', 0);  % Configure duty cycle to be: 50% (Function dependent on selected feature index.)

LabJack.LJM.eWriteName(handle, 'DIO2_EF_CONFIG_B', ConfigLED);

LabJack.LJM.eWriteName(handle, 'DIO2_EF_ENABLE', 1);  % Enable the EF system, PWM wave is now being outputted

% FIO5 - Camers

LabJack.LJM.eWriteName(handle, 'DIO3_EF_ENABLE', 0);  % Disable the EF system for initial configuration

LabJack.LJM.eWriteName(handle, 'DIO3_EF_INDEX', 0);  % Configure EF system for PWM

LabJack.LJM.eWriteName(handle, 'DIO3_EF_OPTIONS', 2);  % Configure what clock source to use: CLOCK2

LabJack.LJM.eWriteName(handle, 'DIO3_EF_CONFIG_A', ConfigCam); 

LabJack.LJM.eWriteName(handle, 'DIO3_EF_ENABLE', 1); 

Here are the signals I get from FIO0 on top and FIO3 below. I want my pulse at the same time of my rising edge.

Thanks, 

Dan

LabJack Support
labjack support's picture
If you want two PWMs with

If you want two PWMs with different frequencies then their rising edges will not normally line up. Occasionally the numbers might work out such that the rising edges occur at the same time, but in general they will not unless one frequency is an even multiple of the other.

If one signal has twice the frequency of the other then you may be able to get them pretty close. You would need to configure both clocks in one packet (eWriteNames) with the two enable register writes adjacent to each other. Then there will be a small offset but you could account for that using PWM with phase.

Another option is a hardware circuit that divides the frequency by two. That would simply toggle the slower frequency's line every time there is a pulse on the faster line.

JV
JV's picture
Dear LabJack support team,

Dear LabJack support team,

regarding a PWM output signal with 50% duty at 50 Hz, is it better to use clock 1 with divisor 32 or clock 0 with divisor 1? I am still not sure about the impact of the roll value on my application. 

 

Thanks a lot!!

LabJack Support
labjack support's picture
CLOCK0 is a 32-bit clock

CLOCK0 is a 32-bit clock while CLOCK1 & CLOCK2 are 16-bit clocks.  CLOCK0 is actually made from the combination of CLOCK1 & CLOCK2 internally. 

https://labjack.com/support/datasheets/t-series/digital-io/extended-feat...

What this means is that the roll value is only a 16-bit value for CLOCK1 & CLOCK2, and the impact of that is reflected by the equations near the beginning of the PWM out page:

https://labjack.com/support/datasheets/t-series/digital-io/extended-feat...

So a couple options for 50 Hz are:

Clock0Frequency = 80M / 1 = 80M
PWMFrequency = 80M / 1600000 = 50
DutyCycle% = 100 * 800000 / 1600000 = 50%

Clock1Frequency = 80M / 32 = 2.5M
PWMFrequency = 2.5M / 50000 = 50
DutyCycle% = 100 * 25000 / 50000 = 50%

Both of these seem fine.  Roll value determines duty cycle resolution, so the clock0 scenario has much higher resolution, but the 50000 parts of resolution for the clock1 scenario seems like plenty.

Where it really starts to make a difference is if you then go to do something else with the same clock source.  Say you use the Frequency In feature for the clock1 scenario:

https://labjack.com/support/datasheets/t-series/digital-io/extended-feat...

Resolution(s) = 1 / 2500000 = 400 ns
Max Period(s) = 50000 / 2500000 = 20 ms => 50 Hz

So the resolution here is great, but the minimum frequency you can measure in this case is 50 Hz.