Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Clitches while chancing state ?


  • Please log in to reply
11 replies to this topic

#1 Per Hana

Per Hana
  • Members
  • 12 posts

Posted 14 September 2010 - 02:26 AM

I built a simple routine with FreeBasic, but did not get it working. Then I made some tries on Ubuntu command line: echo 1 > FIO6-dir cat FIO6 echo 0 > FIO6 cat FIO6 1 echo 0 > FIO6-dir cat FIO6 0 It seems that if I set a port output - input - output, the device sets the output register to '1' by itself. This causes a clitch to the output line. I tried to use U3 DIO-lines as opencollector like that I first set FIO4 to '0' and then send bits to open collector line with switching the line between HighImpedance '1' and LowImpedance '0' with FIO4-dir. I have done this with some microprocessors.

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 14 September 2010 - 08:52 AM

What firmware version are you using? Are you working through FUSE?

#3 Per Hana

Per Hana
  • Members
  • 12 posts

Posted 14 September 2010 - 09:46 AM

What firmware version are you using?

Are you working through FUSE?


FW = 1.32
Jup. I forgot to mention I have LJFuse.

#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 14 September 2010 - 11:32 AM

Two things here: 1) Whenever a line is set to input then changed to output the state will be high. 2) When the state of a DIO is written the dirrection is automatically set to output. So, if we change step 3 to write the state to zero we should get the desired result.

#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 14 September 2010 - 01:32 PM

Two things here:
1) Whenever a line is set to input then changed to output the state will be high.
2) When the state of a DIO is written the dirrection is automatically set to output.

So, if we change step 3 to write the state to zero we should get the desired result.


I apologize, but to follow this (correct) advice you'll need a new copy of LJFuse. Once you get the latest LJFuse, you'll be able to do:

$ echo 0 > FIO6-dir	 # Set FIO6 to digital input (hi-Z)
$ echo 0 > FIO6		 # Set FIO6 to digital output low


#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 14 September 2010 - 02:11 PM

Oh, and thanks a ton for showing what you wanted to do on the command line. That's a great thing about LJFuse: everyone can use the shell to communicate.

#7 Per Hana

Per Hana
  • Members
  • 12 posts

Posted 14 September 2010 - 11:59 PM

Two things here:
1) Whenever a line is set to input then changed to output the state will be high.
2) When the state of a DIO is written the dirrection is automatically set to output.

So, if we change step 3 to write the state to zero we should get the desired result.


I apologize, but to follow this (correct) advice you'll need a new copy of LJFuse. Once you get the latest LJFuse, you'll be able to do:

$ echo 0 > FIO6-dir	 # Set FIO6 to digital input (hi-Z)
$ echo 0 > FIO6		 # Set FIO6 to digital output low


Do you mean, that you wrote some new code to LJFuse after my last message ? COOL ;)
I don't have the device in my hands just now, so I got to ask, if you mean that the new procedure is:

1. echo 1 > FIO6-dir 'set dir=OUTPUT
2. echo 0 > FIO6 'set outp=LOW
3. echo 0 > FIO6-dir 'set dir=INPUT
4. echo 1 > FIO6-dir 'set dir=OUTPUT
- now the state is still 'outp=LOW' ?
Or should I add 'echo 0 > FIO6' between lines 3. and 4. ?

-------------------------------

A small academic sidenote: because the dir states are '0' for input and '1' for output, there is a small thing to remember:
I have to swap values '0' and '1' in my code to get '1' and '0' in the output pin, if I use DIO lines OC as I have told:

<pseudo FreeBasic Code>
' Using the output as OC with an external resistor

open FIO6-dir for output as#1 : print #1,1 : close 1 ' set dir=OUTPUT
open FIO6 for output as#1 : print #1,0 : close 1 ' set outp=LOW
' Now output pin = LOW

value=0 : set_putop(value) 'set dir=INPUT=HIGH IMPEDANCE
' Now outp pin=HIGH, even if we wanted 'value=0'
value=1 : set_putop(value) set dir=OUTPUT=LOW IMPEDANCE
' Now outp pin=LOW, even if we wanted 'value=1'

sub set_outp(outp as single)
open FIO6-dir for output as#1: print #1,outp:close 1 ' set outp value
end sub
</pseudo FreeBasic Code>

-- The sub_outp() has to be rewritten like this:

</pseudo FreeBasic Code>
sub set_outp(outp as single)
' Only for OC
if outp=0 then outp=1 else outp=0 ' swap '0' and '1'
open FIO6-dir for output as#1: print #1,outp:close 1 ' set outp value
end sub
</pseudo FreeBasic Code>

Of course we can not get all. In OpenDrain system or with a inverting OC buffer the original code gives the right state of pin.

---------------

And YES: LJFuse is great in testing, because you can use it straight from the command line.

#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 15 September 2010 - 08:39 AM

Do you mean, that you wrote some new code to LJFuse after my last message ? COOL ;)


Indeed. I like any excuse to improve LJFuse.

I don't have the device in my hands just now, so I got to ask, if you mean that the new procedure is:

1. echo 1 > FIO6-dir 'set dir=OUTPUT
2. echo 0 > FIO6 'set outp=LOW
3. echo 0 > FIO6-dir 'set dir=INPUT
4. echo 1 > FIO6-dir 'set dir=OUTPUT
- now the state is still 'outp=LOW' ?
Or should I add 'echo 0 > FIO6' between lines 3. and 4. ?


No, the procedure is much simpler. You want to toggle between output low and input. There's just one command needed for each.

Here's how to set FIO6 to output low:

$ echo 0 > FIO6

This always works because setting the state to low automatically sets the direction to output. This always works no matter what the current state and direction are.

Here's how to set FIO6 to input:

$ echo 0 > FIO6-dir

This, too, always works no matter what the current state and direction are.

Here's my attempt to rewrite your FreeBasic code. Don't laugh too hard.

<pseudo FreeBasic Code>
' Using the output as OC with an external resistor
open FIO6 for output as#1 : print #1,0 : close 1		' set outp to OUTPUT LOW
' Now output pin = LOW

value=1 : set_putop(value)			   'set dir=INPUT=HIGH IMPEDANCE
' Now outp pin=HIGH
value=0 : set_putop(value)			   set dir=OUTPUT=LOW IMPEDANCE
' Now outp pin=LOW

sub set_outp(outp as single)
' Only for OC
if outp=1 then 
	open FIO6-dir for output as#1: print #1,0:close 1   ' set outp to INPUT
else
	open FIO6 for output as#1 : print #1,0 : close 1	' set outp to OUTPUT LOW
end sub
</pseudo FreeBasic Code>

As you can see, you will use different files in the set_outp() function if you want to set the pin to input (FIO6-dir) or output (FIO6).

#9 Per Hana

Per Hana
  • Members
  • 12 posts

Posted 15 September 2010 - 03:31 PM

Do you mean, that you wrote some new code to LJFuse after my last message ? COOL ;)


Indeed. I like any excuse to improve LJFuse.

No, the procedure is much simpler. You want to toggle between output low and input. There's just one command needed for each.

Here's how to set FIO6 to output low:

$ echo 0 > FIO6

This always works because setting the state to low automatically sets the direction to output. This always works no matter what the current state and direction are.

Here's how to set FIO6 to input:

$ echo 0 > FIO6-dir

This, too, always works no matter what the current state and direction are.

Here's my attempt to rewrite your FreeBasic code. Don't laugh too hard.

As you can see, you will use different files in the set_outp() function if you want to set the pin to input (FIO6-dir) or output (FIO6).


I gave some simple tests to your code and it works !
Just now I'm too tired to go to acid tests, but it seems you have done it :)

If you are really in improving LJFuse, I'll throw you a challenge:
- How about the counters and timers ?
First I thought to add 'counters with triggers', but then I noticed, that the trigger can be built easier with an external NAND gate with one input from either external system or some port of LJ.
The timer is another thing. If you want to measure the duration of some phenomenon, you got to trig the timer more exactly than is possible while polling the ports via USB.
I dunno, if this is possible with LJ. Got to read the manual ;)
Using LJ as a counter and driver I can throw one VIC-20 with the special IO cards from the 'dual-chrystal-röentgen-spectroskope' I built as my MSc thesis. The device has been out of business for some years now.

You had just some normal typos in your FB code and 'end if' was missing. Of course we need the normal variable and sub function declarations, but I had left them out from my pseudocode too.
I corrected the typos, added the missing parts and compiled your code. It works fine :)
Basic is very powerful language because it is so simple. Most lab staff can write code after some hours testing. Besides, the mathematical syntax is rather easy. The bad thing is that the documentation of FB is in 'ethernal beta' stage.

#10 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 16 September 2010 - 09:07 AM

If you are really in improving LJFuse, I'll throw you a challenge:
- How about the counters and timers ?


We're going to try to expose timers and counters via LJFuse. We're going to try to do it via the modbus/ subdirectory, which you may have not looked in yet. Every file in that directory represents a register in our Modbus map that you can read or write to. There aren't files in LJFuse for the timers & counters bank of registers (the 7000 range), but we have an idea on how to elegantly add them. Stay tuned.

First I thought to add 'counters with triggers', but then I noticed, that the trigger can be built easier with an external NAND gate with one input from either external system or some port of LJ.
The timer is another thing. If you want to measure the duration of some phenomenon, you got to trig the timer more exactly than is possible while polling the ports via USB.
I dunno, if this is possible with LJ. Got to read the manual ;)


Yes, Section 2.9 of the U3 User's Guide describes all the available timer modes.

#11 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 16 September 2010 - 02:53 PM

If you are really in improving LJFuse, I'll throw you a challenge:
- How about the counters and timers ?


We're going to try to expose timers and counters via LJFuse. We're going to try to do it via the modbus/ subdirectory, which you may have not looked in yet. Every file in that directory represents a register in our Modbus map that you can read or write to. There aren't files in LJFuse for the timers & counters bank of registers (the 7000 range), but we have an idea on how to elegantly add them. Stay tuned.


OK, we did timers and counters in LJFuse and they work pretty well.

#12 Per Hana

Per Hana
  • Members
  • 12 posts

Posted 17 September 2010 - 02:47 PM

If you are really in improving LJFuse, I'll throw you a challenge:
- How about the counters and timers ?


We're going to try to expose timers and counters via LJFuse. We're going to try to do it via the modbus/ subdirectory, which you may have not looked in yet. ... Stay tuned.


OK, we did timers and counters in LJFuse and they work pretty well.


Oh my, I tought I'm throwing you a challenge, but you did it in some hours :)
Got to test it as soon as I have a spare moment -about 4 weeks from now.
It seems that there is a good reason to stay tuned with LabJack.

I have had no time to look around me. I'm in extremely tight timetable. The product should be built, tested, callibrated and in a case in one week. And most parts are still coming.
I have to say that those modifications you have made to LJFuse, have saved me many hours, possibly days.
In the next project I will look in the modbus material. So far I have only had a quick view of it.

LJ has returned the fun of programming I have lost since VIC-20 and C64 ;)


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users