def write_special_function_6_pwm_generator(self, timer, timebase=1, output_2_enable=0, period=500, output_1_low_time=250, output_2_low_time=250, ): """ The Pulse Width Modulation Generator function uses discrete output channels DO0 and DO1 if Timer 0 is used to implement the function or discrete output channels DO2 and DO3 if Timer 1 is used to implement the function. One or two output signals can be generated for each implementation of the function. If two signals are generated using a given Timer, both will have the same period, but duty cycle for each can be independently controlled. Output DO0 for Timer 0 implementation or output DO2 for Timer 1 implementation are automatically enabled when the function is configured. Output DO1 for Timer 0 implementation or output DO3 for Timer 1 implementation are enabled or disabled by writing to a register. All PWM outputs are enabled or disabled by arming or disarming the function. Period and each output low time are set by writing to a register. Minimum period is 200µs and minimum low time is 100µs. The timebase is selected as seconds, milliseconds or microseconds based on the waveform to be generated in order to obtain the best resolution and performance. The example shown in Figure 13 below shows the use of both Timers, each used to generate two PWM signals. :param timer: :param timebase: :param output_2_enable: :param period: :param output_1_low_time: :param output_2_low_time: :return: """ function = 6 start_address = {0: 1100, 1: 1200}[timer] self.write_register(start_address + 1, 0) # disarm previous special function to enable this one. period = utils.int32_to_int16s(period) output_1_low_time = utils.int32_to_int16s(output_1_low_time) output_2_low_time = utils.int32_to_int16s(output_2_low_time) self.write_registers(start_address, [ function, # 0 0, 0, timebase, output_2_enable, 0, # 5 period[0], period[1], output_1_low_time[0], output_1_low_time[1], output_2_low_time[0], # 10 output_2_low_time[1], ]) self.write_register(start_address + 1, 1) # Enable/arm special function. status = self.read_register(start_address + 2) # if not status: # No errors. # self.write_register(start_address + 90, 0) # Save settings to EEPROM. return status
def write_special_function_7_one_shot_pulse_generator( self, timer, timebase=1, pulse_count_limit=0, output_pulse_polarity=0, trigger=0, pulse_width=500, pre_delay=100, post_delay=100, ): function = 7 start_address = {0: 1100, 1: 1200}[timer] self.write_register( start_address + 1, 0) # disarm previous special function to enable this one. pulse_count_limit = utils.int32_to_int16s(pulse_count_limit) pulse_width = utils.int32_to_int16s(pulse_width) pre_delay = utils.int32_to_int16s(pre_delay) post_delay = utils.int32_to_int16s(post_delay) self.write_registers( start_address, [ function, # 0 0, 0, timebase, 0, 0, # 5 pulse_count_limit[0], pulse_count_limit[1], output_pulse_polarity, trigger, pulse_width[0], # 10 pulse_width[1], pre_delay[0], pre_delay[1], post_delay[0], post_delay[1], # 15 ]) self.write_register(start_address + 1, 1) # Enable/arm special function. status = self.read_register(start_address + 2) # if not status: # No errors. # self.write_register(start_address + 90, 0) # Save settings to EEPROM. return status
def write_special_function_5_frequency_generator(self, timer, frequency, ): function = 5 start_address = {0: 1100, 1: 1200}[timer] self.write_register(start_address + 1, 0) # disarm previous special function to enable this one. frequency_16 = utils.int32_to_int16s(frequency) # Special Function Configuration [0,12] self.write_registers(start_address, [ function, # 0 0, 0, 0, frequency_16[0], frequency_16[1], ]) self.write_register(start_address + 1, 1) # Enable/arm special function. status = self.read_register(start_address + 2) # if not status: # No errors. # self.write_register(start_address + 90, 0) # Save settings to EEPROM. return status
def write_special_function_4_time_between_events( self, timer, timebase=1, event_1_internal_trigger=0, event_2_internal_trigger=0, average_weight=4, events_to_measure=0, ): function = 4 start_address = {0: 1100, 1: 1200}[timer] self.write_register( start_address + 1, 0) # disarm previous special function to enable this one. events_to_measure = utils.int32_to_int16s(events_to_measure) # Special Function Configuration [0,12] self.write_registers( start_address, [ function, # 0 0, 0, 0, 0, 0, # 5 0, 0, 0, 0, 0, # 10 0, 0, 0, 0, 0, # 15 timebase, event_1_internal_trigger, event_2_internal_trigger, average_weight, events_to_measure[0], # 20 events_to_measure[1], ]) self.write_register(start_address + 1, 1) # Enable/arm special function. status = self.read_register(start_address + 2) # if not status: # No errors. # self.write_register(start_address + 90, 0) # Save settings to EEPROM. return status
def write_special_function_3_waveform_measurement( self, timer, timebase=1, internal_trigger=0, events_to_measure=0, average_weight=4, ): function = 3 start_address = {0: 1100, 1: 1200}[timer] self.write_register( start_address + 1, 0) # disarm previous special function to enable this one. events_to_measure = utils.int32_to_int16s(events_to_measure) # Special Function Configuration [0,12] self.write_registers( start_address, [ function, # 0 0, 0, 0, 0, ]) # Special Function Continuation. self.write_registers(start_address + 30, [ timebase, internal_trigger, events_to_measure[0], events_to_measure[1], average_weight, ]) self.write_register(start_address + 1, 1) # Enable/arm special function. status = self.read_register(start_address + 2) # if not status: # No errors. # self.write_register(start_address + 90, 0) # Save settings to EEPROM. return status
""" Example of how to use the utilities module in the MAQ20 API when reading and writing directly to registers. """ from maq20 import MAQ20 import maq20.utilities as utils maq20 = MAQ20(ip_address="192.168.128.100", port=502) com = maq20.get_com() # get a reference to the COM module in the MAQ20 system # The name of a module is stored in the first 15 registers name_raw = com.read_registers(0, 15) name = utils.response_to_string( com.read_registers(address=0, number_of_registers=11)) print('Raw name: {}'.format(name_raw)) print('utils.response_to_string(name_raw) : {}'.format(name)) print('') # new line # Writing a number bigger than 16 bits: 2^16-1 = 65535 com.write_registers(address=1368, values=utils.int32_to_int16s(987134)) # Reading a number bigger than 16 bits: read_back = utils.int16_to_int32( com.read_registers(address=1368, number_of_registers=2)) print('Wrote 32 bit number 987134 and we read: {}'.format(read_back))