Both Motor control on MD25

Motor, Servo, Speech etc.

Moderator: chris

Both Motor control on MD25

Postby MadAboutPic » Sun Mar 14, 2010 7:36 pm

Hello friends,

I'm trying to develop a proportional control of the position using as input the encoder signal and as output the speed of the engines.

My system is formed by:

PDA (WM2003SE) ----> PIC16F877A ----> MD25.

The bus between the PDA and the PIC is RS232 while the bus between PIC and MD25 is I2C.

In theory the system should works in this way:
Given a setpoint in terms of encoder tick the PDA check every 200 msec the encoder position and calculate a speed according with a proportional function. This speed is sent to the PIC that send trough I2C to the MD25. The speed became 0 when the encoder signal is equal to the setpoint and the duty is finished.

Everything works fine when apply the function to a single motor ( MD25 mode set to 0 ).

When apply the function to both motors ( MD25 mode set to 2 ) after about 2 seconds the system crash.

I think the problem is in the my 16f877 firmware that doesn't respect the i2c timing of the MD25 PIC. But I haven't enough information about this to fix the problem.
Does anybody have some experience about this?

Generally I develop a pic firmware using PROTEUS VSM and MPLAB. In this way I can simulate the circuit with an in debug circuit features. In this case I can't do that since I haven't a virtual device that simulate the MD25.
Does anybody knows if exist a place where download the MD25 firmware in hex format ?

Thank you very much.
MadAboutPic
 
Posts: 3
Joined: Sun Mar 14, 2010 6:40 pm

Re: Both Motor control on MD25

Postby chris » Wed Mar 17, 2010 11:08 am

When you say that the system crashes after 2 seconds is it simply the timeout feature of the MD25?
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: Both Motor control on MD25

Postby MadAboutPic » Wed Mar 17, 2010 12:07 pm

Thank you Chris for your attention.

I don't think that the problem is the timeout. Every 0.2 seconds I ask for the encoder position.
I've tried also to disable the timeout and give a continuous rotation command (in mode 2 setting). During the rotation if I try to ask for the encoder status I can only do a few reading of them before the system crashes. There isn't a fix numbers of reading it seems something random. For that reason I think about the I2C timing.
Maybe the MD25 in mode 2 is too busy for the tasks I’m asking for?

Thank you again
MadAboutPic
 
Posts: 3
Joined: Sun Mar 14, 2010 6:40 pm

Re: Both Motor control on MD25

Postby chris » Wed Mar 17, 2010 12:46 pm

Sounds like you need to post your I2C routines, maybe I can shed some light on it then. Please also say what bus frequency and pull up resistors you are using.
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: Both Motor control on MD25

Postby MadAboutPic » Wed Mar 17, 2010 7:03 pm

Hi Chris,
These are the I2c routines that I use.
This is not the whole firmware. These routines are called when the PIC receive trough RS232 some commands.
To read the encoder I use a comand that starts the reading routine once for every register, so the routine works for 17 times ( see the routine GlobalStat ).
After the total register reading the pda calculate a new engines speed that is sent to MD25 trough the I2C writing routine.
The speed is updated every 200 ms. I've tried also a 500/1000 msec with no better results.
This system is stopped when the encoders value reach the given setpoint.
As I wrote everything works fine when apply this procedure to a single motor ( MD25 mode set to 0 ).
The I2C frequency is about 100 KHz. The pull up resistors are 10K.
What about the MD25 hex firmware? Do you think it is possible find it?

Thank you very much.




You will find some italian words in the code because.... I'm italian :D
- The total register reading routine:

GlobalStat ; Read all registers
movlw 0xff
movwf ContaI2C

Scorri:
incf ContaI2C ;Starts from 0 register
movf ContaI2C,W
sublw 0x11 ; check for 17 registers read
btfsc STATUS,Z
goto $+8
movf ContaI2C,W
movwf Indirizzo ; Send the actual register
call LeggiI2C ; Read the register

movlw 0x3B
movwf TXREG
call TransWt ;Send RS232 the ";" symbol
Goto Scorri ; Go back for the next register

- The I2C Read routine

LeggiI2C ; I2C reading routine
call StartI2C ; Set SSPCON2.SEN
call WaitI2C ; Wait PIR1,SSPIF

BANKSEL SSPBUF
movlw B'10110000' ; Write Address in Write mode
movwf SSPBUF
call WaitI2C

BANKSEL SSPBUF
movf Indirizzo,W ; Write register
movwf SSPBUF
call WaitI2C

call RstartI2C ; Set SSPCON2.SEN
call WaitI2C ; Wait

BANKSEL SSPBUF
movlw B'10110001' ; Write Address in read mode
movwf SSPBUF
call WaitI2C

call RecI2C ; Enable I2C Receive
call WaitI2C ; Wait Until Buffer Received
BANKSEL SSPBUF
movf SSPBUF,W ; Save to I2C_Data First !!
BANKSEL I2C_Data
movwf I2C_Data
;

call StopI2C ; Initial STOP Condition
call WaitI2C ; Wait Until STOP Condition Terminated


- The I2C write routine

ScriviI2C
call RiceviRS232
call StartI2C ; Set SSPCON2.SEN
call WaitI2C ; Wait PIR1,SSPIF

BANKSEL SSPBUF
movlw B'10110000' ; Write address
movwf SSPBUF
call WaitI2C

BANKSEL SSPBUF
movf Indirizzo,W ; Write register
movwf SSPBUF
call WaitI2C

BANKSEL SSPBUF
movf DatoRicevuto,W ; Write data
movwf SSPBUF
call WaitI2C

call StopI2C ; Initial STOP Condition
call WaitI2C ; Wait Until STOP Condition Terminated


- The Wait I2C routine

WaitI2C ; Poll for SSPIF
banksel PIR1
FLoop btfss PIR1,SSPIF
goto FLoop
bcf PIR1,SSPIF
return

- The Start/Stop routines

StartI2C ; Initiate the I2C START condition.
banksel SSPCON2
bsf SSPCON2,SEN
return

StopI2C ; Initiate the I2C STOP condition.
banksel SSPCON2
bsf SSPCON2,PEN
return


- The restart routine

RstartI2C ; Initiate the I2C restart condition.
banksel SSPCON2
bsf SSPCON2,RSEN
return

- The I2C Init routine

InitI2C: ; The subroutine of I2C Initialization

movlw 0x08 ; This gives 100KHz I2C clock @ 4MHz
banksel SSPADD
movwf SSPADD
movlw b'10000000' ; Disable slew rate control.
banksel SSPSTAT
movwf SSPSTAT
movlw b'00000000' ;
movwf SSPCON2 ; Setup MSSP for continuous reception.
movlw b'00101000' ; Enable MSSP and setup for I2C master
banksel SSPCON ; mode.
movwf SSPCON
return
MadAboutPic
 
Posts: 3
Joined: Sun Mar 14, 2010 6:40 pm


Return to Drivers

Who is online

Users browsing this forum: No registered users and 1 guest

cron