Shop OBEX P1 Docs P2 Docs Learn Events
MD23 Code Help... — Parallax Forums

MD23 Code Help...

LitefireLitefire Posts: 108
edited 2007-01-08 00:46 in Propeller 1
Hello again, I'm having a lot of trouble getting the I2C routines to work with my motor controller, the MD23.

I was wondering if anyone had any spare time on their hands, and if they wanted to make me some sample code that would do just a few simple functions. I'd greatly appreciate it. Or if someone could look at my code and see where i'm going wrong, that would help too...

Here's the information on the motor controller, all the info anyone would need is there. http://www.robot-electronics.co.uk/htm/md23tech.htm#encoders

the only functions i would need would be:
Mode changing from 0 (default) to 1
Disabling the 2second timeout (command found in command register)
Resetting the encoder count (also in command register)
Receiving encoder count.
and of course, setting motor speeds.

any help is greatly appreciated, and if anyone can help me get my robot working they earn my eternal gratitude!

My current code is attached.

p.s. I don't have pull-up resistors on either of the I2C lines, but the I2Cobject that i'm working with says that i don't need them if i initialize it with _driveSCLLine == TRUE. Think this is an issue?
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-05 22:55
    Litefire,
    You must have a pullup on the data (SDA) line. I would recommend having a pullup as well on the clock (SCL) line. The I2C spec requires it even though the Propeller gets away with not having one on the clock line.
  • LitefireLitefire Posts: 108
    edited 2007-01-05 23:00
    curses!

    okay, i'll get to work on that and see if it works.
  • LitefireLitefire Posts: 108
    edited 2007-01-05 23:02
    managed to scrounge a resistor from a current project, to no avail.

    still not working... the motor controller isn't even reading any valid I2C data coming through. [noparse]:([/noparse]
  • LitefireLitefire Posts: 108
    edited 2007-01-05 23:25
    wow, i just tried doing it bit by bit (switching each pin high or low based on the I2C specs)... that didn't even work.

    I really hope that this controller isn't a waste of $225...
  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-01-05 23:29
    Here is some code for the SRF08 which is from the same company.· I used pull-ups on both clock and data lines.· I think I used 4.7Kohm pull-ups, robot is in truck so I cannot measure it right now.· The I2C low level code is from an object that Beau wrote.
  • LitefireLitefire Posts: 108
    edited 2007-01-06 00:03
    wow, this is frustruating. just tried the SRF08 code... again with no luck.

    what could be the problem?

    physically, i have the stamp and MC powered by 9volts (low for driving motors i know but i'm not running them too hard and i should see SOMETHING!!), then i have pins 0 and 1 pulled to 3.3V, which then go to SDA and SCL on the MC respectively.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-06 00:30
    What voltage is used for the I2C bus? Don't forget that the I2C bus that the Propeller uses has a maximum voltage of +3.3V. Some other I2C busses have a maximum voltage of +5V. It's not enough to have pullups to +3.3V. Also, the higher voltage can damage the Propeller pins. There's a long discussion thread "HOW TO SAFELY INTERFACE A 5V SIGNAL TO THE PROPELLER?" at the beginning of this forum that includes a discussion of a mixed voltage I2C bus. Please read it carefully.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-06 00:33
    I hope my previous note doesn't discourage you. If you read the thread, you'll find that it's very easy to connect +5V devices and systems to the Propeller. It's just that you can't usually just use a piece of wire to do it.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-01-06 01:07
    I powered the SRF08 with 5 volts but only pulled the clock an data lines up to 3.3. That also worked for a compass. No guarntee about the motor contorller. My Spyglass LCD requied that the clock and data lines be pulled up to 5 volts.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-01-06 01:22
    Litefire, I just looked at you code and the MD23 documentation. Have you tried a speed different from 140? 128 is stop. If this is a motor with gears and wheels attached, 140 may not be big enough to get it to start. I am assuming that the controller is still in mode 0. Just to double check you do have ground from the motor controller connected to ground on Prop board?
  • LitefireLitefire Posts: 108
    edited 2007-01-06 02:04
    okay, tried that at 200 (to hell with battery life!) and with the grounds connected. there is still no proper I2C communication happening on the MD23 (as viewed by the I2C activity LED).

    i tried beau's i2c lowlevel object (that i got with the SRF08 package) again with no I2C activity.
  • LitefireLitefire Posts: 108
    edited 2007-01-06 02:54
    i just shot an email to the company asking if the i2c lines needed 5v, and for any other hints.
  • LitefireLitefire Posts: 108
    edited 2007-01-06 23:21
    okay, so i got an email back from them. they said that 3.3v should work fine as pull ups. they also reccomended that i try using one of the sample programs for the propeller. i tried those with no luck.

    now i found a BS2 sample program for another product of theirs (a thermistor package). I compiled (to my knowledge) directly from the PBASIC code to spin, but it STILL IS NOT WORKING!

    Could someone check my spin and my basic code to see if they're the same... and perhaps if the sample code was decent to begin with? It looks good to me...

    Thanks for the continued help.

    ~~Brian
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-06 23:28
    Are you sure the prop is running properly? What about flashing an LED to check. Also check your pinouts are as expected. If example programs don't work it makes it sound like hardware.

    Graham
  • LitefireLitefire Posts: 108
    edited 2007-01-06 23:30
    okay, that's a good point. i'll see if i can scrounge around for an led.

    will it affect the program if i put wait periods in some places, so i can see the led changing? i wouldn't think so, but i'm not taking any chances at this point.

    thanks.

    ~~Brian
  • LitefireLitefire Posts: 108
    edited 2007-01-06 23:37
    also, i should note that it was not exactly sample code for my product. they don't produce code, only distribute what is submitted to them. for each of the sample spin programs i needed to do some small changes (seemingly only changing the address and register configs), but i needed to completely build the spin code to try the BS2 source (which was probably very inefficient but should have worked).

    you can be sure that once i get this working i'm going to send them my code :P.

    ~~Brian
  • rokickirokicki Posts: 1,000
    edited 2007-01-06 23:41
    This sort of thing is exactly why I love using the demo board. You can add LED flashing at various points, or even
    TV/VGA debugging, and everything just works. No need to hook up a bunch of additional stuff. If you value your
    time, using the demo board to prototype things is a *great* way to go.
  • LitefireLitefire Posts: 108
    edited 2007-01-06 23:48
    that would have been perfect... but my eventual project is going to use way more than 8 I/O pins, and we had to scrap the demo board in favor of the PRC (which is discussed in this forum every so often). since i wasn't going to use most of the features of the demo board (vga header, headphone jack, keyboard/mouse, etc.) they just wasted I/O pins that i am going to desperately need later.

    but the LED array would have been nice... oh well. I'll take a trip to the 'shack sometime tonight and give it a whirl.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-07 00:06
    This may work better. Notice that the register selection is a write type transaction. For reading, you have to do the write type transaction first, then restart and readdress the device for reading, read the data, then do the stop sequence.
  • LitefireLitefire Posts: 108
    edited 2007-01-07 00:17
    i'm starting to think that it actually may be a hardware error. I just used your (Mike's) sample code and i'm still not getting any correctly recieved I2C data on the MD23 end.

    I'll see what i can do to check out the board. will a simple led suffice? and how should i go about checking the hardware?

    ~~Brian
  • LitefireLitefire Posts: 108
    edited 2007-01-07 19:00
    just tried my propeller on the code posted here, using the basic i2c functions.

    http://forums.parallax.com/forums/default.aspx?f=25&m=156661

    anyone mind taking a quick peek at my code (Using I2C_toy) and seeing if I am using I2C_toy right?
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-07 19:24
    Brian, you don't even need an LED, if you have a volt meter you could write a simple program to toggle a pin very slowly or even run the program twice, once with the pins high once low, you just want to make sure that the clock is working OK and that the program a program is running OK.

    repeat
       !outa[noparse][[/noparse]10]   'toggle pin 10 (for example)
       waitcnt(cnt+10000000)  'delay
    
    



    Something like that.

    Graham
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-07 19:27
    At the moment your main will just end, you may want to add a repeat so it will just sit there doing its thing after the I2C command.

    Or perhaps try putting the I2C command in a loop, remember it may be so fast that you will not see the indicator LED on your hardware.

    Graham
  • LitefireLitefire Posts: 108
    edited 2007-01-07 19:57
    found the problem!

    my A0 pin is not functioning correctly!

    i'm going to run some programs now to check if they work.

    everyone, thanks so much for helping me through this.

    ~~Brian
  • LitefireLitefire Posts: 108
    edited 2007-01-07 20:49
    found the problem!

    my A0 pin is not functioning correctly!

    i'm going to run some programs now to check if they work.

    everyone, thanks so much for helping me through this.

    ~~Brian
  • LitefireLitefire Posts: 108
    edited 2007-01-07 20:56
    well, it looks to me like the problem was twofold.

    my A0 pin wasn't working, which used to be my SDA pin.

    i changed that, and am now watching the LEDs change correctly, and the motor controller won't even acknowledge a start bit.

    so i believe that the second problem was the motor controller itself, for which i am requesting an RMA number.

    I'll let everyone here know when i get the new controller how it goes from there.

    and i'd like to thank you guys once again for your perseverance.

    ~~Brian
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-07 21:46
    Why is your A0 pin not functioning?
  • LitefireLitefire Posts: 108
    edited 2007-01-07 22:38
    i do not know. however this code:

    pub main
    dira[noparse][[/noparse]0]~~
    outa[noparse][[/noparse]0]~~
    waitcnt(cnt+80_000_000*10)


    will not light an led connected between the pin and ground. it's distressing, but if i know about it i can avoid other issues.

    i actually checked by setting dira~~ and outa~~ and plugging the led into all of the pins consecutively. every other pin functions, save for pin 0.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-07 22:43
    I can't remember what your setup was but to check it is not just a connection problem try touching the led onto the physical leg of propeller pin.

    Graham
  • LitefireLitefire Posts: 108
    edited 2007-01-07 22:48
    i just did that, it is for serious fried.
Sign In or Register to comment.