I currently have a 5000 Pulse per revolution encoder that I need to calculate the duty cycle of all the pulses.
I am doing this in Visual Basic 6.0 and I am using DAQmx. The counter card is the PCI 6624.
Currently my problem is this..I think that I am filling the array with the necessary data, but I am having a hard time retrieving it. When I do retrieve some data, it seem like it is repetetive information. Here is my code and any suggestions that can help is greatly appreciated.
Dim data(100000) As Double
Dim samples As Integer
Dim NSamples As Integer
Dim sampsPerChanRead As Long
Dim A_Gate_Counter As String
Dim A_SignalSource As String
A_Gate_Counter = "Dev1/ctr1"
A_SignalSource = "/Dev1/PFI34"
samples = 5000 'value of encoder ppr
NSamples = (samples * 2)
DAQmxErrChk DAQmxCreateTask("", ADutyTaskHandle)
DAQmxErrChk DAQmxCreateCISemiPeriodChan(ADutyTaskHandle, A_Gate_Counter, "", 0.0000001, 0.000008, DAQmx_Val_TimeUnits3_Seconds, "")
DAQmxErrChk DAQmxCfgSampClkTiming(ADutyTaskHandle, "20MHzTimebase", 10000, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_FiniteSamps, 10000)
DAQmxErrChk DAQmxCfgImplicitTiming(ADutyTaskHandle, DAQmx_Val_AcquisitionType_FiniteSamps, NSamples)
DAQmxErrChk DAQmxSetCISemiPeriodTerm(ADutyTaskHandle, "", A_SignalSource)
DAQmxErrChk DAQmxSetArmStartTrigType(ADutyTaskHandle, DAQmx_Val_TriggerType4_DigEdge)
DAQmxErrChk DAQmxSetDigEdgeArmStartTrigSrc(ADutyTaskHandle, A_SignalSource)
DAQmxErrChk DAQmxSetDigEdgeArmStartTrigEdge(ADutyTaskHandle, edge)
DAQmxErrChk DAQmxSetCISemiPeriodStartingEdge(ADutyTaskHandle, "", DAQmx_Val_Edge1_Falling)
DAQmxErrChk DAQmxStartTask(ADutyTaskHandle)
DAQmxErrChk DAQmxReadCounterF64(ADutyTaskHandle, NSamples, 10#, data(1), NSamples, sampsPerChanRead, ByVal 0&)
DAQmxStopTask ADutyTaskHandle
For i = 1 To samples 'this is the value of encoder PPR
Cycle(i) = data(2 * i - 1) + data(2 * i)
If Cycle(i) >= CycleMax Then CycleMax = Cycle(i)
If Cycle(i) <= CycleMin Then
CycleMin = Cycle(i)
TotalCycle = TotalCycle + Cycle(i)
CycleAve = TotalCycle / i
End If
High(i) = data(2 * i - 1)
Duty(i) = (High(i) / Cycle(i) * 100)
CycleCum = CycleCum + Cycle(i) * 80000000
Next i
For i = 1 To samples 'this is the value of encoder PPR
If Duty(i) >= DutyMax Then DutyMax = Duty(i)
If Duty(i) <= DutyMin Then DutyMin = Duty(i)
TotalDuty = TotalDuty + Duty(i)
DutyAve = TotalDuty / i
Next i
DutyMax = (DutyMax * 3.6) 'converts the duty cycle percentage value into a degree value
DutyMin = (DutyMin * 3.6)
DutyAve = (DutyAve * 3.6)
Anybody please help me with this. I can even change the code. I am not stuck with this code so if you have any recommendations, I'll take them.
Thanks