Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

6602: Rising edge capturing hardware interrupt

Solved!
Go to solution

I have this signal in input:

 

pulse train.JPG

 

I have to do something on rising edge as soon as possible.

My idea is to receive an hw interrupt from the board, and to write an isr soubroutine.

I read about callback function so i write some code.

 

 

But when i call:

    DAQmxErrChk ( DAQmxCfgChangeDetectionTiming ( udpTaskHandle,
                                                  "Dev1/Ctr0",
                                                  "Dev1/Ctr0",
                                                  DAQmx_Val_ContSamps,
                                                  1));

 

I have an error for the ctr0, it seems i can use onli the port0.

 

Now my question.... is there on port0 a software thread that read continuosly the value of the pins?

Or is there an hardware interrupt anyway ?

I think that a software thread has a big latency for me, at this point don't need the 6602 board,

i could read  the signal on LPT standard port.

 

Thank you for the answer.



There are 10 kinds of people. Those who understand binary notation, and those who do not.
0 Kudos
Message 1 of 8
(7,602 Views)

Hello Blacksocket,

 

Let me summurize what i undestood baout your issue. You are trying to receive an hardware Interrupt from your board (6602) so that you can start a secondary subroutine. Now, after you performed different test, your main question is about if exist a software thread which continually polls the value change on the desired pin? Please correct me if i bad figured you technical situation. 

Anyway if you must trigger a procedure according to a start signal, the counter board is one of the best choice you could perform. 

Did you try to explore the example finder in search of a possible example code which fits your specifications?

You you could provide for more informations about you application i'll be happy to help you moreover.

 

Best regards.

Matteo
0 Kudos
Message 2 of 8
(7,584 Views)

Ciao Matteo, i'm italian so i'm going to write in both language.

 

(English)

Yes i'm tryng to receive an hardware interrupt from the board to execute some my subroutine (this is my real problem) i can't actually.

I have to do this in ANSI C. I' searching for some sample code.

 

 

PS

Searching in the example i found one that don't use ctr but port line, i suppose that on those line nidaqx create a thread polling on the pin.

So if i can't have an interrupt, i don't need the board, because I can do a thread myself polling a standard the LPT port.

 

 

(Italian)

Il mio scopo è avere un interrupt hardware dall scheda per eseguire una mia subroutine.

Ci sono esempi ? Dovrei farlo in ANSI C.

 

 

Guardando gli esempi, ne ho trovato uno su una callback che sembrava fare al caso mio, ma non usa le periferfiche contatori , bensì le linee della port0.

E' una mia supposizione che i driver nidaqmx creino un thread che faccia polling sui pin della porta.

Se così fosse, non avrei bisogno della scheda , perchè posso direttamente creare thread che mi legge dalla porta parallela LPT del mio PC (non credo che cambierebbe molto)

Io avrei bisogno di un interrupt hardware, così abbasserei la latenza dei thread di windows.

 

Tra l'altro l'esempio che ho trovato non funziona neanche, ecco il link di un post in cui parlo dell' esempio trovato e che non mi funziona Esempio Ansi C 😞

 

 

 

 



There are 10 kinds of people. Those who understand binary notation, and those who do not.
0 Kudos
Message 3 of 8
(7,578 Views)

Hi blacksocket,

 

As mentioned on the other thread, Change Detection is not supported on the 6602.  It sounds like you just need to generate a software event when a single digital line goes high.  I was able to do this by configuring a "dummy" counter task and using the Sample Clock event.  The basic steps are as follows:

1.  Create Task

 

2.  Create CI Count Edges Channel

 

3.  Configure Sample Clock Timing to use HW-Timed Single Point with one of the PFI Lines as your external source

 

4.  Register the Sample Clock Signal Event

 

5.  Start the Task

 

You should now be able to use the Sample Clock (on one of the PFI lines) to initiate your callback.  The downside to this method is that it uses a counter, but hopefully the 8 counters available on the 6602 should give enough to work with.  If you are using the external signal as a sample clock for one of your counter tasks already then there wouldn't be a need to use the extra counter.

 

 

I hope this helps, be sure to let us know if you run into any issues!

 

 

Best Regards,

John Passiak
Message 4 of 8
(7,555 Views)

Sorry if it's passed a long time, i tryed to do as you suggested, but if i set  DAQmx_Val_HWTimedSinglePoint how can i have a continuos acquisition?

 

that's my code, it seems that thecallback function is called only once.



#include <stdio.h>
#include <NIDAQmx.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int32 CVICALLBACK TriggerDetectionCallback(TaskHandle taskHandle, int32 signalID, void *callbackData);

void Cleanup (void);

static TaskHandle  taskHandle=0;

int main(void)
{
    int         error=0;
   
    int32       read;
    uInt32      data[1000];
    char        errBuff[2048]={'\0'};

    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));


    DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle,
                                             "Dev1/ctr1",
                                             "",
                                             DAQmx_Val_Rising,
                                             0,
                                             DAQmx_Val_CountUp));


    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,
                                       "/Dev1/PFI35",
                                       1000.0,
                                       DAQmx_Val_Rising,
                                       DAQmx_Val_HWTimedSinglePoint ,
                                       1000));


    DAQmxErrChk (DAQmxRegisterSignalEvent(taskHandle,
                                          DAQmx_Val_SampleClock ,
                                          0,
                                          TriggerDetectionCallback,
                                          NULL)
                                          );


    /*********************************************/
    // DAQmx Start Code
    /*********************************************/

    DAQmxErrChk (DAQmxStartTask(taskHandle));

    printf("Continuously reading. Press Ctrl+C to interrupt\n");

    while( 1 ) {
       
    }

Error:
    puts("");
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 ) {
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmx Error: %s\n",errBuff);
    printf("End of program, press Enter key to quit\n");
    getchar();
    return 0;
}


int32 CVICALLBACK TriggerDetectionCallback(TaskHandle taskHandle, int32 signalID, void *callbackData)
{
    int32   error=0;
    uInt32  data[200]={0};
    int32   numRead;
    uInt32  i=0;
    char    errBuff[2048]={'\0'};

    static int count =0;

    count++;

    printf("\n\n%d", count);

    if( taskHandle ) {

        /*********************************************/
        // DAQmx Read Code
        /*********************************************/
        DAQmxErrChk (DAQmxReadCounterU32(taskHandle,1000,10.0,data,1000,&numRead,NULL));

        printf("\n%d",data);

    }
    return 0;

Error:
    if( DAQmxFailed(error) )
    {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        Cleanup();
        printf("DAQmx Error: %s\n",errBuff);
    }
    return 0;
}


void Cleanup (void)
{
    if( taskHandle!=0 )
    {
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
        taskHandle = 0;
    }
}

 

Message Edited by blacksocket on 30-03-2010 03:56 PM


There are 10 kinds of people. Those who understand binary notation, and those who do not.
0 Kudos
Message 5 of 8
(7,389 Views)
Solution
Accepted by topic author blacksocket

If you do want to read the value from the counter, try changing the read code to the following:

 

2010-03-30_101447.png

 

You are currently requesting 1000 samples to read so the Read function will block until 1000 samples are available.  The read should not be necessary if all you want to do is fire the event to do something else (which is what it sounded like from earlier posts).

 

Let me know how it goes!

 

 

Best Regards,

John Passiak
Message 6 of 8
(7,383 Views)

Great, it works, thank you.

 

I was focused on the brakpoint i put in the callback, and ii break only one time because the function was waiting 1000 samples... deh.

 

I modified only what you sayd , thank you again.

 

 



There are 10 kinds of people. Those who understand binary notation, and those who do not.
0 Kudos
Message 7 of 8
(7,352 Views)

Hello -

 

Do you have a suggestion to perform this task without a counter/timer board? Actually, in this case, there aren't any NI boards.

I have a TTL signal on a digital input line. I would like to execute code on detection of a rising edge.

 

Thanks!

0 Kudos
Message 8 of 8
(6,687 Views)