
|
INFO - FAQ - CC2-Forum - CCPro-Forum |
|
Hello, I have written new example software for the RN-MOTOR, let me know what you think. If everything works then maybe it could be posted on the roboter netz to help other people with the C-Control system. Greetings, H.J. Windt '----------------------------------------------------------------------------------------------------' '**************************************************************************' '* WINDT SYSTEMS *' '*RN-MOTOR EXAMPLE VIA EMULATED I2C BUS v1.1 for CCIUM2.02 and CCIMainU1.1*' '* 2005/ H.J. WINDT *' '* With thanks to Gaston for testing the example! *' '**************************************************************************' '----------------------------------------------------------------------------------------------------' 'This software for the C-Control I Unit M v2.02 and C-Control I Main U v1.1 will demonstrate using' 'the RN-MOTOR controller' 'Communication with the RN-MOTOR is via an emulated I2C bus.' 'Look under *** I/O PORTS *** for the I2C connections.' 'You may want to adjust some variables under ** INITIALIZATION SUBROUTINES ** to make the RN-MOTOR' 'work with your stepper motor(s)!!' '----------------------------------------------------------------------------------------------------' '**************** I/O PORTS ****************' define sda port[4] define scl port[5] '*******************************************' '**************** VARIABLES ****************' define i2c_nack bit[1] define i2c_last bit[2] define i2c_nack_count byte[2] define i2c_byte byte[3] define i2c_out_bit bit[24] define i2c_in_bit bit[17] define loop byte[4] define motor_selection byte[5] define control byte[6] define motor_direction byte[7] define motor_speed byte[8] define motor_continuous byte[9] define motor_steps word[6] define low_word word[7] define high_word word[8] '*******************************************' '**************** CONSTANTS ****************' '*******************************************' '****************** SETUP ******************' print"#ON_CONFIG#"; : put &b1000 : print"#OFF#"; '<<--TAKE THIS LINE AWAY FOR C-CONTROL MAIN UNIT V1.1!!' gosub initialize_rn_motor '*******************************************' '***************** PROGRAM *****************' #start print"Enter motor selection/ 0 = left/ 1 = right/ 2 = both" input motor_selection print"Enter control/ 0 = stop motor(s)/ 1 = control motor(s)/ 2 = read motor steps taken" input control on control goto stop_motor, control_motor, read_motor_steps_taken #stop_motor gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 3 : gosub write_byte_i2c i2c_byte = motor_selection : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto stop_motor goto start #control_motor print"Enter motor(s) direction/ 0 = left turn/ 1 = right turn" input motor_direction print"Enter motor(s) speed/ (0 to 255) 255 = slow" input motor_speed print"Turn motor(s) continuous?/ 0 = NO/ 1 = YES" input motor_continuous if motor_continuous = 1 then gosub rn_motor_control if motor_continuous = 1 then goto start print"Enter motor(s) steps to turn/ (0 to 32767)" input motor_steps gosub rn_motor_control goto start #read_motor_steps_taken if motor_selection > 1 then print "Cant read both motors at the same time!!" if motor_selection > 1 then goto start gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 13 : gosub write_byte_i2c i2c_byte = motor_selection : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack then goto pass_read gosub start_i2c i2c_byte = &h57 : gosub write_byte_i2c gosub read_byte_i2c : low_word = i2c_byte gosub read_byte_i2c : low_word = i2c_byte * 256 + low_word gosub read_byte_i2c : high_word = i2c_byte gosub read_last_byte_i2c : high_word = i2c_byte * 256 + high_word gosub stop_i2c #pass_read if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto read_motor_steps_taken print"HIGH word = ";high_word;" Low word = ";low_word goto start end '*******************************************' '*************** SUBROUTINES ***************' #rn_motor_control #set_motor_direction gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 4 : gosub write_byte_i2c i2c_byte = motor_selection : gosub write_byte_i2c i2c_byte = motor_direction : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto set_motor_direction #set_motor_speed gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 8 : gosub write_byte_i2c i2c_byte = motor_selection : gosub write_byte_i2c i2c_byte = motor_speed : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto set_motor_speed if motor_continuous = 1 then goto turn_motor_continuous #turn_motor_number_of_steps gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 5 : gosub write_byte_i2c i2c_byte = motor_selection : gosub write_byte_i2c i2c_byte = motor_steps mod 256 : gosub write_byte_i2c i2c_byte = motor_steps / 256 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto turn_motor_number_of_steps return #turn_motor_continuous gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 6 : gosub write_byte_i2c i2c_byte = motor_selection : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto turn_motor_continuous return #start_i2c sda = 0 : scl = 0 return #stop_i2c sda = 0 : deact scl : deact sda return #write_byte_i2c for loop = 1 to 8 sda = i2c_out_bit deact scl #write_byte_i2c_clock_stretch if not scl then goto write_byte_i2c_clock_stretch scl = 0 i2c_byte = i2c_byte shl 1 next deact sda deact scl #write_byte_i2c_ack_clock_stretch if not scl then goto write_byte_i2c_ack_clock_stretch i2c_nack = sda scl = 0 if i2c_nack then goto i2c_error i2c_nack_count = 0 return #i2c_error i2c_nack_count = i2c_nack_count + 1 goto stop_i2c #read_byte_i2c i2c_last = 0 #get_i2c_byte deact sda for loop = 1 to 8 deact scl #read_byte_i2c_clock_stretch if not scl then goto read_byte_i2c_clock_stretch i2c_in_bit = sda scl = 0 if loop < 8 then i2c_byte = i2c_byte shl 1 next if i2c_last then deact sda else sda = 0 deact scl #read_byte_i2c_ack_clock_stretch if not scl then goto read_byte_i2c_ack_clock_stretch scl = 0 return #read_last_byte_i2c i2c_last = 1 goto get_i2c_byte '*******************************************' '******* INITIALIZATION SUBROUTINES ********' #initialize_rn_motor #set_motor_amps gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 1 : gosub write_byte_i2c i2c_byte = 2 : gosub write_byte_i2c i2c_byte = 190 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto set_motor_amps #set_mode gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 14 : gosub write_byte_i2c i2c_byte = 0 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto set_mode #switch_motors_on gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 2 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto switch_motors_on #show_configuration gosub start_i2c i2c_byte = &h56 : gosub write_byte_i2c i2c_byte = 10 : gosub write_byte_i2c i2c_byte = 11 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c i2c_byte = 255 : gosub write_byte_i2c gosub stop_i2c if i2c_nack_count > 18 then goto no_ack_from_i2c_device if i2c_nack then goto show_configuration return '*******************************************' '****************** DATA *******************' '*******************************************' '************* ERROR MESSAGES **************' #no_ack_from_i2c_device print"**************************" print"* No ACK from I2C device *" print"**************************" pause 50 goto no_ack_from_i2c_device '*******************************************' > Hello, > > the display is "202" > > I understand what you mean. Is it not possible to read out the corresponding 4 bytes and to > handle this problem in a seperate routine? > > Greetings, > Gaston > > > > Hello again, > > I'm glad to hear that the RN-MOTOR controller is now working!! > > There is a problem with code 13: > > The c-control I v1.1 and v2.0x will only handle 16 bit variables but the read out of number of steps is a 32 bit variable ( 0 to 4294967295), this will not work on the c-control I system. > > Also, the c-control I 16 bit variables are signed integers, this means that the variables are 0 to 32767 and -32768 to -1 and not 0 to 65535. > > > > I have an idea how you can use the RN-MOTOR in a more controlled fashion, without the need for code 13, but I first need to know which version of the c-control you are using. > > > > Load and run the program below and let me know what is displayed. > > Greetings, > > H.J. Windt > > > > define version byte[64] > > put 0 > > print version > > > > > I have already the solution for code 11. It is very simple because the data output is via RS232 of the RN-Motor board only. But code 13 is a problem for me.... > > > Greetings > > > Gaston > > > > > > |
| Antwort schreiben |