mcculw icon indicating copy to clipboard operation
mcculw copied to clipboard

USB-1608G AnalogSE Configuration

Open javiercasian opened this issue 2 years ago • 8 comments

javiercasian avatar Dec 13 '22 00:12 javiercasian

Hi I'm trying to measure different range of voltages using my DAQ USB-1608G but I have noticed that it needs to be configured as Single Ended however, eventhough I manually configure my DAQ as SE, when I send the command using python, the DAQ swaps back to to Differential

How to send the SE command using python, please see below what I'm sending. Board 0, Channel 0, 16 resolution, 10v range .

    global can_tran_3v3
    channel = 0
    can_tran_3v3 = ul.v_in(board_num, channel, ai_range)

javiercasian avatar Dec 13 '22 00:12 javiercasian

Hi, Did you configure the USB-1608G to be single ended in InstaCal?

Did you test with the example v_in.py?
How does it respond? does it stay in SE mode?

jeffreyg3 avatar Dec 13 '22 03:12 jeffreyg3

Hi Jeffrey 1.- Correct, I configured the USB-1608G to be single ended using InstaCal 2.- Correct, I have tested using the example v_in.py 3.- It does respond but with the wrong voltages, when I open InstaCal and execute channel 0, it reports the correct values

javiercasian avatar Dec 13 '22 03:12 javiercasian

Can I see the rest of you device instantiation routine?

jeffreyg3 avatar Dec 13 '22 04:12 jeffreyg3

sure, I basically made a copy & paste of the v_in.py, please see below:

  def Target_Voltage():
      use_device_detection = True
      dev_id_list = []
      board_num = 0
      try:
          if use_device_detection:
              config_first_detected_device(board_num, dev_id_list)
  
          daq_dev_info = DaqDeviceInfo(board_num)
          if not daq_dev_info.supports_analog_input:
              raise Exception('Error: The DAQ device does not support '
                              'analog input')
  
          print('\nActive DAQ device: ', daq_dev_info.product_name, ' (',
              daq_dev_info.unique_id, ')\n', sep='')
  
          ai_info = daq_dev_info.get_ai_info()
          ai_range = ai_info.supported_ranges[0]
          
          global can_tran_3v3
          channel = 0
          can_tran_3v3 = ul.v_in(board_num, channel, ai_range)
          time.sleep(2)
  
          global adc_in
          channel = 1 
          adc_in = ul.v_in(board_num, channel, ai_range)
          time.sleep(2)
  
          global R164_2
          channel = 2
          R164_2 = ul.v_in(board_num, channel, ai_range)
          time.sleep(2)
  
          global v3_3D
          channel = 3 
          v3_3D = ul.v_in(board_num, channel, ai_range)
          time.sleep(2)
  
          global can_l
          channel = 4 
          can_l = ul.v_in(board_num, channel, ai_range)
          time.sleep(2)
  
          global can_h
          channel = 5 
          can_h = ul.v_in(board_num, channel, ai_range)
          time.sleep(2)
  
  
      except Exception as e:
          print('\n', e)
      finally:
          if use_device_detection:
              ul.release_daq_device(board_num)
  
  if __name__ == '__main__':
      Target_Voltage()
  logging.info("")
  logging.info("##########################################################")
  logging.info("##                CAN TRANSIVER 3V3                     ##")
  logging.info("##########################################################")
  logging.info ("")
  can_tran_3v3 = ("%.3f" % can_tran_3v3)
  logging.info('Test CAN 3V3 : ' + can_tran_3v3) ##N17132111
  
  logging.info ("")
  logging.info("##########################################################")
  logging.info("##               U3 ADC INPUT 1.35V                     ##")
  logging.info("##########################################################")
  logging.info ("")
  adc_in = ("%.3f" % adc_in)
  logging.info('Test U26.4 : ' + adc_in) ##N16789872
  
  logging.info ("")
  logging.info("##########################################################")
  logging.info("##            R164 THERMISTOR VOLTAGE                   ##")
  logging.info("##########################################################")
  logging.info ("")
  R164_2 = ("%.3f" % R164_2)
  logging.info('Test r152.2 : ' + R164_2) ##N17154732
  
  logging.info ("")
  logging.info("##########################################################")
  logging.info("##             3V3D REEL VOLTAGE TEST                   ##")
  logging.info("##########################################################")
  logging.info ("")
  v3_3D = ("%.3f" % v3_3D)
  logging.info('Test r156.2 : ' + v3_3D) 
  
  logging.info ("")
  logging.info("##########################################################")
  logging.info("##            CAN LOW 1.5V VOLTAGE TEST                 ##")
  logging.info("##########################################################")
  logging.info ("")
  can_l = ("%.3f" % can_l)
  logging.info('Test r156.2 : ' + can_l) ##N16960320
  
  logging.info ("")
  logging.info("##########################################################")
  logging.info("##            CAN HIG 2.5V VOLTAGE TEST                 ##")
  logging.info("##########################################################")
  logging.info ("")
  can_h = ("%.3f" % can_h)
  logging.info('Test r156.2 : ' + can_h) ##N16960317

javiercasian avatar Dec 13 '22 04:12 javiercasian

The problem is these 2 lines: ai_info = daq_dev_info.get_ai_info() ai_range = ai_info.supported_ranges[0]

In short, the program is doing exactly what you are telling it. Let me explain. When you call "ai_info = daq_dev_info.get_ai_info()" you are really calling into a subroutine. Part of that subroutine is to find out what the MCC device can do. It is part of the program because these are general purpose examples, and we wanted them to work 'out of the box'. So there needed to be some way for the app to discover what the device was capable of including appropriate settings (like SE or DIFF). In this case, since the device is capable of both SE and DIFF, it is safest for the app to configure the device as differential inputs (DIFF). So when you called this, it forces the device into the configuration you don't want.

Instead, remove those 2 lines and replace them with:

ai_range = ULRange.BIP10VOLTS # or some other supported range (See ULhelp for complete list) ul.a_input_mode(board_num, AnalogInputMode.SINGLE_ENDED) # to set it programmatically.

I believe that will resolve the issue.

jeffreyg3 avatar Dec 13 '22 14:12 jeffreyg3

Hi Jeff Not sure if is the library or something else, but I cannot set the “ai_range = ULRange.BIP10VOLTS” however, when I call “ai_range = ai_info.supported_ranges[0]” does the same thing, where “0” is 5v, “1” is 10v, “14” is 2v and “4” is 1v

@.***

Gracias de antemano Javier Casian Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: JeffG at @.> Sent: Tuesday, December 13, 2022 9:17 AM To: @.> Cc: @.>; @.> Subject: Re: [mccdaq/mcculw] USB-1608G AnalogSE Configuration (Issue #36)

The problem is these 2 lines: ai_info = daq_dev_info.get_ai_info() ai_range = ai_info.supported_ranges[0]

In short, the program is doing exactly what you are telling it. Let me explain. When you call "ai_info = daq_dev_info.get_ai_info()" you are really calling into a subroutine. Part of that subroutine is to find out what the MCC device can do. It is part of the program because these are general purpose examples, and we wanted them to work 'out of the box'. So there needed to be some way for the app to discover what the device was capable of including appropriate settings (like SE or DIFF). In this case, since the device is capable of both SE and DIFF, it is safest for the app to configure the device as differential inputs (DIFF). So when you called this, it forces the device into the configuration you don't want.

Instead, remove those 2 lines and replace them with:

ai_range = ULRange.BIP10VOLTS # or some other supported range (See ULhelp for complete list) ul.a_input_mode(board_num, AnalogInputMode.SINGLE_ENDED) # to set it programmatically.

I believe that will resolve the issue.

— Reply to this email directly, view it on GitHubhttps://github.com/mccdaq/mcculw/issues/36#issuecomment-1348661891, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKWNXH4YUAR2KSL5XK3PFS3WNCAN5ANCNFSM6AAAAAAS4SRQQU. You are receiving this because you authored the thread.Message ID: @.***>

javiercasian avatar Dec 13 '22 15:12 javiercasian

your imports should include:

from mcculw import ul from mcculw.enums import ULRange, AnalogInputMode, ScanOptions, FunctionType, Status

Attached is a "more than you need" example, implementing a more direct approach to accessing data from the USB-1608G series. A lot of it is not germane to your needs, but it does include recommended way to use the mcculw library without the 'bloat code' USB1608G_a_in_scan_continuous_py.txt

jeffreyg3 avatar Dec 13 '22 15:12 jeffreyg3

Let me give it a try, thanks

Gracias de antemano Javier Casian Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: JeffG at @.> Sent: Tuesday, December 13, 2022 10:12 AM To: @.> Cc: @.>; @.> Subject: Re: [mccdaq/mcculw] USB-1608G AnalogSE Configuration (Issue #36)

your imports should include:

from mcculw import ul from mcculw.enums import ULRange, AnalogInputMode, ScanOptions, FunctionType, Status

Attached is a "more than you need" example, implementing a more direct approach to accessing data from the USB-1608G series. A lot of it is not germane to your needs, but it does include recommended way to use the mcculw library without the 'bloat code' USB1608G_a_in_scan_continuous_py.txthttps://github.com/mccdaq/mcculw/files/10219273/USB1608G_a_in_scan_continuous_py.txt

— Reply to this email directly, view it on GitHubhttps://github.com/mccdaq/mcculw/issues/36#issuecomment-1348771350, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKWNXH3E7LM3ZMY5FX6WQPLWNCG4FANCNFSM6AAAAAAS4SRQQU. You are receiving this because you authored the thread.Message ID: @.***>

javiercasian avatar Dec 13 '22 19:12 javiercasian

Hi Jeff Sorry it took me a few days to reply back to you, after I set the “ul.a_input_mode(board_num, AnalogInputMode.SINGLE_ENDED” my DAQ start taking the correct measures.

Now I have one and I think the last question. I have a test that voltage changed rapidly, is a CAN signal where the voltage change from 0.9 up to 2.8 how I can make take X amount of samples and get an average out of those samples?

Thanks in advance Javier Casian Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: JeffG at @.> Sent: Tuesday, December 13, 2022 8:12 AM To: @.> Cc: @.>; @.> Subject: Re: [mccdaq/mcculw] USB-1608G AnalogSE Configuration (Issue #36)

your imports should include:

from mcculw import ul from mcculw.enums import ULRange, AnalogInputMode, ScanOptions, FunctionType, Status

Attached is a "more than you need" example, implementing a more direct approach to accessing data from the USB-1608G series. A lot of it is not germane to your needs, but it does include recommended way to use the mcculw library without the 'bloat code' USB1608G_a_in_scan_continuous_py.txthttps://github.com/mccdaq/mcculw/files/10219273/USB1608G_a_in_scan_continuous_py.txt

— Reply to this email directly, view it on GitHubhttps://github.com/mccdaq/mcculw/issues/36#issuecomment-1348771350, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKWNXH3E7LM3ZMY5FX6WQPLWNCG4FANCNFSM6AAAAAAS4SRQQU. You are receiving this because you authored the thread.Message ID: @.***>

javiercasian avatar Dec 16 '22 21:12 javiercasian

"...how I can make take X amount of samples and get an average out of those samples?" What you are asking is not a feature of the USB-1608G series nor Universal Library, it is something you would do in your python script.

Depending on the required sampling rate, collecting the data can be accomplished using a finite loop or the function v_in() of the specific analog channel. In each iteration of the loop, saving the data to an element of a user created array, then totaling the collected data, and dividing the sum by the number of samples (ie elements) in the array.

Or, you can use a_in_scan() for a finite number of samples, then once the scan completes, and you copy the data to a local array, the final process is the same, totaling the collected data and dividing the sum by the number of samples in the array.

jeffreyg3 avatar Dec 19 '22 13:12 jeffreyg3

Hi Jeff Thanks, I was able to scan the channels I need the quantity of times I need by using the function “scanOptions.foreground” and “ul.scaled.win.buf_alloc”

I think I have everything I need now.

Thanks for your excellent support and happy holidays!

Gracias de antemano Javier Casian Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: JeffG at @.> Sent: Monday, December 19, 2022 6:46 AM To: @.> Cc: @.>; @.> Subject: Re: [mccdaq/mcculw] USB-1608G AnalogSE Configuration (Issue #36)

"...how I can make take X amount of samples and get an average out of those samples?" What you are asking is not a feature of the USB-1608G series nor Universal Library, it is something you would do in your python script.

Depending on the required sampling rate, collecting the data can be accomplished using a finite loop or the function v_in() of the specific analog channel. In each iteration of the loop, saving the data to an element of a user created array, then totaling the collected data, and dividing the sum by the number of samples (ie elements) in the array.

Or, you can use a_in_scan() for a finite number of samples, then once the scan completes, and you copy the data to a local array, the final process is the same, totaling the collected data and dividing the sum by the number of samples in the array.

— Reply to this email directly, view it on GitHubhttps://github.com/mccdaq/mcculw/issues/36#issuecomment-1357697539, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKWNXH3AWCDT4CG26LOV7ILWOBRJVANCNFSM6AAAAAAS4SRQQU. You are receiving this because you authored the thread.Message ID: @.***>

javiercasian avatar Dec 19 '22 15:12 javiercasian