K8061 somehow 'freezes' reading...?

Hello!

I am using the K8061 USB interface board to do some reading using all the digital inputs. Actually, I have 64 bits, which is read eight by eight.

To control this, I let three analog outputs generate at binary pattern for 0, 1, 2 up to 7 (like: 000, 001, 010, 011 …etc.).

It is cycling ‘forever’, and reading at a speed of 3 readings of all 64 bits a second. This means, the output is changing 24 times a second.

I understand there is a small delay, from I set the output on the analog channel, to the channel is actually set on the board.
So I connected the three analog outputs to three analog inputs.
This way I can determine when the setting actually has taken place, and then read the digital inputs.

So far so good. It work fine - for approximately 100.000 cycles.

Then it somehow freezes. With my voltmeter I can see, that the analog channels is set, but the reading of the three analog input-channels says it is not (?).

When this happens, I can see the reading of the eight digital inputs are the same as the reading before, even though I can measure they have changed.

If I leave the things waiting, sometimes it starts up again. But I have to wait for - sometimes seconds, sometimes hours. This is not quite satisfying.

I have tried different things, but (software-)disconnecting and reconnecting doesn’t work. When disconnected the card won’t reconnect.
Stopping the entire program, and restart doesn’t work either.
I can pull the USB-cable and the power cable, and reconnect them. Sometimes it starts up again, and will run for another 100.000 cycles.

I have run out of ideas. Only thing left is this ‘PWM’-thing. I have not tried to do anything with this, as I haven’t the slightest idea about what it does.

Can anybody in here give me a hint?

(And what is this PWM? Does it need a setting I don’t know about?)

Sorry for the long speech, and many thanks in advance.

It seems that the USB communication stops for some reason.
Have you tested with the DLL from the package k8061_vistapack_2007v1.zip ?
If you have - is there any difference between the behavior of this version and the original DLL on the CD?

Have you tried some small delay in between the DLL requests?

Can you put some of your main code (source) here for testing.

Hello again,

Thanks for the reply.
I forgot to mention, I use WinXP and Visual Studio, C#.
I have not tried actually delays, from when I set the output till I read the input.

Here comes some of the code. I pretty much describes the basics of what I try to do:
As you see, OutputAnalogChannel 1, 2 and 3 starts with 0,0,0.
Then I count it up: 001, 010, 011, 100, 101, 110, 111.

The read_service_loop is called from a tread running infinitely.
When it returns because of a timeout, it shows the number of timeouts in a textbox, and stort over again from the beginning (0,0,0) in hope of this would clear the problem with the inputs. Unfortunately it didn’t.

—Code:---------------------------------------------------------------

    public void read_service_loop()
    {
        in_loops++;

        ClearAllAnalog(1);
        dt_datotid_nu = DateTime.Now;
        in_timeout_chk = 0;
        while (!fn_get_control(0) & in_timeout_chk != 1)
        {
            in_timeout_chk = fn_timeout(1);
        }
        if (in_timeout_chk != 0) return;
        st_report = fn_get_digital();

        ClearAllAnalog(1);
        OutputAnalogChannel(1, 1, 255);
        dt_datotid_nu = DateTime.Now;
        in_timeout_chk = 0;
        while (!fn_get_control(1) & in_timeout_chk != 1)
        {
            in_timeout_chk = fn_timeout(1);
        }
        if (in_timeout_chk != 0) return;
        st_report = st_report + " " + fn_get_digital();

        ClearAllAnalog(1);
        OutputAnalogChannel(1, 2, 255);
        dt_datotid_nu = DateTime.Now;
        in_timeout_chk = 0;
        while (!fn_get_control(2) & in_timeout_chk != 1)
        {
            in_timeout_chk = fn_timeout(1);
        }
        if (in_timeout_chk != 0) return;
        st_report = st_report + " " + fn_get_digital();

        ClearAllAnalog(1);
        OutputAnalogChannel(1, 1, 255);
        OutputAnalogChannel(1, 2, 255);
        dt_datotid_nu = DateTime.Now;
        in_timeout_chk = 0;
        while (!fn_get_control(3) & in_timeout_chk != 1)
        {
            in_timeout_chk = fn_timeout(1);
        }
        if (in_timeout_chk != 0) return;
        st_report = st_report + " " + fn_get_digital();

…and so on, ending up with OutputAnalogChannel 1, 2 and 3 all on 255.

    }

    public int fn_timeout(int pr_seconds)
    {
        TimeSpan ts_number = DateTime.Now - dt_datotid_nu;
        in_millisec = Convert.ToInt16(ts_number.TotalMilliseconds);

        if (in_millisec < (pr_seconds * 1000))
        {
            return 0;
        }
        else
        {
            in_timeout++;
            return 1;
        }
    }

    public bool fn_get_control(int pr_num)
    {
        in_checksum = 0;
        in_ch_1 = ReadAnalogChannel(1, 1);
        in_ch_2 = ReadAnalogChannel(1, 2);
        in_ch_3 = ReadAnalogChannel(1, 3);

        if (in_ch_1 > 500)
        {
            in_checksum = in_checksum + 1;
        }

        if (in_ch_2 > 500)
        {
            in_checksum = in_checksum + 2;
        }

        if (in_ch_3 > 500)
        {
            in_checksum = in_checksum + 4;
        }

        if (in_checksum == pr_num)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public string fn_get_digital()
    {
        in_digital = ReadAllDigital(1);

…and here some code to change the number returned from something between 0 and 255 to a string, st_digital, containing something readable.

        return st_digital;
    }

Thanks for the code. I’ll look it and try to test too.
Sorry that I’m not familiar with the C# language.

Your code looks OK. I don’t know the reason to the freezing of the USB communication.
BTW: Have you checked current physical and virtual memory usage when running this program?

Is it always (and how exactly) 100.000 cycles this runs OK?

Thank you for the effort.

I have not checked the memory usage. The whole program is quite small, and should not use very much of any ressources.

The 100.000 cycles is not exact at all. Sometimes it is 50.000, sometimes 110.000. I have had it running for 320.000 cycles without freezing.

(Please note, that “50.000” and “110.000” is just round numbers. The exact number would be something like “51.387” etc.)

The computer is an Acer, brand new, clean WinXP-installation with servicepack2. And Visual Studio.

(Could this be taken care of with a firmware-update - if it something like that exists at all?)

I have come to think, that I have put the analog-Out directly to the analog-In (from the analog-out, there is a resistor, 10K, to GND).

But should I put a transistor in between for amplification of the signal?

The thing is, with a voltmeter, I read the full voltage (~8.5) but the card reads a very small number. If the problem was insufficient current, I believe the voltage would also be drawn down by the strain. Since it does not, the transistor should not be necessary (?)

Just a small remark, don’t know if this is the case here but anyway.
I remember a similar problem with a customer (he read analog values for days without a problem, and suddenly the card returned only zeroes) We did tests for weeks, but we were unable to simulate the problem. Suddenly, the customer informed us that he used a power suppy for the K8061 which had the GND in common with the PC. When he changed to a floating PSU for K8061, the problem was solved. Hope this helps.

Thanks for an interesting input.

My powersupply does not share the GND with the PC, except if the grounding from the DC socket is connected to the GND on the USB-socket on the board - but in this way, it would allways be connected (?)

However, the GND of the powersupply is connected to the GND of the analog input and outputs, since it supplies the entire external system with power. Could this be the issue?

The USB section is not connected to the power supply GND on the board.
The problem to freezing may be some sort of electric noise (EMC) problem. Do you have some long wirings connected to the K8061 card?

Your power supply is floating - No internal connection to the mains ground?.

About connecting the analog outputs to analog inputs:
You have selected the 10V range to the analog outputs and analog inputs.
If the voltage to the analog input is about 10V you should get about full reading from it. You may test this using the demo software.

The Powersupply is a stabilized adaptor, which supplies 12.5 VDC.
As mentioned, it also runs the “extras”, various switches, MOS Curcuits, and the rest of my own construction.

The cables is quite short: Less than thirty centimeter from the PC to the board.

The demo software says everything is OK, but so does my application - in the beginning. It could be interesting to see, if the demo software would give the same problem if I used it 100.000 times, but I am afraid I don’t have the patience for that… :wink:

The three analog outputs is connected to three analog inputs, all has a resistor, 10K, to GND, and also drives a MOS 4096 gate each.
This should not be too much, I believe?

Surely 10k load is OK for the K8061.
I checked the voltage was 9.86V with a 10k load.
With 1k ohm load it was 9.25 V.
With no load 9.90V.

I have just made some tests, and I have to correct a little bit:

I have earlier stated, that the output is OK, but the input doesn’t read it.
In a recently made test, I can see it is a little different:

The output is only half of what it should be:

Setting the output is using this procedure:
OutputAnalogChannel(1, 1, 255);
OutputAnalogChannel(1, 2, 255);
OutputAnalogChannel(1, 3, 255);

This should give approximately 9.5 volt on each channel.

As I described earlier, i go binary from 0 to 7 on these channels: 000, 001, 010, 011, 100, 101, 110, 111.

Right now I find, when reaching no. 6 (“110”) the first bit is only 4,5 volt, the second is 9,5 and the last is (of course) zero.

The funny part is, that I have been through this first bit when reaching 4 (“100”) and 5 (“101”), where it was allright. Now, after doing this drill on no. 6 (“110”):

ClearAllAnalog(1);
OutputAnalogChannel(1, 2, 255);
OutputAnalogChannel(1, 3, 255);

The no. 3 bit does not deliver full power, only 4,5 volt.

What can the explanation be??

If I should make a wild quess, I should say somehow the board thinks it is 0-5 volt on analog output no. 3, instead of the 0-10 volt. (but only when I activate 2 and 3, not 3 alone, and not 1 and 3.

That IS a little far out…!

Very strange! - Does this happen if you activate analog outputs 2 and 3 in the demo program “manually” with the sliders?

Is there any difference if you change the order of the instructions?

e.g.
OutputAnalogChannel(1, 3, 255);
OutputAnalogChannel(1, 2, 255);
OutputAnalogChannel(1, 1, 0);

This is just to try to find if there is some sort of communication problem between the DAC and the PIC microcontroller.

Please check the voltage at IC7 pins 2 and 16. Should be about 5V when the analog outputs 2 and 3 are set to 255.

Hello again,

I have not solved the “5 volt instead of 10 volt”-analog output problem, but to get forward I stopped using the analog outputs.
Instead, I use three digital outputs to make the binary counting from 0 to 7.

The reason I started out using the analog outputs is, that I needed all digital outputs for other things.
However, my program runs in two cycles, where cycle one uses the digital outputs, ant cycle two didn’t. And it was in cycle two I needed the binary counting.

So, I now only use the digital outputs in both cycles, and everything works fine.

Thanks to everybody who took the time to read my post and add constructive suggestions.

Sincerely / Best regards
Mads Aggerholm