using Pulse Out for a relais/switch | LabJack
 

using Pulse Out for a relais/switch

16 posts / 0 new
Last post
momberg
momberger's picture
using Pulse Out for a relais/switch

Hallo, I would like to use the Pulse Out-Feature of my T7 to switch a relais, but I'm not quite shure what it actually does. I did read the instruchtions:
https://labjack.com/support/datasheets/t7/digital-io/extended-features/pulse-out

.. So lets make an example: "Switch a relais every second"
--clock-setup:
DIO_EF_CLOCK0_DIVISOR = 8
DIO_EF_CLOCK0_ROLL_VALUE = 10000000
DIO_EF_CLOCK0_ENABLE = 1
 --f_core = 80MHz = 80.000.000
 --f_clock = f_core/(div*roll_clock) = 1Hz
 --t_clock = 1/f_clock = (div*roll_clock)/f_core = 1s

--pulse-setup:
--adjust duty cycle to output FIO0
roll0 = roll_clock*2  --> f_switch=f_clock/2=0.5Hz, t_switch=t_clock*2=2s-switching

MB.W(44000,1,0)   --DIO0_EF_ENABLE = 0

MB.W(2000,0,0)   --DIO0 = 0                  // set DIO0 to output-low

MB.W(44100,1,2)   --DIO0_EF_INDEX = 2         // pulse out type index

MB.W(44300,1,roll0/2)  --DIO0_EF_CONFIG_A = 50000  // high to low count

MB.W(44400,1,roll0/2)  --DIO0_EF_CONFIG_B = 0      // low to high count

MB.W(44500,0,roll0)  --DIO0_EF_CONFIG_C = 50000  // number of pulses

MB.W(44000,1,0)   --DIO0_EF_ENABLE = 1


.. and here are my questions:
1. Which pin is being set to "high/low"? is it the DIO0-Pin with the ModBus adress '2000'? Or is it the DIO1_EF_ENABLE pin with the ModBus adress '44000'?
2. what does 'high/low' mean? does that mean that the pin has '5V/0V'?
3. If I run the example code, would I have a pattern of 1s-5V and 1s-0V on DIO0-pin '2000' (i.e. changing the voltage each second from 0V to 5V)?
4. If I change the example as follows:
 MB.W(44300,1,roll0)  --DIO0_EF_CONFIG_A = 50000  // high to low count

 MB.W(44400,1,0)   --DIO0_EF_CONFIG_B = 0      // low to high count

is the DIO0-pin '2000' on high (5V) all the time or is there a small gap (i.e. voltage drop to 0V) when the counter restarts at '0' (DIO0_EF_CONFIG_B = 0)?

thank you a lot for your help. I really appreciate it!

LabJack Support
labjack support's picture
1.  You are enabling the

1.  You are enabling the pulse out feature on DIO0.  DIO0_EF_ENABLE is not a pin, but rather is just a register that controls whether DIO-EF is enabled on DIO0.

2.  The line will be switched between output-high (3.3V) and output-low (0V).  See "Electrical Overview" in Section 13.0 of the T7 Datasheet.

3.  Your clock is 10 MHz, so with DIO0_EF_CONFIG_A=50000 and DIO0_EF_CONFIG_B=0 you will get DIO0/FIO0 high for 50000 ticks (5000 microseconds), and then low for the remaining 9950000 ticks (995000 microseconds).

4.  I'm afraid I don't understand what you are asking here.

momberg
momberger's picture
Hmm.. do I miss something?!

Hmm.. do I miss something?!

.. So, the switching works but I don't understand how to set the switching time. From my understanding, this should be valid:

--clock-setup:

--f_core = 80MHz = 80.000.000 = 8e+7

--f_clock = f_core/(div*roll_clock)

--t_clock = 1/f_clock = (div*roll_clock)/f_core

--> So if I set div=8 and roll_clock=1e+7
f_clock = 8e+7/(8*1e+7)Hz=1Hz --> t_core = 1000ms

That means that one clock-tick occurs every second. Is that right?


Now the part that I might got wrong. I guess I do not understand what the 'DIO0_EF_CONFIG_C'-value is for and how it relates to 'DIO0_EF_CONFIG_A' and 'DIO0_EF_CONFIG_B'.
Possibility 1:
'DIO0_EF_CONFIG_C' is an absolute number of pulses to generate and not related to the Pulse frequency.
If e.g. 'DIO0_EF_CONFIG_C' is set to 5, there will be performed just 5 pulses and than PulseOut will be disabled.

Possibility 2: (this is what I assumed)
'DIO0_EF_CONFIG_C' is a second ROLL_VALUE specifying the Pulse-frequency, so the following calculations are valid:

roll_pulse = roll_clock/2
DIO0_EF_CONFIG_A = roll_pulse/2
DIO0_EF_CONFIG_B = roll_pulse/2
DIO0_EF_CONFIG_C = roll_pulse
-->f_switch = f_core/(div*roll_pulse) = f_clock * (roll_clock/roll_pulse)
 = 2*f_clock
-->t_switch = (div*roll_clock)/f_core * (roll_pulse/roll_clock) = t_clock * (roll_pulse/roll_clock) = t_clock/2

.. So, what is right?

Thank you for your help!

LabJack Support
labjack support's picture
--> So if I set div=8 and

--> So if I set div=8 and roll_clock=1e+7
f_clock = 8e+7/(8*1e+7)Hz=1Hz --> t_core = 1000ms

That means that one clock-tick occurs every second. Is that right?

That means the Pulse Out Frequency is 1 Hz, or the Pulse Out Period is 1000ms.

The clock is 80M/8 = 10 MHz, so a clock tick occurs every 100ns.

The formula given in Section 13.1.4 is:

PulseOutFrequency = 80M / (DIO_EF_CLOCK#_DIVISOR * DIO_EF_CLOCK#_ROLL_VALUE)

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

Config-C is the number of pulses, so if you set that to 5 you will only get 5 pulses.  If you want continuous pulses use PWM.

momberg
momberger's picture
Ok, almost there, but here's

Ok, almost there, but here's the catch:
I actually want to use three different switches with three different switching times. So here are my thoughts:


Let's use Clock0 with div=8 --> 10MHz Clock-freq.
now define a Roll Value of roll=1.0e+7 --> 1Hz Pulse-freq.

SWITCH 1:
So, if I now configure DIO0_EF_CONFIG_A=roll/2 I will get 50% duty-cycle, so for the first 5.0e+6 ticks the DIO will be on 3.3V and the remaining 5.0e+6 ticks of the roll-cycle, the DIO will be on 0V.
--> switching time of the first relais is now every 500ms
--> would it here make any difference if I would set DIO0_EF_CONFIG_B=roll/2 or leave it on DIO0_EF_CONFIG_B=0?

SWITCH 2:
Please correct me if I'm wrong, but I assume that the 'DIO0_EF_CONFIG_B'-register is a possibility to manipulate the PulseOut-frequency, as it provides in combination with the 'DIO0_EF_CONFIG_A'-register multiple High-/Low-Transitions within one Roll-Cycle.
So, if I now configure
DIO0_EF_CONFIG_A=roll/4
DIO0_EF_CONFIG_B=roll/4
I will also get 50% duty-cycle, but within one Roll-Cycle there will be four Transitions:
0 to 2.5e+6-1 --> high
2.5e+6 to 5e+6-1 --> low
5e+6 to 7.5e+6-1 --> high
7.5e+6 to 1.0e+7-1 --> low
--> switching time of the 2nd relais is now every 250ms
--> If this assumption holds true, I could further devide the Pulse-frequency by symmetrical division of the two 'DIO0_EF_CONFIG_A'- & 'DIO0_EF_CONFIG_B'-registers.

SWITCH 3:
DIO0_EF_CONFIG_A=roll/10
DIO0_EF_CONFIG_B=roll/10
--> switching time of the 3rd  relais is now every 100ms

In Summary, that means that the Pulse-Out-Feature is like the PWM-Out-Feature, but the Pulse-Out-Feature can change both, dudy-cycle and 'base'-Frequency. Is that correct?


Now, let's assume I'm wrong, but I want to be able to have three different switching times for my relaises. How can I achieve this? Can I use all three Clocks at the same Time (Clock0-Clock2)? I just found the registers for Clock0, that I can use for setup (44900-44908). How do I set up the other 2 clocks?

Thank you for your Help.

LabJack Support
labjack support's picture
--> would it here make any

--> would it here make any difference if I would set DIO0_EF_CONFIG_B=roll/2 or leave it on DIO0_EF_CONFIG_B=0?

Setting config-b = config-a is not defined.  You would be trying to set the line high and low at the same time.

The most common way to use PulseOut and PWM is to set config-b to 0 and then you know:

DutyCycle% = 100 * DIO#_EF_CONFIG_A / DIO_EF_CLOCK#_ROLL_VALUE

The reason to use a non-zero config-b is to get a phase difference between 2 pulse outputs.  For example, if you configured another pulse output with config-a=0.75*roll and config-b=0.25*roll, that 2nd pulse train would have the same 50% duty cycle as your original pulse train but would be 90 degrees out of phase.

SWITCH 2:
Please correct me if I'm wrong, but I assume that the 'DIO0_EF_CONFIG_B'-register is a possibility to manipulate the PulseOut-frequency, as it provides in combination with the 'DIO0_EF_CONFIG_A'-register multiple High-/Low-Transitions within one Roll-Cycle.

No.  Config-b defines a singular tick value at which the line will transition to high.  It does not go high at every multiple of config-b, just the one time the clock hits config-b as it ticks from 1 to 10000000.

Now, let's assume I'm wrong, but I want to be able to have three different switching times for my relaises. How can I achieve this?

Do you need different duty cycles (on/off times), frequencies, or both?

If you just need different duty cycles use 3 different PulseOut or PWM channels.

If you need different frequencies, that is difficult using the DIO-EF system.  You can get 2 different frequencies by using Clock1 and Clock2 rather than Clock0, but they are just 16-bit clocks so your available frequencies will be much more limited:

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

The other thing to look at is alternate methods of creating your switch signals:

https://labjack.com/support/app-notes/waveform-generation

momberg
momberger's picture
I in deed need different

I in deed need different frequencies, as my derired duty-cycle is 50% for every Switch. I already studied the given link:

https://labjack.com/support/datasheets/t7/digital-io/extended-features/ef-clock-source

But I still not know how to set up Clock1 and clock2, as there are no dedicated Registers described. Please help.

LabJack Support
labjack support's picture
Clock1 and Clock2 have the

Clock1 and Clock2 have the same registers as Clock0.  To see them go to the modbus map and put "dio_ef_clock" in the modbus map Search box:

https://labjack.com/support/software/api/modbus/modbus-map

Look at the "Configure" section in 13.1.1.  It is describing the DIO_EF_CLOCK#_ registers that apply to any of the 3 clocks.

Note that using Clock1 and Clock2 you can get 2 different frequencies, with a more limited frequency range since roll value is only 16-bit.  Since you need 3 different frequencies you will likely have to consider one of the other techniques from the Waveform Generation app note.

AA
arrigo's picture
I'm trying to do a similar

I'm trying to do a similar things, but i need to use sinking configuration for generating a single pulse with precise duration (from 20 to 600 nanoseconds). Is it possible directly with a LUA script?

I've already tried link  but with standard configuration.

 

Thanks in advance for your help!

LabJack Support
labjack support's picture
A Lua script does not have

A Lua script does not have that sort of time ability.  You need to use hardware somehow.

Try the Wait technique:

http://labjack.com/support/app-notes/waveform-generation#WaitTechnique

I would expect it to peform similar whether you send the command packet from a host or use on-board Lua.

 

AA
arrigo's picture
Thnak you very much for your

Thnak you very much for your help.

If i understand correctly i should use LJM_eNames and send a single MODBUS packet with different instructions so T7 will execute continuously and only after the end of the packet will communicate with PC.

Is there a LUA porting of this function (like MB.WA or MB.RA)?

For a simpler solution, i thought about https://labjack.com/support/datasheets/t-series/digital-io/extended-features/pulse-out that i've already used but i don't know if should work correctly with sinking configuration (you cannot change direction during pulse)

 

Thanks in advance for you precious support

AA
arrigo's picture
Tried with sinking config too

Tried with sinking config too but it doesn't work with the following script

 

local count = 0
local high = 0
local mbwrite=MB.writeName
local mbread=MB.readName

LJ.IntervalConfig(0, 1000)      --set interval to 1000 for 1000ms
local checkInterval=LJ.CheckInterval

local outPin = 2003--FIO3. Changed if T4 instead of T7


--suppress truncation warning
mbwrite("LUA_NO_WARN_TRUNCATION", 1)

--disable clock
mbwrite("DIO_EF_CLOCK0_ENABLE",0)
-- set divisor 1
mbwrite("DIO_EF_CLOCK0_DIVISOR",1)
-- set roll value 0=max roll value
mbwrite("DIO_EF_CLOCK0_ROLL_VALUE",100000000)
--enable clock
mbwrite("DIO_EF_CLOCK0_ENABLE",1)

 

--disable DIO for config
mbwrite("DIO0_EF_ENABLE",0)
--set DIO output low
LJ.DIO_S_W(0,0)

print("clock config done and running")

--set pulse type
mbwrite("DIO0_EF_INDEX",2)
--set high-to-low , every step=12.5ns so 200ns=insert 200/12.5=16
mbwrite("DIO0_EF_CONFIG_A",80000000)
--set low-to-high
mbwrite("DIO0_EF_CONFIG_B",4000)
--set number of pulse
mbwrite("DIO0_EF_CONFIG_C",100)
--enable pulse
mbwrite("DIO0_EF_ENABLE",1)

LabJack Support
labjack support's picture
single pulse with precise

single pulse with precise duration (from 20 to 600 nanoseconds). Is it possible directly with a LUA script?

No. Lua can not produce pulses with the requested resolution. Depending on the constraint that you ran into with pulse-out, You may need to use an inverting gate or buffer on the output of a pulse-out DIO_EF mode. Pulse-out allow you to specify when the line goes high and low relative to the SourceClock. That should allow you to create a very low or nigh duty cycle PWM.

 

 

AA
arrigo's picture
OK, thank you,

OK, thank you,

i'm trying to use standard pulse out feature with logic level shifter (TI TXS0108E).

I cannot drive my load, could T7 drive a 50 Ohm load with pulse feature (pulse length 100ns)?

I've checked with AIN and shifter works well

LabJack Support
labjack support's picture
The T7 has 470 Ω in series

The T7 has 470 Ω in series with FIO pins and 100 Ω in series with EIOs. On EIO, a 50 Ω load will create a voltage divider with an output ratio of 0.33, which is ~1.1V for a high. If you need to put 5 V on that 50 Ω load then we need a switch which can handle at least 100 mA. There are a few options here:

If you are not familiar with Electrical Engineeing then a relay or the PS12DC will be easier than the other two options.

AA
arrigo's picture
Thanks for your invaluable

Thanks for your invaluable support.

I forgot to post the solution that i used:

I bought some ultra-cheap series74 TTL and put in parallel for driving a 5V / 50Ω load.

It works perfectly, tested for many hours, and, if TTL has a trigger-schmitt input, improve peaks of the square wave.