Ejemplo n.º 1
0
def ReadCounter1():
    '''
    Desc: Read counter1 
    !!! Before using it make sure than the counter is really enabled!!!
      
    Ex: 
    >>> LJU3HV.ResetCounter1()
    []
    '''

    return d.getFeedback(u3.Counter1(Reset=True))
Ejemplo n.º 2
0
def ctr7(d):
  global u3channels_saved
  i=7
  if u3channels_saved[i] == 'ctr':
    if u3channels_saved[6] == 'ctr':           #Then there are two counters, so FIO7 is counter 1 and FIO6 is counter 0
      return d.getFeedback(u3.Counter1( Reset = True ) )
    else:
      return d.getFeedback(u3.Counter0( Reset = True ) )
  else:
    print "Error trying to get counter data from FIO"+str(i)+".  You didn't set it up for counter input."
    print "ctr"+str(i)+" exiting.  Bye bye."
    raise RuntimeError('Sorry...')
Ejemplo n.º 3
0
def ResetCounter1():
    '''
    Desc: Performs a reset of counter1 
    !!! Before using it make sure than the counter is really enabled!!!
      
    Ex: 
    >>> LJU3HV.ResetCounter1()
    
    Conter 1 was reset
    '''

    d.getFeedback(u3.Counter1(Reset=True))
Ejemplo n.º 4
0
 def resetCounter(self):  # Reset the content counter 1
     return self.labjackModule.getFeedback(u3.Counter1(Reset=True))
Ejemplo n.º 5
0
 def readCounter(self):  # Return the content counter 1
     return self.labjackModule.getFeedback(u3.Counter1())
Ejemplo n.º 6
0
    def count(self):
        counterPin = self.portlist[0][1]
        
        # lowest timer is fio4, thus lowest counter fio5
        if counterPin < 5:
            self.logger.info("Lowest port for counter is FIO 05")
            self.logger.info("  ... aborting")
            exit()
        
        self.logger.info("  placing timer on FIO" + str(counterPin - 1) )
        self.logger.info("  placing counter on FIO" + str(counterPin) )

        
        numOfCounters = 1
        clockBase = "1MHz"
        clockDivisor = 0

        import u3
        import datetime
        import time

        clkBaseStr = clockBase

        if clockBase is "1MHz":
            clockBase = 3
        elif clockBase is "4MHz":
            clockBase = 4
        elif clockBase is "12MHz":
            clockBase = 5
        elif clockBase is "48MHz":
            clockBase = 6
        else:
            self.logger.info("Invalid clockBase for timer/counter specified")
            self.logger.info("  possible: 1MHz, 4MHz, 12MHz, 48MHz")
            self.logger.info("  ... aborting")
            exit()
        
        self.logger.info("  clock frequency is " + str(clkBaseStr) )
        self.logger.info("  clock divisor is " + str(clockDivisor) )
        
        # Enable the timers, make sure no pin is set to analog
        self.lj.configIO(
                    NumberOfTimersEnabled = numOfCounters,
                    EnableCounter1=True,
                    TimerCounterPinOffset = counterPin-1,       # first comes the timer, then the counter
                    FIOAnalog = 0)

        sysTimerConf = u3.TimerConfig(0,10,0) 
        self.lj.getFeedback(sysTimerConf)

        self.lj.configTimerClock(TimerClockBase = clockBase,
                            TimerClockDivisor = clockDivisor)

        #print "U3 Configuration: ", self.lj.configU3()
        
        # handles for timer / counter
        clkTimer = u3.Timer0(False)
        counter = u3.Counter1(False)
        
        # stop systemtime from computer
        start_time = systemtime()
        number_of_measures = 0

        ##
        ##
        ## Counter Loop
        while True:
            if self.STOP is True:    # exit condition
                break

            # stop actual time
            act_time = systemtime() - start_time
           
            
            # before sleep
            startData = self.lj.getFeedback(clkTimer, counter)
            prevClock = startData[0]
            prevEvents = startData[1]
            
            # pause and wait for events
            time.sleep( self.parent.count_interval )
           
            # after sleep
            results = self.lj.getFeedback(clkTimer, counter)
            clock = results[0]
            events = results[1]
            
            # calculate frequency
            counts = events - prevEvents   # temp store here
            intervalTime = clock - prevClock   # temp store here
            deltaT = intervalTime / 4e6

            freq = float(counts) / deltaT 

            # put measures
            self.queue.put( (act_time,) + tuple([freq]) )
            #print ( (act_time,) + tuple([freq]) )


            # count and delay
            number_of_measures = number_of_measures + 1
            
            # max count/time exceeded
            if (self.parent.max_count is not None) and (number_of_measures >= self.parent.max_count):
                break
            if (self.parent.max_time is not None) and (act_time >= self.parent.max_time):
                break