Counter is delayed, reading rpm using K8055

Hi!
This is my first k8055 project and I’m using an optical sensor that counts the counter up every time it is obscured, I’m posting a picture on my setup as well.

My problem is that the counter doesn’t count up instantly but with a small delay so when i stop running, the counter continues to count a short time, say half a second afterwards.
The program I made reads the counter with a certain interval and then resets the counter again and read it again so my input in the program is how many counts in a certain time.
But with the delay in the counter makes the reading not accurate so I need help with fins a way so that the counting is instant. It appears to be the smae problem with all debounce times.

All advice are welcome and thanks is advance!

Hello :unamused:

What is the frequency of the rotation? I hope you know that K8055 can count up to 2kHz frequency maximum. In what programing language you have writen the program? have you tried counting with the demo program, does it also lag?

I have tried the counter with delphi and expierenced the same problem. But later i found out that there is a specific algorithm for that.

[quote=“edvardas”]Hello :unamused:

What is the frequency of the rotation? I hope you know that K8055 can count up to 2kHz frequency maximum. In what programing language you have writen the program? have you tried counting with the demo program, does it also lag?

I have tried the counter with delphi and expierenced the same problem. But later i found out that there is a specific algorithm for that.[/quote]

Thanks for your fast reply,
I want to maesure around 1000 rpm with a disk that obscures the light 12 times per rotation so around 200 Hz. The program is written with Matlab but with the demo program is lags as well.

Did you mean that you had an algorithm to fix the problem or to adjust the signal from the board?

Unless theres is any other way to connect the card/sensor I get the feeling that the card is to slow for the measuring? It’s not that it don’t register the obscures but that it’s doing it with a small delay that makes it a problem.

Did you or someone else had the same problem with the card?

Thanks in advance!

[quote=“sebbo”][quote=“edvardas”]Hello :unamused:

What is the frequency of the rotation? I hope you know that K8055 can count up to 2kHz frequency maximum. In what programing language you have writen the program? have you tried counting with the demo program, does it also lag?

I have tried the counter with delphi and expierenced the same problem. But later i found out that there is a specific algorithm for that.[/quote]

Thanks for your fast reply,
I want to maesure around 1000 rpm with a disk that obscures the light 12 times per rotation so around 200 Hz. The program is written with Matlab but with the demo program is lags as well.

Did you mean that you had an algorithm to fix the problem or to adjust the signal from the board?

Unless theres is any other way to connect the card/sensor I get the feeling that the card is to slow for the measuring? It’s not that it don’t register the obscures but that it’s doing it with a small delay that makes it a problem.

Did you or someone else had the same problem with the card?

Thanks in advance![/quote]

You got me here. I had similar problem with delphi program i’ve written myself, and it was lagging like hell. Later i found specific delphi language requirement to make it faster. But in your case that has no sense. But in my case the demo program was working well. Did you use the latest version of the DLL?

The card shouldn’t be too slow to measure this, since your frequency is like 10 times lower than the maximum. maybe there is a problem in a circuit that is used between the sensor and the board? I mean maybe something is slowing it down. I’m not very pro in this, and the problem is that this forum isn’t very active…

I have not used MatLab, however using VB I would keep the counter running and poll it via a timer event. Here is timer event code for doing this:

[code]'read K8055 counter 1 and calc RPM

'device has been opened prior to enabling timer

'uses count differential between timer events to avoid starting and stopping the counter

Private Sub tmr1_Timer()

Const numTeeth = 12                         '# of teeth on interrupter wheel

Static oldCnt As Long                       'holds old count between events

Dim inpCnt As Long                          'get new count
Dim curCnt As Long                          'current count this timer event

Dim curRPM As Double                        'calculated RPM, could/should be a global

tmr1.Enabled = False                        'disable timer while processing event

inpCnt = ReadCounter(1)                     'get counter 1

curCnt = inpCnt - oldCnt                    'calculate current count

Debug.Print inpCnt, curCnt

oldCnt = inpCnt                             'save new count

If curCnt > 0 Then                          'has to be > 0 to have meaning

    curRPM = (curCnt / numTeeth) * (60000 / tmr1.Interval)      'calc current RPM, assume timer interval units are ms
    
    lblRPM.Caption = CStr(curRPM)                               'show it, formatted

End If
    
tmr1.Enabled = True                         'enable timer

End Sub
[/code]

At each timer event the K8055 counter is read (inpCnt) and has subtracted from it a saved value (oldCnt) to calculate the current period’s input count (curCnt). If curCnt > 0 then it is used to calculate the RPM using the tooth count of the interrupter (numTeeth), and 60000 divided by the timer interval (in ms).

A couple of notes:

oldCnt is declared as Static, in VB this means that it retains it’s value between timer events. You may need to declare it as a global in other languages.

To a point the longer the timer interval the more accurate will be the calculated value, so at 200 Hz input a 500 ms timer interval will accumulate 100 counts for reasonably good accuracy.

Play with the debounce interval as it seems it can clean up the input count if the signal is not 50% duty cycle.

The same thing is with delphi. You must use a timer even, or you’ll gonna get big delay.