Shop OBEX P1 Docs P2 Docs Learn Events
SPI communications UM6-LT — Parallax Forums

SPI communications UM6-LT

3dogpottery3dogpottery Posts: 78
edited 2013-05-15 08:38 in Propeller 1
I am about to attempt communicating with the UM6-LT Orientation Sensor using SPI. However, I see a major problem in that the minimum SPI clock speed specified for the UM6 is 200 KHZ (a clock period of 5 uS). It seems to me that, even with the propeller runing at 80MHz, with the time it would take for the propeller to shift bits in, update a counter, and toggle the clock pin, the propeller would not be fast enough. Any information anybody has would help. Thanks.

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-12-21 12:31
    The Propeller can handle SPI bit rate of ~20Mhz/10MHz up/down using counters or 5Mhz using PASM.

    80Mhz is 12.5nS (12.5x10^-9). Most PASM instructions are 4 clocks.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-22 22:17
    I made a um6 object. It's at code.anzhelka.com

    code.google.com/p/anzhelka/source/browse/software/spin/lib/um6.spin
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-01-04 08:31
    I am still attempting to communicate with the UM6 via SPI. In my first attempt, I tried to communicate by using the SPI_Spin object from the Propeller Tool library. The UM6 datasheet specifies a clock period of 2 to 5 microseconds, and so I found that the spin routine is too slow. Currently, I am attempting to communicate by using the SPI_Asm object. According to the documentation in the object, I believe a clock delay of “35” will give me a clock period of 4 microseconds. However, I am still not getting any results. It is most likely a timing issue. For instance, even after reading the current UM6 datasheet, I am still not sure how to read a register after sending a read command. Are the bytes sent immediately after the read command, or does the UM6 send the results when MOSI is set low? Anyway, If I make any progress, I will post my results.
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-02-07 12:04
    I have completed writing an SPI driver to communicate with the UM6-LT. I wrote it in assembly, and checked its functioning by single-stepping it with PASD. I checked all the timing with an oscilloscope, and all is correct. However, I still cannot successfully communicate with the UM6. In fact, I cannot find ANYONE who can get the SPI interface to work. I believe that CH Robotics has a problem with the driver within the chip. I have written to them and only have received terse responses, and no help. This is most unfortunate for me since I spent a good chunck of change on their sensor.
  • vanmunchvanmunch Posts: 568
    edited 2013-02-08 09:52
    $150 yikes! Have you seen this?

    http://arduino.cc/forum/index.php?topic=108689.0

    I have no idea if seeing his meathod helps or not.
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-02-08 20:17
    Thank you for the link, but the protocol referenced there is serial. I am trying to communicate via SPI.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-08 20:27
    Have you tried SRLM's object?
  • SRLMSRLM Posts: 5,045
    edited 2013-02-09 19:19
    I haven't had any problems communicating with the sensor using serial (which is what my object uses). The main issue that I have run into is that the filtering algorithm that they have onboard doesn't seem to work very well (at least in my tests). Still, why must you use SPI? I've had good (and plenty fast) results with the serial option.
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-03-08 10:00
    I have finally succeeded in communicating to the UM6-LT via SPI. After many failed attempts, I tried other modes, and discovered that Mode 0 worked. The technical help at CH-Robotics confirmed that there indeed is a mistake in their datasheet, and that the mode is actually “0”. Another mistake I found in their datasheet regards sending commands. A “write” operation, not a “read” operation is required. The only command that receives a response from the UM6 is the “UM6_GET_FW_VERSION” command. These mistakes have been corrected on the current datasheet from CH Robotics.
    I wrote the SPI driver in assembly, and it operates at a clock frequency of 340K Hz (I picked a frequency between the minimum and maximum as per the datasheet). I realize that there are routines that communicate through the UART; however, I don’t want the latency and the parsing overload.
    I also discovered that my particular UM6 has a problem with the accelerometers. I was able to graph the raw accelerometer data using their free serial interface software, and send it to them. They analyzed the data, and immediately volunteered to send me a new unit. When I get the new unit, and do some more-fine tuning on the SPI driver, I will attempt to publish it on the OBEX site. However, I have read that it takes a long time before uploaded objects actually appear on the site.
  • zwhitlowzwhitlow Posts: 1
    edited 2013-03-10 17:48
    Thanks for posting. I've been working on a pasm driver for the UM6 and also having trouble using mode 2. After seeing your post I checked the CH Robotics website and found an updated data sheet that describes operation in mode 0 for spi. I'm still having some trouble reading data though. I'm reading all zeros from the UM6_status register, 0x55. And several other registers return zeros or strange values. Sometimes the miso pin seems to be sending data during the write phase of a single register read. Please post an update if you learn anything new.
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-03-10 20:32
    Hi zwhitlo

    I haven't tried to query the status register, although all zeros seems to indicate that none of the self test failed.

    Since this is my first attempt at writing assembly code, let alone an SPI routine, my learning curve was rather steep. I didn't get any results until I realized that there should not be any delay between the 16 bits written to the UM6 and the 32 bits sent back to your microcontroller. In other words, when querying a register, the UM6 is clocked 48 cycles with no pause. I use the assembly waitcount instruction to time each half cycle. This insures that the clock transitions at precise time intervals, even though there are intervening instructions. Thus, querying a register is accomplished with just one function. My assembly routine reads data on the MISO pin immediately after the last bit is sent on the MOSI pin.

    I hope some of this helps.
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-03-15 11:57
    I posted the SPI driver object and a demo object on the OBEX. It is called


    SPI Driver for UM6 and UM6-LT UMI


    I don't know how long it will take to appear. From some of the comments I have read on this forum, it may never? In any event, the assembly object allows you to send a command, write to a configuration register, or read from a data register.
  • joshccnajoshccna Posts: 3
    edited 2013-03-15 12:13
    Thanks 3dogpottery!!!
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-03-15 17:27
    I guess I was wrong (or others were wrong) about posting on OBEX. It looks like the object I posted was immediately available. Here is the link again...

    SPI Driver for UM6 and UM6-LT UMI

    You are most certainly welcome, joshccna. I really like the UM6 from CH Robotics because it has an on board Extended Kalmen Filter, and relieves the processer (and me!) from having to do all the work. Additionally, you can modify the filter variables for fine tuning.

    Incidentally, I have found an excellent book for understanding the Kalman filter. It is titled "Kalman Filter for Beginners" by Phil Kim. I purchased it on Amazon. Previous to this book, I spent countless hours perusing the understanding of the Kalman filter. I read articles about State Models, Matrix Math, Stochtic Models, and Statistics. I also read many articles with titles like "A Beginners Understanding of Kalman Filtering.” However, I was always left more confused that I was in the beginning. Everything I read always had a very analytical approach where mostly I was presented with a lot of abstruse math. I just wanted an intuitive approach, and one that enabled me to use the damn filter! As far as the UM6 IMU, it will help you understand how you can change some variables to better utilize their product. Incidentally, I am not in any way affiliated with their IMU. I am just a dumb retired guy 63 years of age.
    Unfortunately for CH Robotics, they had the SPI mode wrong in their datasheet, and many people, including me, struggled over an attempt to implement the SPI protocol. If you read all the blogs from the beginning, it documents my struggle. I received many kind suggestions to use a routine that works using the USART. However, I found it a challenge to write an assembly routine for SPI, especially since it is my first Propeller assembly routine.
    If you find any problems with it, please email me. I am not, by any means, a professional programmer, but I am very trying..At least my wife tells me that.
  • joshccnajoshccna Posts: 3
    edited 2013-03-19 21:27
    Would it be too much to ask to convert this object into Arduino compatible language for me and all of those at arduino.cc???
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-03-21 14:01
    I would be glad to do it if I could. Unfortunately, I don't own an arduino, and have no idea how they are programmed. I think they are programmed in c. I do know how to program in c, however, I don't think I could just upload some code that would work on that particular platform.
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-03-21 16:36
    Just another thought...
    I am in the process of making a "ballbot", and considered the various microcontrollers that are available provide the “brains”. I have not read a lot about the arduino, but I don't believe that it is not capable of parallel processing like the Parallax Propeller is. My present robot uses the 386Ex by JK Microsystems. It is programmed in c. I fake true parallel processing by using an operating system called Ertos. Each process is allowed to run a short time. Continuity between runs is preserved by saving the process variables on a "stack". Each process is allowed to run a short time in a round robin fashion. Like an eight millimeter motion picture, the processes run so fast that it blurs before the eyes and everything seems to be running at once. It is fast, but not that fast. The clock speed of the 386Ex is 25 MHz. Getting back to the point: The problem is that my 386Ex is not well suited for a "ballbot" where very-very fast sampling is in order. The CH Robotics UM6 needs a clock input of at least 200 KHz, preferable 350 Khz. The Parallax Propeller is well suited for this. And, it can actually run several processes at the same time! For instance, the balancing algorithm can run in a "cog", and the motor drive can run in another "cog". A robot needs to sense its environment... so a camera routine can run in a "cog", sonar sensors can run in another "cog", and bumper sensors can run in another "cog". A "prioritizing" algorithm can run in another cog. The prioritizing algorithm arbitrates which sensor takes control of the motors. For instance, let’s say that that the camera commands the robot towards a target. The sonar assigned a higher priority and sensing an obstacle, would immediately take over and steer the robot clear of the obstacle. This is called "Behavioral Programming", and lends a robot a "lifelike" quality. It’s going to take me awhile to get all the programming written. When I do, I will post it on the Parallax Forum. However, I am still sidetracked by my desire of implementing a Kalman filter on a standalone accelerometer and gyroscope. Anyway, I have bloviated enough.
  • joshccnajoshccna Posts: 3
    edited 2013-04-26 08:18
    I hope it is not a problem, but I have uploaded your code to Pololu forums to see if someone could convert it to Arduino language (It's based on Wiring) which is a simplified version of C. I made sure to give recognition to your work. I tried converting it myself, but I have little time to try learning asm. IF you could convert it to C, that would make it a lot easier for me to convert because I do have some exp working with C. The Arduino community is a very large community for beginners, so I'm sure your work would be greatly appreciated.
  • zwdaviszwdavis Posts: 8
    edited 2013-05-15 08:38
    Did you do any calibration of the magnetometers over the serial port before communicating via SPI. I wired my LT sensor up and loaded your demo object to the propeller and am not having any luck getting a reading. Im getting an output to the serial terminal but only of strange strings of characters, no numbers. Any help you can offer would be greatly appreciated.
    Thanks
Sign In or Register to comment.