Hallo an alle!
Ich habe ein einfaches Programm, das auf Interrupts (steigende Flanke) an J5 - Pin 3 ein kurzes Signal an J5- Pin 2 ausgibt. Wenn man den Eingang und Ausgang auf einem Oszilloskop beobachtet, dann kann man feststellen, daß unabhängig von der Interruptfrequenz, das Ausganssignal nicht nur bei jeder steigenden Flanke sondern sporadisch auch bei manchen fallenden Flanken auftritt.
Dies hat auch nichts mit Prioritäten od. Sytemlast zu tun, mein IST läuft mit Priorität 0 und auf dem System läuft kein anderer Prozess!
Das kann auch nicht vom Signalgeber verursacht werden, sondern muß in der Interruptbehandlung der NetDCU liegen, denn wenn ich die Flanke auf fallende Flanke umkonfiguriere (Registry), dann ist dieser Effekt nicht mehr festzustellen. Außerdem habe ich verschiedene Signalquellen und Eingangsfilter probiert und der Effekt war der selbe.
Mein Programm:
- extern "C" BOOL InterruptInitialize(DWORD idInt, HANDLE hEvent, LPVOID pvData, DWORD cbData);
- extern "C" VOID InterruptDone( DWORD idInt );
- // Global Variables:
- DWORD dwIRQ, dwSysIntr;
- static HANDLE hIsrEvent = NULL;
- HANDLE hDIO = INVALID_HANDLE_VALUE;
- // Forward declarations of functions included in this code module:
- DWORD WINAPI TachoControlThread(LPVOID pData);
- void closeAll();
- int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- // for this example the Pin J5-3 is used as interrupt source
- // J5-2 is used as output to signal the counter reached
- // craete event which will be fired when interrupt occurs
- hIsrEvent = CreateEvent( NULL, FALSE, FALSE, _T("DIOINTF") );
- if( NULL == hIsrEvent )
- {
- ERRORMSG(1,(_T("Can't create event (%d)\r\n"), GetLastError()));
- return -1;
- }
- // initialize DATAIO
- DWORD dwPort = 0; // port nr
- int nRet=0;
- // Open the port.
- TCHAR szPort[32];
- wsprintf(szPort,_T("DIO%d:"),dwPort);
- hDIO = CreateFile (szPort, // Pointer to the name of the port
- GENERIC_READ | GENERIC_WRITE,
- // Access (read-write) mode
- 0, // Share mode
- NULL, // Pointer to the security attribute
- OPEN_EXISTING,// How to open the serial port
- 0, // Port attributes
- NULL); // Handle to port with attribute
- // to copy
- if( INVALID_HANDLE_VALUE == hDIO )
- {
- ERRORMSG(1,(L"ERROR: Can't open %s (Error=%d)\r\n", szPort, GetLastError()));
- closeAll();
- }
- // set the filepointer to the start
- if( -1 == SetFilePointer( hDIO, dwPort, NULL, FILE_BEGIN ) )
- {
- ERRORMSG(1,(L"ERROR: Can't access port %d (Error=%d)\r\n", dwPort, GetLastError()));
- nRet = -1;
- closeAll();
- return -1;
- }
- // create and set ISR entry
- RETAILMSG(1,(_T("initializing ISR\r\n")));
- dwIRQ = 6;
- if( !DeviceIoControl( hDIO, IOCTL_DIO_REQUEST_SYSINTR, &dwIRQ, sizeof(DWORD), &dwSysIntr, sizeof(DWORD), NULL, NULL ) )
- {
- ERRORMSG(1,(L"Error initializing interrupt, InitInterrupt() failed (%d)\n\r", GetLastError()));
- closeAll();
- return -1;
- } /* end-if */
- RETAILMSG(1,(L"dwSysIntr = %d\r\n", dwSysIntr));
- /* connect IRQ with event and enable IRQ */
- if (!InterruptInitialize( dwSysIntr,hIsrEvent, NULL, 0 ))
- {
- ERRORMSG(1, (L"Error initializing interrupt, InitInterrupt() failed (%d)\n\r", GetLastError()));
- closeAll();
- return -1;
- } /* end-if */
- // start the thread for counting the tacho
- DWORD newId;
- HANDLE hThreadHandle = CreateThread( NULL, 0, TachoControlThread, NULL, 0, &newId);
- if(hThreadHandle == NULL) {
- // thread konnte nicht erzeugt werden
- ERRORMSG(1, (L"Error: failed to create thread\n\r"));
- closeAll();
- return -1;
- }
- CeSetThreadPriority(hThreadHandle, 0);
- CeSetThreadQuantum(hThreadHandle, 0);
- RETAILMSG(1,(_T("Waiting for Events\r\n")));
- bool loop = true;
- while( loop ) {
- Sleep(1);
- }
- // release own sysintr if not default
- DeviceIoControl( hDIO, IOCTL_DIO_RELEASE_SYSINTR, &dwSysIntr, sizeof(DWORD), NULL, 0, NULL, NULL );
- dwSysIntr = 0;
- closeAll();
- return 0;
- }
- // IST, that controls the tacho input
- DWORD WINAPI TachoControlThread(LPVOID pData) {
- // first enables the interrupt
- InterruptDone( dwSysIntr );
- BYTE pin = 7;
- while( TRUE )
- {
- // wait for interrupt (event)
- WaitForSingleObject( hIsrEvent, INFINITE );
- DeviceIoControl(hDIO, IOCTL_DIO_SET_PIN, &pin, 1, NULL, 0, NULL, NULL);
- DeviceIoControl(hDIO, IOCTL_DIO_CLR_PIN, &pin, 1, NULL, 0, NULL, NULL);
- // acknowledge interrupt
- InterruptDone( dwSysIntr );
- }
- }
- void closeAll() {
- DeviceIoControl( hDIO, IOCTL_DIO_RELEASE_SYSINTR, &dwSysIntr, sizeof(DWORD), NULL, 0, NULL, NULL );
- dwSysIntr = 0;
- if( INVALID_HANDLE_VALUE != hDIO )
- {
- CloseHandle( hDIO );
- }
- CloseHandle( hIsrEvent );
- }
Und die Einstellungen in der Registry:
reg open \drivers\builtin\digitalio
reg set value port dword 0
reg set value index dword 0
reg set value datadir dword 0x080
reg set value datainit dword 0x0
reg set value useasio dword 0x0C0
reg set value IRQCfg0 dword 0x040
reg set value IRQCfg1 dword 0x0
reg set value IRQCfg2 dword 0x0
reg save
Ich wäre für jeden Tip dankbar!