Пример #1
0
def buddy_set_pwm_duty_value(channel, value, sample_rate=1000, streaming=False):
    hid_handle = buddy_open()
    
    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_PWM_ENABLE
    general_settings.mode = bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = (1 << int(channel))
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(int(sample_rate))

    runtime_settings.pwm_mode = bt.RUNTIME_PWM_MODE_DUTY_CYCLE
    runtime_settings.pwm_timebase = bt.RUNTIME_PWM_TIMEBASE_SYSCLK

    if (bt.buddy_configure(hid_handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        return -1

    packet = bt.general_packet_t()
    
    for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
        bt.int32_t_ptr_setitem(packet.channels, i, int(value))

    if (bt.buddy_send_pwm(hid_handle, packet, streaming) != bt.BUDDY_ERROR_CODE_OK):
        return -1

    time.sleep(0.1)
    bt.buddy_flush(hid_handle)
Пример #2
0
def buddy_set_pwm_duty_value(channel,
                             value,
                             sample_rate=1000,
                             streaming=False):
    hid_handle = buddy_open()

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_PWM_ENABLE
    general_settings.mode = bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = (1 << int(channel))
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(int(sample_rate))

    runtime_settings.pwm_mode = bt.RUNTIME_PWM_MODE_DUTY_CYCLE
    runtime_settings.pwm_timebase = bt.RUNTIME_PWM_TIMEBASE_SYSCLK

    if (bt.buddy_configure(hid_handle, general_settings, runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        return -1

    packet = bt.general_packet_t()

    for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
        bt.int32_t_ptr_setitem(packet.channels, i, int(value))

    if (bt.buddy_send_pwm(hid_handle, packet, streaming) !=
            bt.BUDDY_ERROR_CODE_OK):
        return -1

    time.sleep(0.1)
    bt.buddy_flush(hid_handle)
Пример #3
0
def test_seq_dac(handle, sample_rate, streaming, poncho_mode):
    mask = bt.BUDDY_CHAN_0_MASK | bt.BUDDY_CHAN_1_MASK | bt.BUDDY_CHAN_2_MASK | bt.BUDDY_CHAN_3_MASK
    
    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_DAC_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = mask
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH
    
    if poncho_mode:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.dac_power = bt.RUNTIME_DAC_POWER_ON
    runtime_settings.dac_ref = bt.RUNTIME_DAC_REF_EXT

    if (bt.buddy_configure(handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_seq_dac: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_dac_count = 0

    for k in range(0, 4095 + 1):
    #for k in range(2048, 2048 + 1):
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, k)

        print 'test_seq_dac: sending %d packet with value %d' % \
                (test_seq_dac_count, k)
        test_seq_dac_count += 1

        if (bt.buddy_send_dac(handle,
                              packet,
                              streaming) != bt.BUDDY_ERROR_CODE_OK):
            print 'test_seq_dac: could not send DAC packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0
Пример #4
0
def test_seq_dac(handle, sample_rate, streaming, poncho_mode):
    mask = bt.BUDDY_CHAN_0_MASK | bt.BUDDY_CHAN_1_MASK | bt.BUDDY_CHAN_2_MASK | bt.BUDDY_CHAN_3_MASK

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_DAC_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = mask
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    if poncho_mode:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.dac_power = bt.RUNTIME_DAC_POWER_ON
    runtime_settings.dac_ref = bt.RUNTIME_DAC_REF_EXT

    if (bt.buddy_configure(handle, general_settings, runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_seq_dac: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_dac_count = 0

    for k in range(0, 4095 + 1):
        #for k in range(2048, 2048 + 1):
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, k)

        print 'test_seq_dac: sending %d packet with value %d' % \
                (test_seq_dac_count, k)
        test_seq_dac_count += 1

        if (bt.buddy_send_dac(handle, packet, streaming) !=
                bt.BUDDY_ERROR_CODE_OK):
            print 'test_seq_dac: could not send DAC packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0
Пример #5
0
def set_dac_value(hid_handle, channel, value, mode):
    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_DAC_ENABLE
    general_settings.mode = bt.MODE_CTRL_STREAM
    general_settings.channel_mask = (1 << channel)
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(BUDDY_TEST_DAC_FREQ)

    runtime_settings.dac_power = bt.RUNTIME_DAC_POWER_ON
    runtime_settings.dac_ref = bt.RUNTIME_DAC_REF_EXT

    if mode:
        print('Poncho mode activated')
        
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = bt.BUDDY_CHAN_0_MASK
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    if (bt.buddy_configure(hid_handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'set_dac_value: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    
    for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
        bt.int32_t_ptr_setitem(packet.channels, i, value)

    print 'set_dac_value: setting DAC channel %d with value %d' %  (channel, value)

    if (bt.buddy_send_dac(hid_handle, packet, True) != bt.BUDDY_ERROR_CODE_OK):
            print 'test_seq_dac: could not send DAC packet'
            return -1

    time.sleep(1.0 / BUDDY_TEST_DAC_FREQ)

    bt.buddy_flush(hid_handle)
    time.sleep(0.1)

    return 0
Пример #6
0
def set_pwm_value(hid_handle, channel, value, poncho_mode):
    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_PWM_ENABLE
    general_settings.mode = bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = (1 << channel)
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(BUDDY_TEST_PWM_FREQ)

    runtime_settings.pwm_mode = bt.RUNTIME_PWM_MODE_FREQUENCY
    runtime_settings.pwm_timebase = bt.RUNTIME_PWM_TIMEBASE_SYSCLK_DIV_12
    
    if poncho_mode:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = (1 << channel)
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    if (bt.buddy_configure(hid_handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'set_pwm_value: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    
    for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
        bt.int32_t_ptr_setitem(packet.channels, i, value)

    print 'set_pwm_value: setting PWM channel %d with value %d' %  (channel, value)

    if (bt.buddy_send_pwm(hid_handle, packet, False) != bt.BUDDY_ERROR_CODE_OK):
        print 'set_pwm_value: could not send PWM packet'
        return -1

    time.sleep(1.0 / BUDDY_TEST_PWM_FREQ)

    bt.buddy_flush(hid_handle)
    time.sleep(0.1)

    return 0
Пример #7
0
def buddy_set_dac_value(channel, value, sample_rate=1000, streaming=False):
    hid_handle = buddy_open()

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_DAC_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = (1 << int(channel))
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(int(sample_rate))

    runtime_settings.dac_power = bt.RUNTIME_DAC_POWER_ON
    runtime_settings.dac_ref = bt.RUNTIME_DAC_REF_EXT

    if (bt.buddy_configure(hid_handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        return -1

    packet = bt.general_packet_t()
    
    for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
        bt.int32_t_ptr_setitem(packet.channels, i, int(value))

    if (bt.buddy_send_dac(hid_handle, packet, streaming) != bt.BUDDY_ERROR_CODE_OK):
        return -1

    if not streaming:
        time.sleep(1.0 / int(sample_rate))

    time.sleep(0.5)
    bt.buddy_flush(hid_handle)
Пример #8
0
def buddy_set_dac_value(channel, value, sample_rate=1000, streaming=False):
    hid_handle = buddy_open()

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_DAC_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = (1 << int(channel))
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(int(sample_rate))

    runtime_settings.dac_power = bt.RUNTIME_DAC_POWER_ON
    runtime_settings.dac_ref = bt.RUNTIME_DAC_REF_EXT

    if (bt.buddy_configure(hid_handle, general_settings, runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        return -1

    packet = bt.general_packet_t()

    for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
        bt.int32_t_ptr_setitem(packet.channels, i, int(value))

    if (bt.buddy_send_dac(hid_handle, packet, streaming) !=
            bt.BUDDY_ERROR_CODE_OK):
        return -1

    if not streaming:
        time.sleep(1.0 / int(sample_rate))

    time.sleep(0.5)
    bt.buddy_flush(hid_handle)
Пример #9
0
def test_waveform_dac(handle, fw_info, sample_rate, wave_type, streaming,
                      poncho_mode):
    mask = bt.BUDDY_CHAN_0_MASK | bt.BUDDY_CHAN_1_MASK | bt.BUDDY_CHAN_2_MASK | bt.BUDDY_CHAN_3_MASK

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_DAC_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    #general_settings.channel_mask = bt.BUDDY_CHAN_ALL_MASK
    general_settings.channel_mask = mask
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.dac_power = bt.RUNTIME_DAC_POWER_ON
    runtime_settings.dac_ref = bt.RUNTIME_DAC_REF_EXT

    if poncho_mode:
        print('Poncho mode activated')

        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    if (bt.buddy_configure(handle, general_settings, runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_waveform_dac: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_dac_count = 0

    #y_mag = 255
    #y_mag = 2700
    y_mag = 4000

    t = np.linspace(0,
                    WAVEFORM_TIME,
                    sample_rate * WAVEFORM_TIME,
                    endpoint=False)

    if wave_type == 'square':
        y = ((scisig.square(np.pi * 2.0 * WAVEFORM_FREQUENCY * t) + 1) /
             2) * y_mag
    elif wave_type == 'sine':
        y = ((np.sin(np.pi *
                     (1 / 2.0) * WAVEFORM_FREQUENCY * t) + 1) / 2) * y_mag
    elif wave_type == 'sawtooth':
        y = ((scisig.sawtooth(np.pi *
                              (1 / 2.0) * WAVEFORM_FREQUENCY * t) + 1) /
             2) * y_mag
    else:
        return -1

    for k in y:
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, int(k))

        print 'test_waveform_dac: sending %d packet with value %d' % (
            test_seq_dac_count, k)
        test_seq_dac_count += 1

        if (bt.buddy_send_dac(handle, packet, streaming) !=
                bt.BUDDY_ERROR_CODE_OK):
            print 'test_waveform_dac: could not send DAC packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0
Пример #10
0
def test_seq_pwm_duty(handle, sample_rate, streaming, poncho_mode):
    mask = bt.BUDDY_CHAN_2_MASK

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_PWM_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = mask
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH
    #general_settings.resolution = bt.RESOLUTION_CTRL_LOW

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.pwm_mode = bt.RUNTIME_PWM_MODE_DUTY_CYCLE
    runtime_settings.pwm_timebase = bt.RUNTIME_PWM_TIMEBASE_SYSCLK

    if poncho_mode:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE
        
    if (bt.buddy_configure(handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_seq_pwm_duty: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_pwm_count = 0

    # in counts
    #for k in range(0, 65535, 10):
    #for k in range(128, 129):
    #for k in range(63,64):
    #for k in range(191, 192):
    #for k in range(32767, 32768):
    for k in range(16383, 16384):
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, k)

        print 'test_seq_pwm_duty: sending %d packet with value %d' % \
                (test_seq_pwm_count, k)
        test_seq_pwm_count += 1

        if (bt.buddy_send_pwm(handle,
                              packet,
                              streaming) != bt.BUDDY_ERROR_CODE_OK):
            print 'test_seq_pwm_duty: could not send PWM packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0
Пример #11
0
def test_seq_pwm_freq(handle, sample_rate, streaming, poncho_mode):
    mask = bt.BUDDY_CHAN_0_MASK

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_PWM_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = mask
    #general_settings.resolution = bt.RESOLUTION_CTRL_LOW
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH
    #general_settings.resolution = bt.RESOLUTION_CTRL_SUPER

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.pwm_mode = bt.RUNTIME_PWM_MODE_FREQUENCY
    runtime_settings.pwm_timebase = bt.RUNTIME_PWM_TIMEBASE_SYSCLK_DIV_12

    if poncho_mode:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE
        
    if (bt.buddy_configure(handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_seq_pwm_freq: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_pwm_count = 0

    #for k in range(50000, (50000 + 1)):
    #for k in range(6000, (6000 + 1)):
    for k in range(10000, (60000 + 1)):
    #for k in range(2, (500 + 1)):
    #for k in range(100000, (100000 + 1)):
    #for k in range(45000, (45000 +1)):
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, k)

        print 'test_seq_pwm_freq: sending %d packet with value %d' % \
                (test_seq_pwm_count, k)
        test_seq_pwm_count += 1

        if (bt.buddy_send_pwm(handle,
                              packet,
                              streaming) != bt.BUDDY_ERROR_CODE_OK):
            print 'ERROR: test_seq_pwm_freq: could not send PWM packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0
Пример #12
0
def test_waveform_dac(handle, fw_info, sample_rate, wave_type, streaming, poncho_mode):
    mask = bt.BUDDY_CHAN_0_MASK | bt.BUDDY_CHAN_1_MASK | bt.BUDDY_CHAN_2_MASK | bt.BUDDY_CHAN_3_MASK
    
    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_DAC_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    #general_settings.channel_mask = bt.BUDDY_CHAN_ALL_MASK
    general_settings.channel_mask = mask
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.dac_power = bt.RUNTIME_DAC_POWER_ON
    runtime_settings.dac_ref = bt.RUNTIME_DAC_REF_EXT

    if poncho_mode:
        print('Poncho mode activated')
        
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    if (bt.buddy_configure(handle,
                           general_settings,
                           runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_waveform_dac: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_dac_count = 0
    
    #y_mag = 255
    #y_mag = 2700
    y_mag = 4000

    t = np.linspace(0, WAVEFORM_TIME, sample_rate * WAVEFORM_TIME, endpoint=False)

    if wave_type == 'square':    
        y = ((scisig.square(np.pi * 2.0 * WAVEFORM_FREQUENCY * t) + 1) / 2) * y_mag
    elif wave_type == 'sine':
        y = ((np.sin(np.pi * (1 / 2.0) * WAVEFORM_FREQUENCY * t) + 1) / 2) * y_mag
    elif wave_type == 'sawtooth':
        y = ((scisig.sawtooth(np.pi * (1 / 2.0) * WAVEFORM_FREQUENCY * t) + 1) / 2) * y_mag
    else:
        return -1

    for k in y:
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, int(k))

        print 'test_waveform_dac: sending %d packet with value %d' % (test_seq_dac_count, k)
        test_seq_dac_count += 1

        if (bt.buddy_send_dac(handle,
                              packet,
                              streaming) != bt.BUDDY_ERROR_CODE_OK):
            print 'test_waveform_dac: could not send DAC packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0
Пример #13
0
def test_seq_pwm_duty(handle, sample_rate, streaming, poncho_mode):
    mask = bt.BUDDY_CHAN_2_MASK

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_PWM_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = mask
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH
    #general_settings.resolution = bt.RESOLUTION_CTRL_LOW

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.pwm_mode = bt.RUNTIME_PWM_MODE_DUTY_CYCLE
    runtime_settings.pwm_timebase = bt.RUNTIME_PWM_TIMEBASE_SYSCLK

    if poncho_mode:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    if (bt.buddy_configure(handle, general_settings, runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_seq_pwm_duty: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_pwm_count = 0

    # in counts
    #for k in range(0, 65535, 10):
    #for k in range(128, 129):
    #for k in range(63,64):
    #for k in range(191, 192):
    #for k in range(32767, 32768):
    for k in range(16383, 16384):
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, k)

        print 'test_seq_pwm_duty: sending %d packet with value %d' % \
                (test_seq_pwm_count, k)
        test_seq_pwm_count += 1

        if (bt.buddy_send_pwm(handle, packet, streaming) !=
                bt.BUDDY_ERROR_CODE_OK):
            print 'test_seq_pwm_duty: could not send PWM packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0
Пример #14
0
def test_seq_pwm_freq(handle, sample_rate, streaming, poncho_mode):
    mask = bt.BUDDY_CHAN_0_MASK

    general_settings = bt.ctrl_general_t()
    timing_settings = bt.ctrl_timing_t()
    runtime_settings = bt.ctrl_runtime_t()

    general_settings.function = bt.GENERAL_CTRL_PWM_ENABLE
    general_settings.mode = \
        bt.MODE_CTRL_STREAM if streaming else bt.MODE_CTRL_IMMEDIATE
    general_settings.channel_mask = mask
    #general_settings.resolution = bt.RESOLUTION_CTRL_LOW
    general_settings.resolution = bt.RESOLUTION_CTRL_HIGH
    #general_settings.resolution = bt.RESOLUTION_CTRL_SUPER

    timing_settings.period = bt.FREQUENCY_TO_NSEC(sample_rate)

    runtime_settings.pwm_mode = bt.RUNTIME_PWM_MODE_FREQUENCY
    runtime_settings.pwm_timebase = bt.RUNTIME_PWM_TIMEBASE_SYSCLK_DIV_12

    if poncho_mode:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_PONCHO
        general_settings.expander_mode = bt.BUDDY_EXPANDER_PONCHO_MODE_OUT
        general_settings.expander_pin_state = mask
    else:
        general_settings.expander_type = bt.BUDDY_EXPANDER_TYPE_BASE

    if (bt.buddy_configure(handle, general_settings, runtime_settings,
                           timing_settings) != bt.BUDDY_ERROR_CODE_OK):
        print 'test_seq_pwm_freq: could not configure Buddy device'
        return -1

    time.sleep(0.1)

    packet = bt.general_packet_t()
    test_seq_pwm_count = 0

    #for k in range(50000, (50000 + 1)):
    #for k in range(6000, (6000 + 1)):
    for k in range(10000, (60000 + 1)):
        #for k in range(2, (500 + 1)):
        #for k in range(100000, (100000 + 1)):
        #for k in range(45000, (45000 +1)):
        for i in range(bt.BUDDY_CHAN_0, bt.BUDDY_CHAN_7 + 1):
            bt.int32_t_ptr_setitem(packet.channels, i, k)

        print 'test_seq_pwm_freq: sending %d packet with value %d' % \
                (test_seq_pwm_count, k)
        test_seq_pwm_count += 1

        if (bt.buddy_send_pwm(handle, packet, streaming) !=
                bt.BUDDY_ERROR_CODE_OK):
            print 'ERROR: test_seq_pwm_freq: could not send PWM packet'
            return -1

        if not streaming:
            time.sleep(1.0 / sample_rate)

    bt.buddy_flush(handle)
    time.sleep(0.1)

    return 0