To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 20725
20724  |  20726
Subject: 
Re: I2C interface
Newsgroups: 
lugnet.robotics
Date: 
Mon, 12 May 2003 18:10:55 GMT
Viewed: 
1381 times
  
Hi Bastiaan,

BrickOS only updates the motor register once every millisecond,
so when using functions like motor_a_dir(), the highest frequency
you can generate is 500 Hz.  You can get around this by patching
the kernel, or if that seems disagreeable, below you will find some
routines that will twiddle the bits faster without any kernel patches.
These routines work by accessing the motor register directly.  I
still call the BrickOS motor functions because you can't stop
BrickOS from accessing the motor register without patching the
kernel.

The code assumes that SCL is hooked to output A and SDA
is hooked to output B.  Also, this will only work with BrickOS
0.2.6.10 or later since prior versions did not reliably turn on the
motors 100% of the time (I've posted about this problem in the
past, and it's been fixed in the latest version of BrickOS).

You should be able to call the functions below at full speed
without any delay loops since each function call takes a significant
amount of time already.

Cheers,

Mark

#include <unistd.h>
#include <dmotor.h>

#define MOTOR_A_SHIFT 6
#define MOTOR_B_SHIFT 2
#define MOTOR_C_SHIFT 0

#define MOTOR_A_MASK  (0x03 << MOTOR_A_SHIFT)
#define MOTOR_B_MASK  (0x03 << MOTOR_B_SHIFT)
#define MOTOR_C_MASK  (0x03 << MOTOR_C_SHIFT)

#define MOTOR_FLOAT   0x00
#define MOTOR_REV     0x01
#define MOTOR_FWD     0x02
#define MOTOR_BRAKE   0x03

#define MOTOR_A_BRAKE (MOTOR_BRAKE << MOTOR_A_SHIFT)
#define MOTOR_A_FWD   (MOTOR_FWD   << MOTOR_A_SHIFT)
#define MOTOR_A_REV   (MOTOR_REV   << MOTOR_A_SHIFT)
#define MOTOR_A_FLOAT (MOTOR_FLOAT << MOTOR_A_SHIFT)

#define MOTOR_B_BRAKE (MOTOR_BRAKE << MOTOR_B_SHIFT)
#define MOTOR_B_FWD   (MOTOR_FWD   << MOTOR_B_SHIFT)
#define MOTOR_B_REV   (MOTOR_REV   << MOTOR_B_SHIFT)
#define MOTOR_B_FLOAT (MOTOR_FLOAT << MOTOR_B_SHIFT)

#define MOTOR_C_BRAKE (MOTOR_BRAKE << MOTOR_C_SHIFT)
#define MOTOR_C_FWD   (MOTOR_FWD   << MOTOR_C_SHIFT)
#define MOTOR_C_REV   (MOTOR_REV   << MOTOR_C_SHIFT)
#define MOTOR_C_FLOAT (MOTOR_FLOAT << MOTOR_C_SHIFT)

extern void set_motor(unsigned char mask, unsigned char value);
__asm__("
.text
.align 1
.global _set_motor
_set_motor:
  stc ccr,r1h        ; store current interrupt status
  orc #0x80,ccr      ; disable interrupts

  mov @0x80:8,r0h    ; read motor_bits
  xor r0h,r1l        ; xor motor_bits,value
                     ;   (determine what bits differ)
  and r0l,r1l        ; and mask,value
                     ;   (mask off those bits we want to change)
  xor r1l,r0h        ; xor value,motor_bits
                     ;   (flip those bits)
  mov r0h,@0x80:8    ; write motor_bits

  ldc r1h,ccr        ; restore interrupts
  rts
");

void scl_lo()
  {
  motor_a_dir(brake);
  set_motor(MOTOR_A_MASK, MOTOR_A_BRAKE);
  }

void scl_hi()
  {
  motor_a_dir(fwd);
  set_motor(MOTOR_A_MASK, MOTOR_A_FWD);
  }

// sets SDA to float during acknowledge pulse
void sda_ack()
  {
  motor_b_dir(off);
  set_motor(MOTOR_B_MASK, MOTOR_B_FLOAT);
  }

void sda_lo()
  {
  motor_b_dir(brake);
  set_motor(MOTOR_B_MASK, MOTOR_B_BRAKE);
  }

void sda_hi()
  {
  motor_b_dir(fwd);
  set_motor(MOTOR_B_MASK, MOTOR_B_FWD);
  }

void sda_set(int d)
  {
  if (d)
    sda_hi();
  else
    sda_lo();
  }

void i2c_init()
  {
  motor_a_speed(MAX_SPEED);
  motor_b_speed(MAX_SPEED);

  scl_hi();
  sda_hi();
  }

"Bastiaan van Kesteren" <b.van.kesteren53@zonnet.nl> wrote in message
news:HEpz2J.pwF@lugnet.com...
Hello,

A while ago i was working on a I2C interface for the RCX. i took a little
brake, but started again whit it a week ago. I now have build my own I2C
interface, which can run at 100kHz(and even faster). The signal is also • pretty
stable. I had the RCX running a test program, whit all acknowledge checks
disabled. So when an error occured, the connections would be lost. It • runned
all night without problems. Thats much better than the old device, which • had an
error rate of about 3%.

The problem is still the speed. The interface isn't the problem. So I • looked at
the RCX internals. after reading some documentation about it, i figured • out
that the motors(the I2C channels are connected to the motor ports) must be
connected to port 1,2 or 3 of the H8 chip(I couldn't find any clear answer
about this). So I read the H8 3297 harware manual, and found out that • these
output ports have a delay time of maximum 100ns, when running at 16mHz. • That
should be more than fast enough to run at 100kHz, right? i am not even • getting
close to it....

Then the motor outputs are handled by a driver-IC, the MLX10402. I • couldn't
find anything about the maximum speed of this IC. Anyone knows more about • this?
I don't think it can make 100kHz, but I do expect it to make atleast a few • kHz's

Then the speed problem could alos be in the software. Can BrickOS make a • motor
port run at 100kHz? I am not such a experienced programmer, so I don't now • how
to figure that out. Does anyone know more about this?

thanks,
bas.



Message has 1 Reply:
  Re: I2C interface
 
Thanks for your answer! However, I do have some questions about it.. First of all, I looked at the code you send in your post. looks nice, but to be honest, I don't know anything about assembly ( It is assembly, whats being used in the sub (...) (22 years ago, 13-May-03, to lugnet.robotics)

Message is in Reply To:
  I2C interface
 
Hello, A while ago i was working on a I2C interface for the RCX. i took a little brake, but started again whit it a week ago. I now have build my own I2C interface, which can run at 100kHz(and even faster). The signal is also pretty stable. I had (...) (22 years ago, 11-May-03, to lugnet.robotics)

4 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
13 hours ago
Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR